Spaces:
Runtime error
Runtime error
| from fastai.vision.all import * | |
| import gradio as gr | |
| # Load the model | |
| learn = load_learner('model.pkl') | |
| # Define prediction function | |
| def classify_image(img): | |
| pred, idx, probs = learn.predict(img) | |
| return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))} | |
| # Gradio Interface | |
| interface = gr.Interface( | |
| fn=classify_image, | |
| inputs=gr.Image(type="pil"), | |
| outputs=gr.Label(num_top_classes=2), | |
| title="Cat vs Dog Classifier", | |
| description="Upload an image of a cat or a dog. The model will predict which one it is.", | |
| examples=[ | |
| ["cat.jpg"], | |
| ["dog.jpg"] | |
| ] | |
| ) | |
| # Launch app | |
| if __name__ == "__main__": | |
| interface.launch() | |