Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,30 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
-
return "Hello " + name + "!!"
|
6 |
|
7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
description = """
|
9 |
-
Welcome to the Gradio interface! This simple app detects
|
10 |
-
|
11 |
"""
|
12 |
|
13 |
-
#
|
14 |
demo = gr.Interface(
|
15 |
-
fn=
|
16 |
inputs=gr.Image(label="Upload an Image"),
|
17 |
-
outputs=gr.Textbox(label="
|
18 |
live=True,
|
19 |
-
title="
|
20 |
description=description
|
21 |
)
|
22 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
|
6 |
+
# Load your YOLO model (Make sure the model is in PyTorch format)
|
7 |
+
model = torch.hub.load('ultralytics/yolov5', 'yolov8', pretrained=True) # Replace with YOLOv8
|
|
|
8 |
|
9 |
+
# Define the prediction function for YOLO model
|
10 |
+
def predict(image):
|
11 |
+
image = Image.fromarray(np.array(image)) # Convert image to PIL format
|
12 |
+
results = model(image) # Get predictions from YOLO model
|
13 |
+
return f"Predicted class: {results.names[results.pred[0, -1].item()]}" # Extract class name
|
14 |
+
|
15 |
+
# Define the description and interface
|
16 |
description = """
|
17 |
+
Welcome to the Gradio interface! This simple app detects mouse feet observing from below.
|
18 |
+
Upload an image to see the prediction results!
|
19 |
"""
|
20 |
|
21 |
+
# Create the Gradio interface
|
22 |
demo = gr.Interface(
|
23 |
+
fn=predict,
|
24 |
inputs=gr.Image(label="Upload an Image"),
|
25 |
+
outputs=gr.Textbox(label="Prediction Result"),
|
26 |
live=True,
|
27 |
+
title="Mouse Feet Detection",
|
28 |
description=description
|
29 |
)
|
30 |
|