# AUTOGENERATED! DO NOT EDIT! File to edit: catgradio.ipynb. | |
# %% auto 0 | |
__all__ = ['learn', 'categories', 'image_input', 'label_output', 'iface', 'is_cat', 'classify_image'] | |
# %% catgradio.ipynb 2 | |
from fastai.vision.all import * | |
import gradio as gr | |
def is_cat(x): | |
return x[0].isupper() | |
# %% catgradio.ipynb 4 | |
learn = load_learner('model.pkl') | |
# %% catgradio.ipynb 6 | |
categories = ('Dog', 'Cat') | |
def classify_image(img): | |
print('hi') | |
pred,idx,probs = learn.predict(img) | |
return dict(zip(categories, map(float,probs))) | |
# %% catgradio.ipynb 8 | |
image_input = gr.Image(height=192, width=192) | |
label_output = gr.Label() | |
iface = gr.Interface( | |
fn=classify_image, | |
inputs=image_input, | |
outputs=label_output, | |
examples=['dog.jpg', 'cat.jpg', 'dunno.jpg'], | |
) | |
iface.launch(inline=False) | |