MyFastAI / app.py
Chipmunk91's picture
Rename app to app.py
a271d90 verified
raw
history blame
817 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../Untitled-1.ipynb.
# %% auto 0
__all__ = ['model_path', 'learn', 'categories', 'is_cat', 'classify_image']
# %% ../../Untitled-1.ipynb 0
import gradio as gr
from fastai.vision.all import *
def is_cat(x): return x[0].isupper()
# %% ../../Untitled-1.ipynb 2
model_path = Path('model.pkl')
learn = load_learner(model_path)
# %% ../../Untitled-1.ipynb 4
categories = ('dog', 'cat')
def classify_image(img):
pred,idx,probs = learn.predict(img)
return dict(zip(categories, map(float,probs)))
# %% ../../Untitled-1.ipynb 6
gr.Interface(fn = classify_image,
inputs="image",
outputs="label",
title = "Dog or Cat",
description="Sample workflow",
examples = ['dog.jpg']
).launch()