owinymarvin commited on
Commit
d276007
·
1 Parent(s): 429fbf1

latest changes

Browse files
Files changed (1) hide show
  1. app.py +8 -17
app.py CHANGED
@@ -88,7 +88,6 @@ def predict_live_frames(input_frame):
88
  global frame_buffer, current_prediction_label, current_probabilities
89
 
90
  if input_frame is None:
91
- # If no frame is received (e.g., webcam not active or disconnected)
92
  dummy_frame = np.zeros((200, 400, 3), dtype=np.uint8)
93
  cv2.putText(dummy_frame, "Waiting for webcam input...", (10, 100), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
94
  yield dummy_frame
@@ -141,9 +140,8 @@ def predict_live_frames(input_frame):
141
  # --- 5. Gradio Blocks Interface Setup ---
142
  with gr.Blocks(
143
  title="Real-time Violence Detection", # Title for the browser tab
144
- theme=gr.themes.Default(primary_hue=gr.Color(c50='#e0f7fa', c100='#b2ebf2', c200='#80deea', c300='#4dd0e1', c400='#26c6da', c500='#00bcd4', c600='#00acc1', c700='#0097a7', c800='#00838f', c900='#006064', ca50='#84ffff', ca100='#18ffff', ca200='#00e5ff', ca400='#00b8d4')) # Optional: A subtle theme change
145
  ) as demo:
146
- # Optional: Display a title and description clearly, even without buttons
147
  gr.Markdown(
148
  """
149
  # 🎬 Real-time Violence Detection
@@ -155,32 +153,25 @@ with gr.Blocks(
155
  )
156
 
157
  with gr.Row():
158
- # Input: Live webcam feed
159
- # We need to set a minimum height and width to ensure the video feed is displayed reasonably
160
  video_input = gr.Video(
161
  sources=["webcam"],
162
  streaming=True,
163
  label="Live Webcam Feed",
164
- # Optional: Set dimensions for the video display
165
- height=480, # or None for auto
166
- width=640 # or None for auto
167
  )
168
 
169
- # Output: Image component to display processed frames
170
  video_output = gr.Image(
171
  type="numpy",
172
  label="Processed Feed with Predictions",
173
- # Optional: Set dimensions to match input or your preference
174
- height=480, # or None for auto
175
- width=640 # or None for auto
176
  )
177
 
178
- # Connect the video stream directly to the prediction function
179
- # The 'stream' event on gr.Video is triggered as new frames arrive from the webcam.
180
  video_input.stream(
181
- predict_live_frames, # The function to call for each frame
182
- inputs=video_input, # Pass the video_input component itself as input
183
- outputs=video_output # Update the video_output component
184
  )
185
 
186
  demo.launch()
 
88
  global frame_buffer, current_prediction_label, current_probabilities
89
 
90
  if input_frame is None:
 
91
  dummy_frame = np.zeros((200, 400, 3), dtype=np.uint8)
92
  cv2.putText(dummy_frame, "Waiting for webcam input...", (10, 100), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
93
  yield dummy_frame
 
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
 
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()