aewurm98's picture
Update app.py
a5a8d45
# AUTOGENERATED! DO NOT EDIT! File to edit: ../dog-breeds.ipynb.
# %% auto 0
__all__ = ['learn_inf', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']
# %% ../dog-breeds.ipynb 2
from fastai import *
from fastai.vision.all import *
import gradio as gr
# %% ../dog-breeds.ipynb 13
# Load model wherever you plan to use it for inference
learn_inf = load_learner('export2.pkl')
# %% ../dog-breeds.ipynb 15
categories = ['Abyssinian', 'Bengal', 'Birman', 'Bombay', 'British_Shorthair',
'Egyptian_Mau', 'Maine_Coon', 'Persian', 'Ragdoll', 'Russian_Blue',
'Siamese', 'Sphynx', 'american_bulldog', 'american_pit_bull_terrier',
'basset_hound', 'beagle', 'boxer', 'chihuahua', 'english_cocker_spaniel',
'english_setter', 'german_shorthaired', 'great_pyrenees', 'havanese',
'japanese_chin', 'keeshond', 'leonberger', 'miniature_pinscher',
'newfoundland', 'pomeranian', 'pug', 'saint_bernard', 'samoyed',
'scottish_terrier', 'shiba_inu', 'staffordshire_bull_terrier',
'wheaten_terrier', 'yorkshire_terrier']
def classify_image(img):
pred, idx, probs = learn_inf.predict(img)
return dict(zip(categories, map(float,probs)))
# %% ../dog-breeds.ipynb 16
image = gr.Image(shape=(192,192))
label = gr.Label()
examples = ['dog.jpg', 'cat.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=True, share=False)