Spaces:
Runtime error
Runtime error
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb. | |
# %% auto 0 | |
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image'] | |
# %% ../app.ipynb 0 | |
from fastai.vision.all import * | |
import PIL | |
import gradio as gr | |
def is_cat(x): | |
return x[0].isupper() | |
# %% ../app.ipynb 3 | |
learn = load_learner('model.pkl') | |
# %% ../app.ipynb 5 | |
categories = ('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', 'St.Bernard', 'Samyoed', 'Scottish Terrier', 'Shiba Inu', 'Staffordshire Bull Terrier', | |
'Wheaten Terrier', 'Yorkshire Terrier', 'Abyssian', 'Bengal', 'Birman', 'Bombay', 'British Shorthair', | |
'Egyptian Mau', 'Main Coon', 'Persian', 'Ragdoll', 'Russian Blue', 'Siamese', 'Sphynx') | |
def classify_image(img): | |
pred, idx, probs = learn.predict(img) | |
return dict(zip(categories, map(float, probs))) | |
# %% ../app.ipynb | |
image = gr.Image(shape=(192,192)) | |
label = gr.Label() | |
examples = ['americanBulldog.jpg', 'bernard.jpg', 'ragdoll.jpg'] | |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
intf.launch(inline=False) | |