Spaces:
Sleeping
Sleeping
| # 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.Image(height=360, width=360) | |
| set_label = gr.Textbox(label="Predicted Class") | |
| set_prob = gr.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=examples, | |
| title="ML Demo: Pet classification", | |
| description= "Click examples below for a quick demo") | |
| intf.launch(inline=False,debug=True) |