Spaces:
Runtime error
Runtime error
fouadmahmoud283-ai commited on
Commit ·
bbb296c
1
Parent(s): d00b834
fixing camera n1235
Browse files- src/streamlit_app.py +25 -5
src/streamlit_app.py
CHANGED
|
@@ -323,6 +323,25 @@ def create_confidence_chart(detections):
|
|
| 323 |
|
| 324 |
return fig
|
| 325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
class RealtimeVideoProcessor(VideoProcessorBase):
|
| 327 |
def __init__(self, model, conf_threshold):
|
| 328 |
self.model = model
|
|
@@ -533,16 +552,17 @@ def main():
|
|
| 533 |
|
| 534 |
model = st.session_state.model
|
| 535 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
webrtc_ctx = webrtc_streamer(
|
| 537 |
key="realtime_camera",
|
| 538 |
video_processor_factory=lambda: RealtimeVideoProcessor(model, conf_threshold),
|
| 539 |
media_stream_constraints={"video": True, "audio": False},
|
| 540 |
async_processing=True,
|
| 541 |
-
rtc_configuration=
|
| 542 |
-
"iceServers": [
|
| 543 |
-
{"urls": ["stun:stun.l.google.com:19302", "stun:stun1.l.google.com:19302"]}
|
| 544 |
-
]
|
| 545 |
-
}
|
| 546 |
)
|
| 547 |
|
| 548 |
realtime_detections = None
|
|
|
|
| 323 |
|
| 324 |
return fig
|
| 325 |
|
| 326 |
+
def get_rtc_configuration():
|
| 327 |
+
"""Build RTC config from env vars (TURN optional)."""
|
| 328 |
+
turn_url = os.getenv("TURN_URL")
|
| 329 |
+
turn_username = os.getenv("TURN_USERNAME")
|
| 330 |
+
turn_password = os.getenv("TURN_PASSWORD")
|
| 331 |
+
|
| 332 |
+
ice_servers = [
|
| 333 |
+
{"urls": ["stun:stun.l.google.com:19302", "stun:stun1.l.google.com:19302"]}
|
| 334 |
+
]
|
| 335 |
+
|
| 336 |
+
if turn_url and turn_username and turn_password:
|
| 337 |
+
ice_servers.append({
|
| 338 |
+
"urls": [turn_url],
|
| 339 |
+
"username": turn_username,
|
| 340 |
+
"credential": turn_password
|
| 341 |
+
})
|
| 342 |
+
|
| 343 |
+
return {"iceServers": ice_servers}
|
| 344 |
+
|
| 345 |
class RealtimeVideoProcessor(VideoProcessorBase):
|
| 346 |
def __init__(self, model, conf_threshold):
|
| 347 |
self.model = model
|
|
|
|
| 552 |
|
| 553 |
model = st.session_state.model
|
| 554 |
|
| 555 |
+
rtc_config = get_rtc_configuration()
|
| 556 |
+
|
| 557 |
+
if not os.getenv("TURN_URL"):
|
| 558 |
+
st.info("Live camera may fail on some networks without TURN. Set TURN_URL, TURN_USERNAME, TURN_PASSWORD to improve connectivity.")
|
| 559 |
+
|
| 560 |
webrtc_ctx = webrtc_streamer(
|
| 561 |
key="realtime_camera",
|
| 562 |
video_processor_factory=lambda: RealtimeVideoProcessor(model, conf_threshold),
|
| 563 |
media_stream_constraints={"video": True, "audio": False},
|
| 564 |
async_processing=True,
|
| 565 |
+
rtc_configuration=rtc_config
|
|
|
|
|
|
|
|
|
|
|
|
|
| 566 |
)
|
| 567 |
|
| 568 |
realtime_detections = None
|