Ottermad/pet-classifier
1
1import gradio as gr2from fastai.vision.all import *3import skimage4 5def label_func(x): 6 return x.parent.name7 8learn = load_learner('model (2).pkl')9 10labels = learn.dls.vocab11 12def predict(img):13 img = PILImage.create(img)14 pred,pred_idx,probs = learn.predict(img)15 return {labels[i]: float(probs[i]) for i in range(len(labels))}16 17title = "MNIST"18description = "Fast.ai Lesson 2"19interpretation='default'20enable_queue=True21 22gr.Interface(23 fn=predict,24 inputs=gr.inputs.Image(shape=(28, 28)),25 outputs=gr.outputs.Label(num_top_classes=10),26 title=title,27 description=description,28 interpretation=interpretation,29 enable_queue=enable_queue30).launch()31 