Spaces:
Sleeping
Sleeping
busebaser
commited on
Commit
·
95c07de
1
Parent(s):
0972752
Deploy Cat-Dog Recognition model
Browse files
app.py
CHANGED
@@ -1,7 +1,23 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import load_learner
|
2 |
import gradio as gr
|
3 |
+
from PIL import Image
|
4 |
|
5 |
+
# Load the trained model
|
6 |
+
model = load_learner('model.pkl')
|
7 |
|
8 |
+
# Define a function to make predictions
|
9 |
+
def predict(image):
|
10 |
+
pred, _, probs = model.predict(image)
|
11 |
+
return f"Prediction: {pred} (Confidence: {probs.max():.2f})"
|
12 |
+
|
13 |
+
# Create the Gradio web interface
|
14 |
+
interface = gr.Interface(
|
15 |
+
fn=predict,
|
16 |
+
inputs=gr.inputs.Image(type="pil"),
|
17 |
+
outputs="text",
|
18 |
+
title="Cat vs Dog Classifier",
|
19 |
+
description="Upload an image of a cat or dog and let the model classify it!"
|
20 |
+
)
|
21 |
+
|
22 |
+
# Launch the Gradio app
|
23 |
+
interface.launch()
|