# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb. # %% auto 0 __all__ = ['learn', 'options', 'image', 'label', 'examples', 'intf', 'whichBear', 'classify_img'] # %% app.ipynb 2 from fastai.vision.all import * import gradio as gr import pathlib import platform def whichBear(x): return x[0].isBear() # %% app.ipynb 4 # Function to handle the path conversion if necessary def fix_path(): if platform.system().lower() != "windows": pathlib.WindowsPath = pathlib.PosixPath # Call the function to fix path handling before loading the model fix_path() # Load the learner learn = load_learner("model.pkl") # %% app.ipynb 6 options = ("grizzly", "black", "teddy") def classify_img(img): pred, idx, probs = learn.predict(img) return dict(zip(options, map(float, probs))) # %% app.ipynb 8 image = gr.Image() label = gr.Label() examples = ["brown_bear.jpg", "grizzly_bear.jpg", "teddy_bear.jpg"] intf = gr.Interface(fn=classify_img, inputs=image, outputs=label, examples=examples) intf.launch(inline=False)