File size: 677 Bytes
5b925b8
d6d8b22
 
5b925b8
7c560dd
d6d8b22
5b925b8
d6d8b22
 
 
 
e2cd426
 
 
d6d8b22
 
5b925b8
d6d8b22
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from fastai.vision.all import *
import skimage

# I was too lazy to re-export the model using a lambda so I defined the is_cat method here before unpickling
def is_cat(x): return x[0].isupper() 

learn = load_learner('dog_or_cat.pkl')
labels = learn.dls.vocab
def predict(img):
    img = PILImage.create(img)
    pred,pred_idx,probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}

title = "Is it a Cat?"
examples = ['cat_ex.jpg', 'dog_ex.jpg']

gr.Interface(
    fn=predict,
    inputs=gr.components.Image(height=512, width=512),
    outputs=gr.components.Label(),
    title=title,
    examples=examples,
).launch()