Spaces:
Sleeping
Sleeping
Testimony Adekoya
commited on
Commit
·
901aa8c
1
Parent(s):
b828bd1
Status queue change or so
Browse files- pages/1_Live_Detection.py +10 -15
pages/1_Live_Detection.py
CHANGED
@@ -51,11 +51,9 @@ def autoplay_audio(audio_bytes: bytes):
|
|
51 |
|
52 |
# --- WebRTC Video Processor ---
|
53 |
class VideoProcessor(VideoProcessorBase):
|
54 |
-
def __init__(self
|
55 |
-
self.status_queue = status_queue
|
56 |
-
self.audio_queue = audio_queue
|
57 |
self._detector = get_detector(config)
|
58 |
-
self._alerter = get_alerter(config, secrets
|
59 |
|
60 |
def recv(self, frame: av.VideoFrame) -> av.VideoFrame:
|
61 |
img = frame.to_ndarray(format="bgr24")
|
@@ -63,21 +61,21 @@ class VideoProcessor(VideoProcessorBase):
|
|
63 |
strategy = config.get('detection_strategy')
|
64 |
if strategy == 'hybrid':
|
65 |
processed_frame, alert_triggered, active_alerts = self._detector.process_frame(img)
|
66 |
-
|
67 |
-
else:
|
68 |
processed_frame, indicators = self._detector.process_frame(img)
|
69 |
-
alert_triggered = any(
|
70 |
-
|
71 |
|
72 |
if alert_triggered:
|
73 |
audio_data = self._alerter.trigger_alert()
|
74 |
if audio_data:
|
75 |
-
|
76 |
else:
|
77 |
self._alerter.reset_alert()
|
78 |
|
79 |
return av.VideoFrame.from_ndarray(processed_frame, format="bgr24")
|
80 |
-
|
81 |
# --- Page UI ---
|
82 |
# The st.set_page_config() call has been removed from this file.
|
83 |
# The configuration from main.py will apply to this page.
|
@@ -110,11 +108,8 @@ col1, col2 = st.columns([3, 1])
|
|
110 |
with col1:
|
111 |
webrtc_ctx = webrtc_streamer(
|
112 |
key="drowsiness-detection",
|
113 |
-
video_processor_factory=
|
114 |
-
|
115 |
-
audio_queue=st.session_state.audio_queue
|
116 |
-
),
|
117 |
-
rtc_configuration=RTC_CONFIGURATION,
|
118 |
media_stream_constraints={"video": True, "audio": False},
|
119 |
async_processing=True,
|
120 |
)
|
|
|
51 |
|
52 |
# --- WebRTC Video Processor ---
|
53 |
class VideoProcessor(VideoProcessorBase):
|
54 |
+
def __init__(self):
|
|
|
|
|
55 |
self._detector = get_detector(config)
|
56 |
+
self._alerter = get_alerter(config, secrets.gemini_api_key)
|
57 |
|
58 |
def recv(self, frame: av.VideoFrame) -> av.VideoFrame:
|
59 |
img = frame.to_ndarray(format="bgr24")
|
|
|
61 |
strategy = config.get('detection_strategy')
|
62 |
if strategy == 'hybrid':
|
63 |
processed_frame, alert_triggered, active_alerts = self._detector.process_frame(img)
|
64 |
+
st.session_state.active_alerts = active_alerts if alert_triggered else {"status": "Awake"}
|
65 |
+
else: # Fallback for simpler strategies
|
66 |
processed_frame, indicators = self._detector.process_frame(img)
|
67 |
+
alert_triggered = any(indicators.values())
|
68 |
+
st.session_state.active_alerts = indicators if alert_triggered else {"status": "Awake"}
|
69 |
|
70 |
if alert_triggered:
|
71 |
audio_data = self._alerter.trigger_alert()
|
72 |
if audio_data:
|
73 |
+
st.session_state.play_audio = audio_data
|
74 |
else:
|
75 |
self._alerter.reset_alert()
|
76 |
|
77 |
return av.VideoFrame.from_ndarray(processed_frame, format="bgr24")
|
78 |
+
|
79 |
# --- Page UI ---
|
80 |
# The st.set_page_config() call has been removed from this file.
|
81 |
# The configuration from main.py will apply to this page.
|
|
|
108 |
with col1:
|
109 |
webrtc_ctx = webrtc_streamer(
|
110 |
key="drowsiness-detection",
|
111 |
+
video_processor_factory=VideoProcessor,
|
112 |
+
rtc_configuration=RTC_CONFIGURATION, # Use the new robust configuration
|
|
|
|
|
|
|
113 |
media_stream_constraints={"video": True, "audio": False},
|
114 |
async_processing=True,
|
115 |
)
|