whywynn's picture
Updating app.py to fix path issues
feedf3d
raw
history blame contribute delete
927 Bytes
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)