Hamza011 commited on
Commit
7fdc1ab
·
verified ·
1 Parent(s): bd19875

Update app1.py

Browse files
Files changed (1) hide show
  1. app1.py +31 -24
app1.py CHANGED
@@ -2,8 +2,8 @@ import cv2
2
  import numpy as np
3
 
4
  # Load the SSD model and configuration
5
- model_path = 'ssd_mobilenet_v2_coco.pb' # Path to the pre-trained SSD model
6
- config_path = ' pipeline.config' # Path to the deploy prototxt file
7
 
8
  # Load the class labels from the COCO dataset
9
  CLASSES = [
@@ -56,28 +56,35 @@ def detect_objects_in_frame(frame):
56
 
57
  return frame
58
 
59
- # Capture video from a file or camera (0 for the default camera)
60
- cap = cv2.VideoCapture(0) # Use 0 for webcam or provide a path to a video file
61
 
62
- # Check if the video capture is initialized correctly
63
- if not cap.isOpened():
64
- print("Error: Could not open video stream.")
65
- exit()
66
 
67
- while True:
68
- # Read a new frame from the video feed
69
- ret, frame = cap.read()
70
-
71
- if not ret:
72
- print("Error: Failed to read frame from video stream.")
73
- break
74
-
75
- # Detect objects in the current frame
76
- output_frame = detect_objects_in_frame(frame)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
- # Display the resulting frame
79
- cv2.imshow("Detected Objects in Video", output_frame)
80
-
81
- # Break the loop if the user presses the 'Esc' key
82
- if cv2.waitKey(1) & 0xFF == 27: # 27 is the keycode for 'Esc'
83
- break
 
2
  import numpy as np
3
 
4
  # Load the SSD model and configuration
5
+ model_path = 'saved_model.pb' # Path to the pre-trained SSD model
6
+ config_path = 'pipeline.config' # Path to the deploy prototxt file
7
 
8
  # Load the class labels from the COCO dataset
9
  CLASSES = [
 
56
 
57
  return frame
58
 
59
+ import gradio as gr
60
+ from gradio_webrtc import WebRTC
61
 
62
+ css = """.my-group {max-width: 600px !important; max-height: 600px !important;}
63
+ .my-column {display: flex !important; justify-content: center !important; align-items: center !important;}"""
 
 
64
 
65
+ with gr.Blocks(css=css) as demo:
66
+ gr.HTML(
67
+ """
68
+ <h1 style='text-align: center'>
69
+ YOLOv10 Webcam Stream (Powered by WebRTC ⚡️)
70
+ </h1>
71
+ """
72
+ )
73
+ with gr.Column(elem_classes=["my-column"]):
74
+ with gr.Group(elem_classes=["my-group"]):
75
+ image = WebRTC(label="Stream", rtc_configuration=None)
76
+ conf_threshold = gr.Slider(
77
+ label="Confidence Threshold",
78
+ minimum=0.0,
79
+ maximum=1.0,
80
+ step=0.05,
81
+ value=0.30,
82
+ )
83
+
84
+ image.stream(
85
+ fn=detect_objects_in_frame, inputs=[image, conf_threshold], outputs=[image], time_limit=10
86
+ )
87
+
88
+ if __name__ == "__main__":
89
+ demo.launch()
90