tests / app.py
NekoNeko512's picture
Update app.py
f62782a verified
raw
history blame contribute delete
905 Bytes
# 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
import gradio as gr
from fastai.vision.all import *
def is_cat(x):
return x[0].isupper()
# %% ../02x-prototype_gradio_interface.ipynb 2
import pathlib
plt = platform.system()
if plt != 'Windows': pathlib.WindowsPath = pathlib.PosixPath
learner = load_learner('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()