Spaces:
Sleeping
Sleeping
Testimony Adekoya
commited on
Commit
·
5030574
1
Parent(s):
8eabd81
Abeg work
Browse files
pages/1_Live_Detection.py
CHANGED
@@ -19,7 +19,7 @@ if "audio_queue" not in st.session_state:
|
|
19 |
if "last_status" not in st.session_state:
|
20 |
st.session_state.last_status = {"status": "Awake"}
|
21 |
|
22 |
-
|
23 |
# --- Load Configuration and Environment Variables ---
|
24 |
@st.cache_resource
|
25 |
def load_app_config():
|
@@ -51,11 +51,12 @@ 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["gemini_api_key"])
|
|
|
|
|
|
|
59 |
|
60 |
def recv(self, frame: av.VideoFrame) -> av.VideoFrame:
|
61 |
img = frame.to_ndarray(format="bgr24")
|
@@ -90,8 +91,7 @@ class VideoProcessor(VideoProcessorBase):
|
|
90 |
self._alerter.reset_alert()
|
91 |
|
92 |
return av.VideoFrame.from_ndarray(processed_frame, format="bgr24")
|
93 |
-
|
94 |
-
|
95 |
# --- Page UI ---
|
96 |
st.title("📹 Live Drowsiness Detection")
|
97 |
st.info("Press 'START' to activate your camera and begin monitoring.")
|
@@ -136,6 +136,7 @@ if webrtc_ctx.state.playing:
|
|
136 |
st.session_state.last_status = {"status": "Awake"}
|
137 |
|
138 |
try:
|
|
|
139 |
status_result = st.session_state.status_queue.get(timeout=0.1)
|
140 |
st.session_state.last_status = status_result
|
141 |
except queue.Empty:
|
|
|
19 |
if "last_status" not in st.session_state:
|
20 |
st.session_state.last_status = {"status": "Awake"}
|
21 |
|
22 |
+
|
23 |
# --- Load Configuration and Environment Variables ---
|
24 |
@st.cache_resource
|
25 |
def load_app_config():
|
|
|
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 |
+
# Thread-safe queues for communication
|
58 |
+
self.status_queue = queue.Queue()
|
59 |
+
self.audio_queue = queue.Queue()
|
60 |
|
61 |
def recv(self, frame: av.VideoFrame) -> av.VideoFrame:
|
62 |
img = frame.to_ndarray(format="bgr24")
|
|
|
91 |
self._alerter.reset_alert()
|
92 |
|
93 |
return av.VideoFrame.from_ndarray(processed_frame, format="bgr24")
|
94 |
+
|
|
|
95 |
# --- Page UI ---
|
96 |
st.title("📹 Live Drowsiness Detection")
|
97 |
st.info("Press 'START' to activate your camera and begin monitoring.")
|
|
|
136 |
st.session_state.last_status = {"status": "Awake"}
|
137 |
|
138 |
try:
|
139 |
+
# This line will now work because st.session_state.status_queue was initialized
|
140 |
status_result = st.session_state.status_queue.get(timeout=0.1)
|
141 |
st.session_state.last_status = status_result
|
142 |
except queue.Empty:
|