Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Load YOLOv11 model (make sure yolo11n.pt is in the same folder)
|
| 6 |
+
model = YOLO("yolo11n.pt")
|
| 7 |
+
|
| 8 |
+
# Define prediction function
|
| 9 |
+
def detect_objects(image):
|
| 10 |
+
results = model(image)
|
| 11 |
+
# results[0].plot() returns a numpy image with detections drawn
|
| 12 |
+
result_image = Image.fromarray(results[0].plot())
|
| 13 |
+
return result_image
|
| 14 |
+
|
| 15 |
+
# Create Gradio interface
|
| 16 |
+
app = gr.Interface(
|
| 17 |
+
fn=detect_objects,
|
| 18 |
+
inputs=gr.Image(type="pil", label="Upload an image"),
|
| 19 |
+
outputs=gr.Image(type="pil", label="Detections"),
|
| 20 |
+
title="YOLOv11 Object Detection",
|
| 21 |
+
description="Upload an image to detect objects using YOLOv11 Nano (yolo11n.pt)."
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Launch app
|
| 25 |
+
app.launch()
|