File size: 927 Bytes
3aa08d0
 
 
 
feedf3d
 
 
 
 
 
 
3aa08d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
from fastai.vision.all import *
import gradio as gr
import skimage

from pathlib import Path

# Assuming your model file is in the same directory as your script
model_path = Path("puppy.pkl")

# Load the model using the relative path
learn = load_learner(model_path)

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 = "Puppy Breed Classifier"
description = "A puppy breed classifier trained on a custom dataset from DDG images with fastai. Created as a demo for Gradio and HuggingFace Spaces."
image = gr.Image(height=215, width=215)
label = gr.Label()
examples = [['corgi puppy.jfif'], ['golden retriever.jfif'], ['husky bear.jfif']]


intf = gr.Interface(fn=predict, inputs=image, outputs=label, title=title, description=description,examples=examples)
intf.launch(inline=False)