whitphx HF staff commited on
Commit
5bebc6e
·
1 Parent(s): 5a48885

Fix the object detection demo to use Twilio TURN server

Browse files
Files changed (2) hide show
  1. requirements.txt +1 -0
  2. sample_utils/turn.py +11 -12
requirements.txt CHANGED
@@ -2,3 +2,4 @@ opencv-python-headless==4.7.0.72
2
  pydub==0.25.1
3
  streamlit==1.19.0
4
  streamlit_webrtc==0.44.7
 
 
2
  pydub==0.25.1
3
  streamlit==1.19.0
4
  streamlit_webrtc==0.44.7
5
+ twilio~=8.1.0
sample_utils/turn.py CHANGED
@@ -1,26 +1,25 @@
1
  import logging
2
  import os
3
 
4
- import requests
5
  import streamlit as st
6
 
7
  logger = logging.getLogger(__name__)
8
 
9
 
10
- OPEN_RELAY_API_HOST = os.environ.get("OPEN_RELAY_API_HOST")
11
- OPEN_RELAY_API_KEY = os.environ.get("OPEN_RELAY_API_KEY")
12
-
13
-
14
  @st.cache_data
15
  def get_ice_servers():
16
- if not OPEN_RELAY_API_HOST or not OPEN_RELAY_API_KEY:
 
 
 
17
  logger.warning(
18
- "Open Relay API host or key is not set. Fallback to a free STUN server from Google." # noqa: E501
19
  )
20
  return [{"urls": ["stun:stun.l.google.com:19302"]}]
21
 
22
- # Get response from Open Relay API
23
- response = requests.get(
24
- f"https://{OPEN_RELAY_API_HOST}/api/v1/turn/credentials?apiKey={OPEN_RELAY_API_KEY}" # noqa: E501
25
- )
26
- return response.json()
 
1
  import logging
2
  import os
3
 
4
+ from twilio.rest import Client
5
  import streamlit as st
6
 
7
  logger = logging.getLogger(__name__)
8
 
9
 
 
 
 
 
10
  @st.cache_data
11
  def get_ice_servers():
12
+ try:
13
+ account_sid = os.environ['TWILIO_ACCOUNT_SID']
14
+ auth_token = os.environ['TWILIO_AUTH_TOKEN']
15
+ except KeyError:
16
  logger.warning(
17
+ "Twilio credentials are not set. Fallback to a free STUN server from Google." # noqa: E501
18
  )
19
  return [{"urls": ["stun:stun.l.google.com:19302"]}]
20
 
21
+ client = Client(account_sid, auth_token)
22
+
23
+ token = client.tokens.create()
24
+
25
+ return token.ice_servers