from fastai.vision.all import * import gradio as gr learner = load_learner('export.pkl') title = "Bird Species Classifier" description = "A bird species classifier trained on the BIRDS 400 dataset from Kaggle with fastai. Created as a demo for Gradio and HuggingFace Spaces." labels = learner.dls.vocab def predict(img): img = PILImage.create(img) pred, pred_idx, probs = learner.predict(img) return {labels[i]: float(probs[i]) for i in range(len(labels))} examples = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg', '14.jpg', '15.jpg'] gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(224, 224)), outputs=gr.outputs.Label(num_top_classes=3), title=title, description=description, examples=examples).launch(share=True, debug=True)