# credit: https://huggingface.co/spaces/jph00/testing/tree/main # AUTOGENERATED! DO NOT EDIT! File to edit: . (unless otherwise specified). __all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf'] # Cell from fastai.vision.all import * import gradio as gr def is_cat(x): return x[0].isupper() # Cell learn = load_learner('model.pkl') # Cell categories = ('Dog', 'Cat') def classify_image(img): pred,idx,probs = learn.predict(img) if probs[0]>probs[1]: pred_class = 'This is Dog' else: pred_class = 'This is Cat' return pred_class, dict(zip(categories, map(float,probs))) # Cell image = gr.inputs.Image(shape=(192, 192)) set_label = gr.outputs.Textbox(label="Predicted Class") set_prob = gr.outputs.Label(num_top_classes=2, label="Predicted Probability Per Class") examples = ['test1.jpg', 'test2.jpg', 'test3.jpeg', 'test4.jpeg', 'test5.jpeg', 'test6.jpeg', 'test7.jpeg', 'test8.jpeg', 'test9.jpeg', 'test10.jpeg'] intf = gr.Interface(fn=classify_image, inputs=image, outputs=[set_label, set_prob], examples_per_page = 2, examples=examples, title="CSCI4750/5750 Demo 2: Pet classification", description= "Click examples below for a quick demo", theme = 'huggingface', layout = 'vertical') intf.launch(inline=False,debug=True)