Spaces:
Sleeping
Sleeping
File size: 810 Bytes
547b1fc 00eec54 547b1fc f54ee15 547b1fc 266b4cd 547b1fc |
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 30 |
import gradio as gr
from fastai.vision.all import *
from huggingface_hub import hf_hub_download
# Download the model from Hugging Face
model_path = hf_hub_download(repo_id="principle/bears-classifier-model", filename="bears_modle.pkl")
# Load the model
learn = load_learner(model_path)
# Define the prediction function
def classify_bear(img):
pred, pred_idx, probs = learn.predict(img)
return {
'black': float(probs[0]),
'grizzly': float(probs[1]),
'teddy': float(probs[2])
}
# Create the Gradio interface
iface = gr.Interface(
fn=classify_bear,
inputs=gr.Image(),
outputs=gr.Label(num_top_classes=3),
title="Bear Classifier",
description="Upload an image to classify the type of bear: grizzly, black, or teddy."
)
# !
# Launch the app
iface.launch() |