hpchan/pet_breed_classifier
0
1from fastai.vision.all import *2import gradio as gr3 4# Load model5learn = load_learner('export.pkl')6 7# Define prediction function8labels = learn.dls.vocab9def classify(img):10 img = PILImage.create(img)11 pred, pred_idx, probs = learn.predict(img)12 return {labels[i]: float(probs[i]) for i in range(len(labels))}13 14# Create a Gradio interface15title = 'Pet Breed Classifier'16description = 'A pet breed classifier trained on the Oxford Pets dataset with fastai.'17examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']18gr.Interface(19 fn=classify,20 inputs=gr.components.Image(height=512, width=512),21 outputs=gr.components.Label(num_top_classes=3),22 examples=examples,23 title=title,24 description=description25 ).launch(share=True)