mpfoley73's picture
deprecated inputs and outputs
d5b1e82
raw
history blame
1.7 kB
# Gradio app interface to dog_breed_classifier model fine-tuned on kaggle.
# This is the project from lesson 2 of the fastai Deep Learning course.
#
# Reference:
# Kaggle: https://www.kaggle.com/code/mpfoley73/dog-breed-classification
# Dog Breed dataset: https://www.kaggle.com/datasets/khushikhushikhushi/dog-breed-image-dataset
# Tanishq blog: https://www.tanishq.ai/blog/posts/2021-11-16-gradio-huggingface.html
# Fastai: https://course.fast.ai/Lessons/lesson2.html
#
import gradio as gr
from fastai.vision.all import *
import skimage
learn = load_learner('dog_breed_classifier.pkl')
labels = learn.dls.vocab
def predict(img):
img = PILImage.create(img)
pred,pred_idx,probs = learn.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
title = "Dog Breed Classifier"
description = "A dog breed classifier trained on the Dog Breed 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>"
examples = ['chester_14.jpg']
interpretation='default'
enable_queue=True
# Construct a Gradio Interface object from the function (usually an ML model
# inference function), Gradio input components (the number should match the
# number of function parameters), and Gradio output components (the number
# should match the number of values returned by the function).
gr.Interface(
fn=predict,
inputs=gr.Image(),
outputs=gr.Label(),
title=title,
description=description,
article=article,
examples=examples,
interpretation=interpretation,
enable_queue=enable_queue
).launch()