# AUTOGENERATED! DO NOT EDIT! File to edit: four-way-classifier.ipynb. # %% auto 0 __all__ = ['learn', 'categories', 'description', '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 7 description=''' A simple 4-way classifier that categorizes images as 'snake', 'bird', 'otter' or 'forest'. Refined from an initial ResNet18 model downloaded from HuggingFace. **DISCLAIMER**: the images here are merely for demonstration purposes. I don't own any of them and I'm not making money from them. ''' image = gr.components.Image() label = gr.components.Label() examples = glob.glob( './*.jpg' ) interf = gr.Interface( title='Simple 4-way image classifier', description=description, fn=classify_image, inputs=image, outputs=label, examples=examples, allow_flagging='manual' ) interf.launch( inline=True )