File size: 1,098 Bytes
83aa8ce
fea75e2
 
 
 
83aa8ce
fea75e2
 
83aa8ce
fea75e2
83aa8ce
 
fea75e2
83aa8ce
fea75e2
83aa8ce
fea75e2
83aa8ce
fea75e2
 
83aa8ce
fea75e2
 
 
 
 
83aa8ce
c5f3a19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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()