Spaces:
Sleeping
Sleeping
___all___ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf'] | |
from fastai.vision.all import * | |
import gradio as gr | |
# Load the trained model | |
learn = load_learner('model.pkl') | |
# Define the categories based on your model's output | |
categories = learn.dls.vocab | |
# Define the function to classify images | |
def classify_image(img): | |
pred, idx, probs = learn.predict(img) | |
return dict(zip(categories, map(float, probs))) | |
# Define the Gradio components | |
image = gr.Image(type='pil', label='Input Image') | |
label = gr.Label() | |
examples = ['example1.jpeg', 'example2.jpeg', 'example3.jpeg'] # Replace with your example images | |
# Create and launch the Gradio interface | |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, title="Image Classifier", examples=examples) | |
intf.launch(inline=False) |