File size: 734 Bytes
a72431b
 
 
 
 
 
 
 
d71299d
a72431b
 
 
 
 
 
 
3d439cd
d71299d
a72431b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# %% ../hugging-space-model-app.ipynb 4
from fastai.vision.all import *
import gradio as gr

# %% ../hugging-space-model-app.ipynb 7
learn = load_learner('model1.pkl')

# %% ../hugging-space-model-app.ipynb 9
labels = learn.dls.vocab
def classify_image(img):
    img = PILImage.create(img)
    pred,pred_idx,probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}

# %% ../hugging-space-model-app.ipynb 11
image = gr.components.Image()
label = gr.components.Label(show_label=True,num_top_classes=3)
examples = ['afraid.jpg','anger.jpg','happyface.jpg','disgust.jpg','sadface.webp']

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)