Spaces:
Sleeping
Sleeping
# AUTOGENERATED! DO NOT EDIT! File to edit: ../02x-prototype_gradio_interface.ipynb. | |
# %% auto 0 | |
__all__ = ['learner', 'classes', 'examples', 'interface', 'is_cat', 'predict'] | |
# %% ../02x-prototype_gradio_interface.ipynb 1 | |
!pip install -U torchvision==0.8.1 | |
!pip install -U fastai==2.1 | |
!pip install -Uqq fastbook | |
import gradio as gr | |
from huggingface_hub import from_pretrained_fastai | |
def is_cat(x): | |
return x[0].isupper() | |
# %% ../02x-prototype_gradio_interface.ipynb 2 | |
learner = from_pretrained_fastai('model.pkl') | |
# %% ../02x-prototype_gradio_interface.ipynb 5 | |
classes = ('Dog', 'Cat') | |
def predict(img): | |
label, size, probs = learner.predict(img) | |
return dict(zip(classes, map(float, probs))) | |
# %% ../02x-prototype_gradio_interface.ipynb 6 | |
examples = ["Dog.jpg", "Cat.jpg", "Cat2.jpg", "dunno.jpg"] | |
interface = gr.Interface(fn=predict, inputs='image', outputs='label', examples=examples) | |
interface.launch() | |