# AUTOGENERATED! DO NOT EDIT! File to edit: four-way-classifier.ipynb. | |
# %% auto 0 | |
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'interf', 'classify_image'] | |
# %% four-way-classifier.ipynb 1 | |
from fastai.vision.all import * | |
import gradio as gr | |
import PIL | |
import glob | |
# %% four-way-classifier.ipynb 3 | |
learn = load_learner( 'simple-image-classifier.pkl' ) | |
# %% four-way-classifier.ipynb 5 | |
categories = [ 'bird', 'forest', 'otter', 'snake' ] | |
def classify_image( img ): | |
pred, idx, probs = learn.predict( img ) | |
# print( 'This is a %s'%pred ) | |
return dict( zip( categories, map( float, probs ) ) ) | |
# %% four-way-classifier.ipynb 6 | |
image = gr.components.Image() | |
label = gr.components.Label() | |
examples = glob.glob( './resized-*.jpg' ) | |
interf = gr.Interface( fn=classify_image, inputs=image, outputs=label, examples=examples, allow_flagging='manual' ) | |
interf.launch( inline=True ) | |