Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,7 @@ else:
|
|
26 |
# Optimize model for speed
|
27 |
model.conf = 0.3 # Lower confidence threshold
|
28 |
model.iou = 0.3 # Non-Maximum Suppression IoU threshold
|
29 |
-
model.classes = None # Detect all classes
|
30 |
|
31 |
if device.type == "cuda":
|
32 |
model.half() # Use FP16 for faster inference
|
@@ -37,7 +37,7 @@ model.eval()
|
|
37 |
|
38 |
# Pre-generate colors for bounding boxes
|
39 |
np.random.seed(42)
|
40 |
-
colors = np.random.
|
41 |
|
42 |
def process_video(video_path):
|
43 |
cap = cv2.VideoCapture(video_path)
|
@@ -121,8 +121,13 @@ with gr.Blocks(title="Real-Time YOLOv5 Video & Image Detection") as demo:
|
|
121 |
process_button.click(fn=process_video, inputs=video_input, outputs=video_output)
|
122 |
|
123 |
with gr.TabItem("Image Detection"):
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
demo.launch()
|
|
|
26 |
# Optimize model for speed
|
27 |
model.conf = 0.3 # Lower confidence threshold
|
28 |
model.iou = 0.3 # Non-Maximum Suppression IoU threshold
|
29 |
+
model.classes = None # Detect all 80+ COCO classes
|
30 |
|
31 |
if device.type == "cuda":
|
32 |
model.half() # Use FP16 for faster inference
|
|
|
37 |
|
38 |
# Pre-generate colors for bounding boxes
|
39 |
np.random.seed(42)
|
40 |
+
colors = np.random.randint(0, 255, size=(len(model.names), 3), dtype=np.uint8)
|
41 |
|
42 |
def process_video(video_path):
|
43 |
cap = cv2.VideoCapture(video_path)
|
|
|
121 |
process_button.click(fn=process_video, inputs=video_input, outputs=video_output)
|
122 |
|
123 |
with gr.TabItem("Image Detection"):
|
124 |
+
with gr.Row():
|
125 |
+
image_input = gr.Image(type="pil", label="Upload Image", width=256, height=256)
|
126 |
+
with gr.Row():
|
127 |
+
submit_button = gr.Button("Submit")
|
128 |
+
clear_button = gr.Button("Clear")
|
129 |
+
image_output = gr.Image(label="Detected Objects", width=256, height=256)
|
130 |
+
submit_button.click(fn=process_image, inputs=image_input, outputs=image_output)
|
131 |
+
clear_button.click(fn=lambda: None, inputs=None, outputs=image_output)
|
132 |
|
133 |
demo.launch()
|