# AUTOGENERATED! DO NOT EDIT! File to edit: load.ipynb. # %% auto 0 __all__ = ['learn', 'categories', 'examples', 'intf', 'label_func', 'classify_image'] # %% load.ipynb 1 from fastai.vision.all import * import gradio as gr # Define a labeling function: if filename starts with uppercase, it's a cat; otherwise, it's a dog def label_func(f): # Return "Cat" for cat (uppercase first letter), "Dog" for dog (lowercase) return "Cat" if f[0].isupper() else "Dog" # %% load.ipynb 3 learn = load_learner('catdog_model.pkl') # %% load.ipynb 5 categories = ['Cat', 'Dog'] def classify_image(img): pred, pred_idx, probs = learn.predict(img) return {categories[i]: float(probs[i]) for i in range(len(categories))} # %% load.ipynb 7 examples = ['examples/cat.jpg', 'examples/dog.jpeg', 'examples/catdog.png'] intf = gr.Interface(fn=classify_image, inputs=gr.Image(), outputs=gr.Label(), examples=examples, title="Cat vs Dog Classifier", description="Upload an image of a cat or a dog, and the model will predict which it is.") intf.launch(share=True, inline=False)