bear / app.py
luciouw's picture
Update app.py
5471639
raw
history blame contribute delete
856 Bytes
#__all__=['learn','categories','classify_image','image','label','examples','iface']
import gradio as gr
from fastai import *
#load_learner is in here
#widget suppressed
from fastai.vision.all import *
learn=load_learner('export.pkl')
categories=('Black','Grizzly','Teddy')
def classify_image(img):
pred,idx,probs=learn.predict(img)
#map needed because output (tensor) is not handled by gradio
return dict(zip(categories,map(float,probs)))
image=gr.inputs.Image(shape=(224,224))
label = gr.outputs.Label()
examples=['black.jpg','grizzly.jpg','teddy.jpg']
iface=gr.Interface(fn=classify_image,inputs=image,outputs=label,example=examples)
iface.launch()
#Can be autogenerated from cells preceded by #|export
# Using
#|default_exp <name off the created .py>
#from nbdev.export import notebook2script
#notebook2script('notebookname.ipynb')