Spaces:
Sleeping
Sleeping
File size: 890 Bytes
775f235 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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()
|