Spaces:
Sleeping
Sleeping
File size: 673 Bytes
ff445bf 0382a9a ff445bf dda799f |
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 the necessary libraries
from fastai.vision.all import *
import gradio as gr
# Load the trained model
learn = load_learner('export.pkl')
# Get the labels from the model's dataloader
labels = learn.dls.vocab
# Function to classify an image using the model
def classify_image(img):
pred,pred_idx,probs = learn.predict(img)
return dict(zip(labels, probs))
# Create the Gradio interface
image_input = gr.components.Image()
label_output = gr.components.Label()
examples = ["bergen.jpg", "oslo.jpg", "newyork.jpg"]
iface = gr.Interface(
fn=classify_image,
inputs=image_input,
outputs=label_output,
examples=examples
)
iface.launch() |