Spaces:
Runtime error
Runtime error
| # -*- coding: utf-8 -*- | |
| """dogs_cats.ipynb | |
| Automatically generated by Colaboratory. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1M-mzhZdFQ2XWBSbLCuKzrmLsm0aLEYxQ | |
| ## Gradio Pets | |
| """ | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| def is_cat(x): return x[0].isupper() | |
| learn= load_learner('model.pk1') | |
| categories= ('Dog', 'Cat') | |
| def classify_image(img): | |
| pred,idx,probs= learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| im=PILImage.create('dog.jpg') | |
| im.thumbnail((192,192)) | |
| im | |
| learn.predict(im) | |
| classify_image(im) | |
| examples= ['dog.jpg', 'cat.jpg'] | |
| gr.Interface(fn=classify_image, inputs=[gr.Image(type="pil")], outputs=[gr.Label(num_top_classes=2)], examples=examples).launch() |