first_project / app.py
hhemanth's picture
Adding model and app file
ae8852a
raw
history blame contribute delete
831 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: ../cat_dog_predict.ipynb.
# %% auto 0
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image']
# %% ../cat_dog_predict.ipynb 1
from fastai.vision.all import *
import gradio as gr
def is_cat(x): return x[0].upper()
# %% ../cat_dog_predict.ipynb 3
learn = load_learner('cat_dog_model.pkl')
# %% ../cat_dog_predict.ipynb 4
categories = ('Dog', 'Cat')
def classify_image(img):
pred,idx,probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
# %% ../cat_dog_predict.ipynb 6
image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = ['dog.jpeg', 'cat.jpeg','cat.png', 'bear.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)