Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from fastai.vision.all import * | |
| def is_cat(x): return x[0].isupper() | |
| learner = load_learner("model.pkl") | |
| categories = ("Dog", "Cat") | |
| def classify_image(img): | |
| if img is None: | |
| return {} | |
| img = PILImage.create(img) | |
| pred, pred_idx, probs = learner.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| demo = gr.Interface( | |
| fn=classify_image, | |
| inputs=gr.Image(type="pil"), | |
| outputs=gr.Label(), | |
| examples=["cat1.jpeg", "dog1.jpeg", "cat2.jpeg", "dog2.jpg"], | |
| cache_examples=False, | |
| ) | |
| demo.launch() | |