bearsprediction / app.py
whywynn's picture
Updating app.py per Gradio tutorial v4
deffedf
raw
history blame
929 Bytes
from fastai.vision.all import *
import gradio as gr
import skimage
learn = load_learner('bearmodel.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 = "Bear Breed Classifier"
description = "A bear breed classifier trained on a custom dataset from DDG images with fastai. Created as a demo for Gradio and HuggingFace Spaces."
#interpretation ='default'
image = gr.Image(height=192, width=192)
label = gr.Label()
examples = ['black bear.jpg', 'grizzly bear.jpg', 'teddy bear.jpg']
#enable_queue=True
intf = gr.Interface(fn=predict, inputs=image, outputs=label, title=title, description=description,examples=examples)
intf.launch(inline=False)
#def greet(name):
# return "Hello " + name + "!!"
#demo = gr.Interface(fn=greet, inputs="text", outputs="text")
#demo.launch()