minima / app.py
hatruong's picture
update app.py
6bbb193
Raw
History Blame Contribute Delete
1.22 kB
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
# %% auto 0
__all__ = ['model_path', 'predictor', 'labels', 'image', 'label', 'title', 'description', 'examples', 'interpretation',
'enable_queue', 'intf', 'is_cat', 'classify_image']
# %% app.ipynb 2
from fastai.vision.all import *
import gradio as gr
# %% app.ipynb 3
def is_cat(x):
return x[0].isupper()
# %% app.ipynb 13
model_path = 'dog_cat.pkl'
predictor = load_learner(Path(model_path))
# %% app.ipynb 16
labels = predictor.dls.vocab
labels
# %% app.ipynb 17
def classify_image(img):
img = PILImage.create(img)
pred, pred_idx, probs = predictor.predict(img)
return dict(zip(labels, map(float, probs)))
# return {labels[i]: float(probs[i]) for i in range(len(labels))}
# %% app.ipynb 19
image = gr.inputs.Image(shape=(192, 192))
label = gr.outputs.Label()
title = 'Is The Cat?'
description = 'a sample of deploying model to gradio'
examples = ['dog_1.jpeg', 'cat_01.jpeg', 'elephant.jpeg']
interpretation = 'default'
enable_queue = True
intf = gr.Interface(
fn=classify_image, inputs=image, outputs=label,
title=title, description=description, examples=examples,)
intf.launch(share=True, inline=False)