from fastai.vision.all import * import gradio as gr from fastai.learner import load_learner # Load the exported learner learn = load_learner('model.pkl') # Categories (must match your model's label order) categories = ('dog', 'cat') # Prediction function def classify_image(img): pred, idx, probs = learn.predict(img) return dict(zip(categories, map(float, probs))) # Gradio interface setup image = gr.Image(height=192, width=192) label = gr.Label() examples = ['dog.jpg', 'cat.jpg', 'whatever.jpg'] # These must exist in the same folder intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) # Launch app (Hugging Face Spaces will handle this) intf.launch()