minimal / app.py
Michela Ledwidge
cleaned up autogen code so also runs in notebook
35f6f2d
raw
history blame contribute delete
940 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: ../02_production.ipynb.
# %% auto 0
__all__ = ['categories', 'model', 'stem', 'learn', 'image', 'label', 'file_list', 'examples', 'intf', 'classify_image']
# %% ../02_production.ipynb 52
from fastai.vision.all import *
import gradio as gr
# %% ../02_production.ipynb 54
categories = ('black','grizzly','teddy')
# %% ../02_production.ipynb 57
def classify_image(img):
pred,idx, probs = learn.predict(img)
return dict(zip(categories, map(float,probs)))
# %% ../02_production.ipynb 59
model = 'model.pkl'
stem = 'examples/'
# %% ../02_production.ipynb 61
learn = load_learner(model)
image = gr.components.Image(width=224, height=224)
label = gr.components.Label()
file_list = ['grizzly.jpg', 'black.jpg', 'teddy.jpg']
examples = list(map(lambda x: stem + x, file_list))
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label,examples=examples)
intf.launch(inline=False)