|
|
|
|
|
|
|
__all__ = ['learn', 'options', 'image', 'label', 'examples', 'intf', 'whichBear', 'classify_img']
|
|
|
|
|
|
from fastai.vision.all import *
|
|
import gradio as gr
|
|
|
|
|
|
def whichBear(x): return x[0].isBear()
|
|
|
|
|
|
learn = load_learner('model.pkl')
|
|
|
|
|
|
|
|
options = ("grizzly", "black", "teddy")
|
|
|
|
def classify_img(img):
|
|
pred,idx,probs = learn.predict(img)
|
|
return dict(zip(options, map(float, probs)))
|
|
|
|
|
|
image = gr.Image()
|
|
label = gr.Label()
|
|
examples = ["brown_bear.jpg", "grizzly_bear.jpg", "teddy_bear.jpg"]
|
|
|
|
intf = gr.Interface(fn=classify_img, inputs=image, outputs=label, examples=examples)
|
|
intf.launch(inline=False)
|
|
|