File size: 693 Bytes
52a03fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from fastai.vision.all import *
from huggingface_hub import push_to_hub_fastai, from_pretrained_fastai
import gradio as gr

#learner = from_pretrained_fastai("kolkhi/bears")
learner = load_learner("model.pkl")

categories = learner.dls.vocab
def classify_bear(img):
    img_new = PILImage.create(img)
    img_new.resize((128,128))
    pred,idx,probs=learner.predict(img_new)
    return dict(zip(categories, map(float,probs)))


image = gr.components.Image(width=192,height=192)
label = gr.components.Label()
examples=["deer.jpg", "wolf.jpg", "car.jpg", "ship.jpg"] 

iface = gr.Interface(fn=classify_bear, inputs=image,  outputs=label, examples=examples)
iface.launch(inline=False, share=True)