Spaces:
Running
Running
# app.py | |
__all__ = ['bird', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf'] | |
# Load categories from label.txt | |
with open('labels.txt', 'r') as file: | |
categories = [line.strip() for line in file.readlines()] | |
# Load the model | |
from fastai.vision.all import * | |
import gradio as gr | |
learn = load_learner('model.pkl') | |
# Define the classification function | |
def classify_image(img): | |
preds, idx, probs = learn.predict(img) | |
return dict(zip(categories, map(float, probs))) | |
# Gradio components | |
image = gr.components.Image() | |
label = gr.components.Label(num_top_classes=3) | |
# Create and launch the interface | |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label) | |
intf.launch(inline=False, share=True) |