from fastai.vision.all import * import gradio as gr import timm pat = r'^(.*)_\d+.jpg' learn = load_learner('model_convnext.plk') labels = learn.dls.vocab def classify_image(img): img = PILImage.create(img) pred, idx, probs = learn.predict(img) #return {labels[i] : float(probs[i]) for i in range(len(labels))} return dict(zip(labels, map(float,probs))) image = gr.inputs.Image(shape=(256,256)) label = gr.outputs.Label(num_top_classes=3) examples = ['Basset-Hound-standing-in-the-garden.jpg'] title = "Cat&Dog Breed Classifier" description = "A cat and dog breed classifier trained on the Oxford Pets dataset." intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) intf.launch()