Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.vision.all import *
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Load the model
|
| 5 |
+
learn = load_learner('model(1).pkl')
|
| 6 |
+
|
| 7 |
+
# Define prediction function
|
| 8 |
+
def classify_image(img):
|
| 9 |
+
pred, idx, probs = learn.predict(img)
|
| 10 |
+
return {str(learn.dls.vocab[i]): float(probs[i]) for i in range(len(probs))}
|
| 11 |
+
|
| 12 |
+
# Launch Gradio app
|
| 13 |
+
gr.Interface(
|
| 14 |
+
fn=classify_image,
|
| 15 |
+
inputs=gr.Image(type="pil"),
|
| 16 |
+
outputs=gr.Label(num_top_classes=2),
|
| 17 |
+
title="Cat vs Dog Classifier",
|
| 18 |
+
description="Upload an image of a pet and the model will predict if it's a cat or a dog."
|
| 19 |
+
).launch()
|