Spaces:
Build error

pdlfc_bears / app.py
timkral's picture
Fix import
089172c
Raw History Blame Contribute Delete
889 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: drive/MyDrive/PDLfC/PDLfC_Chap2.ipynb.
# %% auto 0
__all__ = ['learn_inf', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']
# %% drive/MyDrive/PDLfC/PDLfC_Chap2.ipynb 27
from fastai.vision.all import load_learner
learn_inf = load_learner('pdlfc_bears.pkl')
# %% drive/MyDrive/PDLfC/PDLfC_Chap2.ipynb 28
categories = ('black', 'grizzly', 'teddy')
def classify_image(img):
img = img.resize((224, 224))
pred, idx, probs = learn_inf.predict(img)
return dict(zip(categories, map(float, probs)))
# %% drive/MyDrive/PDLfC/PDLfC_Chap2.ipynb 30
import gradio as gr
image = gr.Image(type="pil")
label = gr.Label()
examples = ['images/grizzly.jpg', 'images/black.jpg', 'images/plant.jpg', 'images/teddy.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)