fruits_simple / app.py
iamalos's picture
update app
568fb02
raw
history blame contribute delete
904 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
# %% auto 0
__all__ = ['learner', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']
# %% app.ipynb 1
from fastai.vision.all import *
import gradio as gr
# %% app.ipynb 3
learner = load_learner('model.pkl')
# %% app.ipynb 5
categories = ('apple', 'banana', 'grapefruit', 'lime', 'mandarin', 'orange')
def classify_image(img):
"""Gradio need a f-n that returns a dict of each class and its probability.
It also does not accept tensors.
"""
pred, idx, probs = learner.predict(img)
return dict(zip(categories, map(float, probs)))
# %% app.ipynb 7
image = gr.components.Image(shape=(192,192))
label = gr.components.Label()
examples = ['grapefruit.jpg', 'lime.jpg', 'mandarin.jpg', 'banana.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)