File size: 1,113 Bytes
e2490f0 ddd1611 e2490f0 bc2a41f e2490f0 ddd1611 e2490f0 ddd1611 e2490f0 bc2a41f ddd1611 e2490f0 bc2a41f e2490f0 c1f893e |
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 32 33 34 35 36 37 38 39 40 41 |
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
# %% auto 0
__all__ = ['example_image_paths', 'learn', 'categories', 'image', 'label', 'intf', 'classify_image']
# %% ../app.ipynb 2
from fastai.vision.all import *
from PIL import Image
import matplotlib.pyplot as plt
import gradio as gr
from nbdev.export import nb_export
# %% ../app.ipynb 4
example_image_paths = [
'images/tfh-dogs-alcohol.jpg',
'images/dbt-techy-things.jpg',
'images/pbs-book-festival.jpg',
'images/hth-underwear.jpg',
'images/xk-compiling.jpg',
'images/rwo-family-reunion.jpg',
'images/itb-golf-saucer.jpg'
]
# %% ../app.ipynb 6
learn = load_learner('models/02.pkl')
# %% ../app.ipynb 8
categories = ('tfs', 'xk', 'dbt', 'pbs', 'rwo', 'hth', 'itb')
def classify_image(img):
pred, idx, probs = learn.predict(img)
return dict(zip(sorted(categories), map(float, probs)))
# %% ../app.ipynb 10
image = gr.Image(height=192, width=192)
label = gr.Label()
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_image_paths)
intf.launch(inline=False, share=True)
|