Spaces:
Sleeping
Sleeping
Update pages/1_Live_Detection.py
Browse files- pages/1_Live_Detection.py +21 -11
pages/1_Live_Detection.py
CHANGED
@@ -37,7 +37,9 @@ def load_app_config():
|
|
37 |
secrets = {
|
38 |
"gemini_api_key": os.getenv("GEMINI_API_KEY"),
|
39 |
"turn_username": os.getenv("TURN_USERNAME"),
|
40 |
-
"turn_credential": os.getenv("TURN_CREDENTIAL")
|
|
|
|
|
41 |
}
|
42 |
return config, secrets
|
43 |
|
@@ -91,16 +93,24 @@ st.title("📹 Live Drowsiness Detection")
|
|
91 |
st.info("Press 'START' to activate your camera and begin monitoring.")
|
92 |
|
93 |
# --- Dynamically Build RTC Configuration ---
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
col1, col2 = st.columns([3, 1])
|
106 |
|
|
|
37 |
secrets = {
|
38 |
"gemini_api_key": os.getenv("GEMINI_API_KEY"),
|
39 |
"turn_username": os.getenv("TURN_USERNAME"),
|
40 |
+
"turn_credential": os.getenv("TURN_CREDENTIAL"),
|
41 |
+
"metered_domain": os.getenv("METERED_DOMAIN"),
|
42 |
+
"metered_api_key": os.getenv("METERED_KEY")
|
43 |
}
|
44 |
return config, secrets
|
45 |
|
|
|
93 |
st.info("Press 'START' to activate your camera and begin monitoring.")
|
94 |
|
95 |
# --- Dynamically Build RTC Configuration ---
|
96 |
+
@st.cache_data(ttl=3600) # Cache the credentials for 1 hour
|
97 |
+
def get_ice_servers():
|
98 |
+
"""Build the list of ICE servers, including STUN and TURN from Metered."""
|
99 |
+
if not secrets["metered_domain"] or not secrets["metered_api_key"]:
|
100 |
+
print("No Metered credentials found. Using public STUN servers only.")
|
101 |
+
return [{"urls": ["stun:stun.l.google.com:19302"]}]
|
102 |
+
|
103 |
+
try:
|
104 |
+
url = f"https://{secrets['metered_domain']}/api/v1/turn/credentials?apiKey={secrets['metered_api_key']}"
|
105 |
+
response = requests.get(url)
|
106 |
+
response.raise_for_status()
|
107 |
+
print("Successfully fetched ICE servers from Metered.ca")
|
108 |
+
return response.json()
|
109 |
+
except requests.exceptions.RequestException as e:
|
110 |
+
print(f"Warning: Could not fetch TURN credentials from Metered.ca: {e}")
|
111 |
+
return [{"urls": ["stun:stun.l.google.com:19302"]}]
|
112 |
+
|
113 |
+
RTC_CONFIGURATION = RTCConfiguration({"iceServers": get_ice_servers()})
|
114 |
|
115 |
col1, col2 = st.columns([3, 1])
|
116 |
|