File size: 1,028 Bytes
04a2bd6
3ee5b52
 
 
 
 
04a2bd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ee5b52
04a2bd6
 
 
 
3ee5b52
61bab8b
 
04a2bd6
3ee5b52
04a2bd6
 
3ee5b52
04a2bd6
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import gradio as gr
from ultralytics import YOLO
import cv2

# Load YOLOv8 model
model = YOLO("yolov8n.pt")

def detect_objects(video):
    cap = cv2.VideoCapture(video)
    frames = []
    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break
        results = model(frame)
        annotated_frame = results[0].plot()
        _, buffer = cv2.imencode('.jpg', annotated_frame)
        frames.append(buffer.tobytes())
    cap.release()
    return frames

# Create Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# Real-Time Object Detection for Blind Assistance")
    gr.Markdown("This app detects objects in real-time using your webcam.")

    # Remove the `source` argument
    video_input = gr.Video(label="Webcam Stream", type="filepath")
    output_gallery = gr.Video(label="Detection Output")

    detect_button = gr.Button("Start Detection")
    detect_button.click(detect_objects, inputs=[video_input], outputs=[output_gallery])

# Launch the app
demo.launch()