Spaces:
Sleeping
Sleeping
Commit
·
320fc26
1
Parent(s):
d276007
latest changes
Browse files
app.py
CHANGED
@@ -84,6 +84,7 @@ current_prediction_label = "Initializing..."
|
|
84 |
current_probabilities = {label: 0.0 for label in CLASS_LABELS}
|
85 |
|
86 |
# --- 4. Gradio Live Inference Function (Generator) ---
|
|
|
87 |
def predict_live_frames(input_frame):
|
88 |
global frame_buffer, current_prediction_label, current_probabilities
|
89 |
|
@@ -137,41 +138,27 @@ def predict_live_frames(input_frame):
|
|
137 |
|
138 |
yield cv2.cvtColor(display_frame, cv2.COLOR_BGR2RGB)
|
139 |
|
140 |
-
# --- 5. Gradio
|
141 |
-
|
142 |
-
|
143 |
-
#
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
# 🎬 Real-time Violence Detection
|
148 |
-
**Live Feed with Constant Predictions**
|
149 |
-
|
150 |
-
This model analyzes your live webcam feed for violence, displaying the predicted class and probabilities on the screen.
|
151 |
-
Please grant webcam access when prompted by your browser.
|
152 |
-
"""
|
153 |
-
)
|
154 |
|
155 |
-
with
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
)
|
170 |
-
|
171 |
-
video_input.stream(
|
172 |
-
predict_live_frames,
|
173 |
-
inputs=video_input,
|
174 |
-
outputs=video_output
|
175 |
-
)
|
176 |
|
177 |
-
|
|
|
84 |
current_probabilities = {label: 0.0 for label in CLASS_LABELS}
|
85 |
|
86 |
# --- 4. Gradio Live Inference Function (Generator) ---
|
87 |
+
# This function will receive individual frames from the webcam as a NumPy array (H, W, C, RGB)
|
88 |
def predict_live_frames(input_frame):
|
89 |
global frame_buffer, current_prediction_label, current_probabilities
|
90 |
|
|
|
138 |
|
139 |
yield cv2.cvtColor(display_frame, cv2.COLOR_BGR2RGB)
|
140 |
|
141 |
+
# --- 5. Gradio Interface Setup (with hidden buttons) ---
|
142 |
+
iface = gr.Interface(
|
143 |
+
fn=predict_live_frames,
|
144 |
+
# Input: Live webcam feed, configure for streaming
|
145 |
+
inputs=gr.Video(sources=["webcam"], streaming=True, label="Live Webcam Feed"),
|
146 |
+
# Output: Image component to display processed frames
|
147 |
+
outputs=gr.Image(type="numpy", label="Processed Feed with Predictions"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
+
title="Real-time Violence Detection with SmallVideoClassifier (Webcam)",
|
150 |
+
description=(
|
151 |
+
"This model analyzes your live webcam feed for violence, displaying the predicted class and probabilities on the screen. "
|
152 |
+
"Please grant webcam access when prompted by your browser."
|
153 |
+
),
|
154 |
+
|
155 |
+
# --- IMPORTANT: Hide the default submit/clear buttons ---
|
156 |
+
submit_btn=None,
|
157 |
+
clear_btn=None,
|
158 |
+
|
159 |
+
allow_flagging="never",
|
160 |
+
# No examples needed for live webcam
|
161 |
+
examples=None
|
162 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
+
iface.launch()
|