Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +23 -0
- requirements.txt +4 -0
- yolov8n.pt +3 -0
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
|
| 4 |
+
# Load the YOLOv8 model
|
| 5 |
+
model = YOLO('yolov8n.pt') # Ensure this file is in the same directory
|
| 6 |
+
|
| 7 |
+
def detect_objects(image):
|
| 8 |
+
results = model(image) # Run inference
|
| 9 |
+
boxes = results[0].boxes # Get bounding boxes
|
| 10 |
+
detected_classes = [model.names[int(box.cls)] for box in boxes] # Get class names
|
| 11 |
+
return detected_classes
|
| 12 |
+
|
| 13 |
+
# Create a Gradio interface
|
| 14 |
+
interface = gr.Interface(
|
| 15 |
+
fn=detect_objects,
|
| 16 |
+
inputs=gr.Image(type="pil"),
|
| 17 |
+
outputs="label",
|
| 18 |
+
title="Object Detection Bot",
|
| 19 |
+
description="Upload an image to detect objects."
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Launch the interface
|
| 23 |
+
interface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
torchvision
|
| 3 |
+
gradio
|
| 4 |
+
ultralytics
|
yolov8n.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
| 3 |
+
size 0
|