Sofia Casadei commited on
Commit
c24c148
·
1 Parent(s): 97f18ea

fix: use hf-cloudflare turn server

Browse files
Files changed (1) hide show
  1. main.py +13 -7
main.py CHANGED
@@ -17,6 +17,8 @@ from fastrtc import (
17
  AlgoOptions,
18
  SileroVadOptions,
19
  audio_to_bytes,
 
 
20
  )
21
  from transformers import (
22
  AutoModelForSpeechSeq2Seq,
@@ -102,8 +104,10 @@ async def transcribe(audio: tuple[int, np.ndarray]):
102
  )
103
  yield AdditionalOutputs(outputs["text"].strip())
104
 
105
- get_credentials = get_credential_function(TURN_SERVER_PROVIDER, is_async=True) if APP_MODE == "deployed" else None
106
- server_rtc_configuration = get_rtc_credentials(provider=TURN_SERVER_PROVIDER, ttl=360_000) if APP_MODE == "deployed" else None
 
 
107
 
108
  logger.info("Initializing FastRTC stream")
109
  stream = Stream(
@@ -143,7 +147,8 @@ stream = Stream(
143
  ],
144
  additional_outputs_handler=lambda current, new: current + " " + new,
145
  rtc_configuration=get_credentials,
146
- server_rtc_configuration=server_rtc_configuration,
 
147
  concurrency_limit=6
148
  )
149
 
@@ -161,10 +166,11 @@ async def index():
161
  # Return the actual credentials for client-side, not the function
162
  rtc_config = None
163
  if APP_MODE == "deployed":
164
- if asyncio.iscoroutinefunction(get_credentials):
165
- rtc_config = await get_credentials()
166
- else:
167
- rtc_config = get_rtc_credentials(provider=TURN_SERVER_PROVIDER)
 
168
 
169
  return HTMLResponse(content=html_content.replace("__RTC_CONFIGURATION__", json.dumps(rtc_config)))
170
 
 
17
  AlgoOptions,
18
  SileroVadOptions,
19
  audio_to_bytes,
20
+ get_cloudflare_turn_credentials,
21
+ get_cloudflare_turn_credentials_async,
22
  )
23
  from transformers import (
24
  AutoModelForSpeechSeq2Seq,
 
104
  )
105
  yield AdditionalOutputs(outputs["text"].strip())
106
 
107
+ #get_credentials = get_credential_function(TURN_SERVER_PROVIDER, is_async=True) if APP_MODE == "deployed" else None
108
+ #server_rtc_configuration = get_rtc_credentials(provider=TURN_SERVER_PROVIDER, ttl=360_000) if APP_MODE == "deployed" else None
109
+ async def get_credentials():
110
+ return await get_cloudflare_turn_credentials_async(hf_token=os.getenv("HF_TOKEN"))
111
 
112
  logger.info("Initializing FastRTC stream")
113
  stream = Stream(
 
147
  ],
148
  additional_outputs_handler=lambda current, new: current + " " + new,
149
  rtc_configuration=get_credentials,
150
+ #server_rtc_configuration=server_rtc_configuration,
151
+ server_rtc_configuration=get_cloudflare_turn_credentials(ttl=360_000),
152
  concurrency_limit=6
153
  )
154
 
 
166
  # Return the actual credentials for client-side, not the function
167
  rtc_config = None
168
  if APP_MODE == "deployed":
169
+ #if asyncio.iscoroutinefunction(get_credentials):
170
+ # rtc_config = await get_credentials()
171
+ #else:
172
+ # rtc_config = get_rtc_credentials(provider=TURN_SERVER_PROVIDER)
173
+ rtc_config = get_cloudflare_turn_credentials(ttl=360_000)
174
 
175
  return HTMLResponse(content=html_content.replace("__RTC_CONFIGURATION__", json.dumps(rtc_config)))
176