bear_classifier / app.py
shuraimi's picture
Update app.py
78f495f verified
raw
history blame contribute delete
No virus
708 Bytes
__all__=['learn','classify_image','categories','examples','intf']
import gradio as gr
from fastai.vision.all import *
#load the learner
learn=load_learner('bear_classifier_myver.pkl')
# define categories
categories=['Black bear','Grizzly bear','Teddy bear']
# define the function to classify images
def classify_image(img):
pred,idx,probs=learn.predict(img)
return dict(zip(categories,map(float,probs)))
# example images
examples=['grizzly_bear1.jpg','grizzly_bear2.jpg','black+bear1.jpg','black_bear2.jpg','teddy1.jpg','teddy1.jpg']
# creating the interface
intf=gr.Interface(fn=classify_image,inputs="image",outputs="label",examples=examples,title='Bear Classifier')
intf.launch(inline=False)