minima / app.py
lcbasu's picture
feat: Add cat classifier app
93aef43
raw
history blame contribute delete
839 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: ../test_hugging_face.ipynb.
# %% auto 0
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'iface', 'is_cat', 'classify_image']
# %% ../test_hugging_face.ipynb 2
from fastai.vision.all import *
import gradio as gr
def is_cat(): return x[0].isupper()
# %% ../test_hugging_face.ipynb 4
learn = load_learner('model.pkl')
# %% ../test_hugging_face.ipynb 6
categories = ('Dog', 'Cat')
def classify_image(img):
pred, id, prob = learn.predict(img)
return dict(zip(categories, map(float, prob)))
# %% ../test_hugging_face.ipynb 8
image = gr.components.Image(width=192, height=192)
label = gr.components.Label()
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
iface.launch(inline=False)