# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb. # %% auto 0 __all__ = ['path', 'dls', 'im', 'learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image'] # %% ../app.ipynb 2 import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' from fastai.vision.all import * # %% ../app.ipynb 3 path = untar_data(URLs.PETS)/'images' # %% ../app.ipynb 4 def is_cat(x): return x[0].isupper() # %% ../app.ipynb 5 dls = ImageDataLoaders.from_name_func('.', get_image_files(path), valid_pct=0.2, seed=42, label_func=is_cat, item_tfms=Resize(192)) # %% ../app.ipynb 6 #learn = vision_learner(dls, resnet18, metrics=error_rate) #learn.fine_tune(1) # %% ../app.ipynb 7 #learn.export('model.pkl') # %% ../app.ipynb 8 im = PILImage.create('dog.jpg') im.thumbnail((192,192)) im # %% ../app.ipynb 9 learn = load_learner('model.pkl') # %% ../app.ipynb 10 learn.predict(im) # %% ../app.ipynb 11 categories = ('Dog', 'Cat') # %% ../app.ipynb 12 def classify_image(img): pred, idx, probs=learn.predict(img) return dict(zip(categories, map(float, probs))) # %% ../app.ipynb 13 classify_image(im) # %% ../app.ipynb 15 import gradio as gr # %% ../app.ipynb 16 image = gr.inputs.Image(shape=(192,192)) label = gr.outputs.Label() examples = ['dog.jpg', 'cat.jpeg', 'raccoon.jpg'] intf = gr.Interface(fn=classify_image, inputs=image, outputs=label,examples=examples) intf.launch(inline=False,share=True)