coffee-or-tea / app.py
jjglilleberg's picture
add application files
775f235
raw
history blame contribute delete
890 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../../../../Colab Notebooks/Ch2.ipynb.
# %% auto 0
__all__ = ['learn_inf', 'categories', 'examples', 'demo', 'classify_image']
# %% ../../../../../Colab Notebooks/Ch2.ipynb 26
from fastai.vision.all import *
import gradio as gr
# %% ../../../../../Colab Notebooks/Ch2.ipynb 27
learn_inf = load_learner('export.pkl')
# %% ../../../../../Colab Notebooks/Ch2.ipynb 30
categories = learn_inf.dls.vocab
# %% ../../../../../Colab Notebooks/Ch2.ipynb 31
def classify_image(img):
learn_inf.predict(img)
pred, idx, probs = learn_inf.predict(img)
print(pred, idx, probs)
return dict(zip(categories, map(float, probs)))
# %% ../../../../../Colab Notebooks/Ch2.ipynb 33
examples=['tea.jpg', 'coffee.jpg']
demo = gr.Interface(
fn=classify_image,
inputs=gr.Image(),
outputs=gr.Label(),
examples=examples)
demo.launch()