# AUTOGENERATED! DO NOT EDIT! File to edit: DogCat.ipynb. # %% auto 0 __all__ = ['temp', 'learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image'] # %% DogCat.ipynb 1 from fastai.vision.all import * import gradio as gr def is_cat(x): return x[0].isupper() # %% DogCat.ipynb 3 import pathlib # Set the PosixPath to str temp = pathlib.PosixPath pathlib.PosixPath = pathlib.WindowsPath # Load the model learn = load_learner('model.pkl') # Revert the change pathlib.PosixPath = temp # %% DogCat.ipynb 5 categories = ('Dog', 'Cat') def classify_image(img): img = PILImage.create(img) img = img.resize((192, 192)) pred, idx, probs = learn.predict(img) return dict(zip(categories, map(float, probs))) # %% DogCat.ipynb 7 image = gr.Image() label = gr.Label() examples = ['angry_chihuahua.png', 'CatOnCatnip.jpg', 'harrypotterDog.jpg', 'elbanialpxenu.jpg'] intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) intf.launch(inline=False)