|
|
|
|
|
|
|
__all__ = ['example_image_paths', 'learn', 'categories', 'image', 'label', 'intf', 'classify_image'] |
|
|
|
|
|
from fastai.vision.all import * |
|
from PIL import Image |
|
import matplotlib.pyplot as plt |
|
import gradio as gr |
|
from nbdev.export import nb_export |
|
|
|
|
|
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' |
|
] |
|
|
|
|
|
learn = load_learner('models/02.pkl') |
|
|
|
|
|
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))) |
|
|
|
|
|
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) |
|
|