Spaces:
Runtime error
Runtime error
File size: 718 Bytes
39fd66c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from fastai.vision.all import *
import gradio as gr
# gradio
learn_caltech101 = load_learner('image_classifier_caltech101.pkl')
# build prediction function
labels = learn_caltech101.dls.vocab
def predict(img):
img = PILImage.create(img)
pred, pred_idx, probs = learn_caltech101.predict(img)
return {str(labels[i]):float(probs[i]) for i in range(len(labels))}
# build gradio interface
gradio_interface = gr.Interface(
title = "Caltech_101 Image Classifier",
description = "A simple image classifier based on the Caltech_101 dataset.",
fn=predict,
inputs = gr.inputs.Image(shape=(224,224)),
outputs = gr.outputs.Label(num_top_classes=5)
)
gradio_interface.launch(enable_queue=True) |