pet_classifyer / app.py
Norbert Henseler
examples
b6e817c
# AUTOGENERATED! DO NOT EDIT! File to edit: 02_nh_predict.ipynb (unless otherwise specified).
__all__ = ['is_cat', 'path', 'learn_inf', 'categories', 'classify_image', 'image', 'label', 'examples', 'inf']
# Cell changed
import gradio as gr
from fastai.vision.all import *
import skimage
# Cell
def is_cat(x):
if os.path.basename(x)[0].isupper():
return 'cat'
else:
return 'dog'
# Cell
path = Path()
# path.ls(file_exts='.pkl')
# Cell
learn_inf = load_learner(path/'model.pkl')
# Cell
categories = ('cat', 'dog')
# Cell
def classify_image( img):
pred, idx, probs = learn_inf.predict( img)
return dict( zip(categories, map( float, probs)))
# Cell
title = "Pet Breed Classifier"
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
image = gr.inputs.Image( shape = (192, 192))
label = gr.outputs.Label( num_top_classes=3)
examples = [['cat.jpg'], ['dog.jpg']]
interpretation = 'default'
enable_queue = True
gr.Interface(fn=classify_image, inputs=image, outputs=label, title=title, description=description, article=article, examples=examples, interpretation=interpretation, enable_queue=enable_queue).launch()
# image = gr.inputs.Image( shape = (192, 192))
# label = gr.outputs.Label()
# title = "Pet Breed Classifier"
# description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
#
#
# examples = ['./cat.jpg', './dog.jpg']
#
# inf = gr.Interface( fn = classify_image, inputs = image, outputs = label, examples = examples, title = "Cat or a dog?")
# inf.launch()