sarulathas/basic
0
1# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.2 3# %% auto 04__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'interface', 'is_cat', 'classify_image']5 6# %% app.ipynb 17from fastai.vision.all import *8import gradio as gr9 10def is_cat(x): return x[0].isupper()11 12# %% app.ipynb 313# get the pretrained learner we have downloaded14learn = load_learner('model.pkl')15 16# %% app.ipynb 517# create the method that gradio needs to convert the learner output to result18 19categories = ('dog', 'cat')20 21def classify_image(image):22 pred, idx, probs = learn.predict(image)23 return dict(zip(categories, map(float, probs)))24 25# %% app.ipynb 726# create a gradio interface27 28image = gr.inputs.Image(shape=(192,192))29label = gr.outputs.Label()30examples = ['dog.jpg', 'cat.jpg', 'dogcat.jpg', 'dunno.jpg']31 32interface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)33interface.launch(inline=False)34 