File size: 634 Bytes
f3dac4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
from huggingface_hub import from_pretrained_fastai

examples = ["llama.jpg", "alpaca.png"]
repo_id = "osanseviero/llama_or_alpaca"
    
learner = from_pretrained_fastai(repo_id)
labels = learner.dls.vocab

def inference(image):
    label_predict,_,probs = learner.predict(image)
    labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
    return labels_probs

gr.Interface(
    fn=inference,
    title="Llama or alpaca",
    description = "Predict if this image has a llama or an alpaca",
    inputs="image",
    outputs="label",
    examples=examples,
).launch(debug=True, enable_queue=True)