# AUTOGENERATED! DO NOT EDIT! File to edit: dog_cat_predicter.ipynb. | |
# %% auto 0 | |
__all__ = ['learn', 'labels', 'image', 'label', 'examples', 'interface', 'is_cat', 'predict_image'] | |
# %% dog_cat_predicter.ipynb 1 | |
from fastai.vision.all import * | |
import gradio as gr | |
# %% dog_cat_predicter.ipynb 3 | |
def is_cat(x): return x[0].isupper() | |
learn = load_learner('models/dog_cat_model.pkl') | |
# %% dog_cat_predicter.ipynb 5 | |
labels = ['Dog', 'Cat'] | |
def predict_image(img): | |
#Function to predict input image and return a dictionary with each label and probability (as a float) | |
pred,pred_idx,probs = learn.predict(img) | |
return dict(zip(labels, map(float, probs))) | |
# %% dog_cat_predicter.ipynb 7 | |
#Define the Gradio Interface | |
image = gr.inputs.Image(shape=(224, 224)) | |
label = gr.outputs.Label() | |
examples = ['dog.jpg', 'cat.jpg', 'hamster.jpg'] | |
interface = gr.Interface(fn=predict_image, inputs=image, outputs=label, examples=examples) | |
interface.launch(inline=False) | |