experimentation / foo.py
danielyjtan
Add dog cat classifier
05b9b72
raw
history blame
802 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: knnccb.ipynb.
# %% auto 0
__all__ = ['categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image']
# %% knnccb.ipynb 1
from fastai.vision.all import *
import gradio as gr
def is_cat(x):
return x[0].isupper()
# %% knnccb.ipynb 8
categories = ('Dog', 'Cat')
# %% knnccb.ipynb 9
def classify_image(img):
pred, idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
# %% knnccb.ipynb 11
image = gr.components.Image(height = 192, width = 192)
label = gr.components.Label()
examples = ['example-dog.jpg', 'example-cat.jpg']
# %% knnccb.ipynb 12
intf = gr.Interface(fn = classify_image, inputs = image, outputs = label, examples = examples)
# %% knnccb.ipynb 13
intf.launch(inline = False, share=True)