owinymarvin commited on
Commit
320fc26
·
1 Parent(s): d276007

latest changes

Browse files
Files changed (1) hide show
  1. app.py +23 -36
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 Blocks Interface Setup ---
141
- with gr.Blocks(
142
- title="Real-time Violence Detection", # Title for the browser tab
143
- # REMOVED: theme=gr.themes.Default(primary_hue=gr.Color(...)) to fix the AttributeError
144
- ) as demo:
145
- gr.Markdown(
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 gr.Row():
156
- video_input = gr.Video(
157
- sources=["webcam"],
158
- streaming=True,
159
- label="Live Webcam Feed",
160
- height=480,
161
- width=640
162
- )
163
-
164
- video_output = gr.Image(
165
- type="numpy",
166
- label="Processed Feed with Predictions",
167
- height=480,
168
- width=640
169
- )
170
-
171
- video_input.stream(
172
- predict_live_frames,
173
- inputs=video_input,
174
- outputs=video_output
175
- )
176
 
177
- demo.launch()
 
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()