toy / app.py
jerryjia92's picture
version 2
4ea21b4
raw
history blame contribute delete
551 Bytes
from fastai.vision.all import *
import gradio as gr
def is_cat(x):
return 'cat' if (x.name)[0].isupper() else 'dog'
learn = load_learner('export.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))}
image = gr.Image()
label = gr.Label()
examples = ['yorkshire_terrier_171.jpg','Abyssinian_17.jpg']
intf = gr.Interface(fn=predict, inputs=image, outputs=label, examples=examples)
intf.launch(share=True)