Sofia Casadei commited on
Commit
7338a56
Β·
1 Parent(s): c24c148

fix: use hf-cloudflare turn server

Browse files
Files changed (1) hide show
  1. main.py +5 -14
main.py CHANGED
@@ -104,11 +104,11 @@ async def transcribe(audio: tuple[int, np.ndarray]):
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(
114
  handler=ReplyOnPause(
@@ -147,8 +147,7 @@ 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
 
@@ -163,16 +162,8 @@ async def index():
163
  elif UI_TYPE == "screen":
164
  html_content = open("static/index-screen.html").read()
165
 
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
 
177
  @app.get("/transcript")
178
  def _(webrtc_id: str):
 
104
  )
105
  yield AdditionalOutputs(outputs["text"].strip())
106
 
 
 
107
  async def get_credentials():
108
  return await get_cloudflare_turn_credentials_async(hf_token=os.getenv("HF_TOKEN"))
109
 
110
+ server_credentials = get_cloudflare_turn_credentials(ttl=360_000) if APP_MODE == "deployed" else None
111
+
112
  logger.info("Initializing FastRTC stream")
113
  stream = Stream(
114
  handler=ReplyOnPause(
 
147
  ],
148
  additional_outputs_handler=lambda current, new: current + " " + new,
149
  rtc_configuration=get_credentials,
150
+ server_rtc_configuration=server_credentials,
 
151
  concurrency_limit=6
152
  )
153
 
 
162
  elif UI_TYPE == "screen":
163
  html_content = open("static/index-screen.html").read()
164
 
165
+ # Use the same server credentials for the client
166
+ return HTMLResponse(content=html_content.replace("__RTC_CONFIGURATION__", json.dumps(server_credentials)))
 
 
 
 
 
 
 
 
167
 
168
  @app.get("/transcript")
169
  def _(webrtc_id: str):