ipchels01's picture
Update app.py
d69f8b3 verified
# Import necessary libraries
import gradio as gr
from fastai.vision.all import *
import skimage
# Load a pre-trained deep learning model for image classification
learn = load_learner('export.pkl')
# Get the labels (classes) for the model's predictions
labels = learn.dls.vocab
# Define a function to make predictions on input images
def predict(img):
# Create a PIL image from the input image
img = PILImage.create(img)
# Use the loaded model to make predictions on the image
pred,pred_idx,probs = learn.predict(img)
# Create a dictionary to map labels to their corresponding probabilities
return {labels[i]: float(probs[i]) for i in range(len(labels))}
# Set up the Gradio interface with relevant information
title = "What's my Pet Breed?"
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
interpretation='default'
enable_queue=True
# Launch the Gradio interface with the predict function for image classification
gr.Interface(fn=predict,inputs="image",outputs="label").launch()