Sofia Casadei commited on
Commit
fe3ff14
·
1 Parent(s): e0c1694

use cloudflare turn server

Browse files
Files changed (1) hide show
  1. main.py +8 -3
main.py CHANGED
@@ -15,6 +15,8 @@ from fastrtc import (
15
  AlgoOptions,
16
  SileroVadOptions,
17
  audio_to_bytes,
 
 
18
  )
19
  from transformers import (
20
  AutoModelForSpeechSeq2Seq,
@@ -99,6 +101,8 @@ async def transcribe(audio: tuple[int, np.ndarray]):
99
  )
100
  yield AdditionalOutputs(outputs["text"].strip())
101
 
 
 
102
 
103
  logger.info("Initializing FastRTC stream")
104
  stream = Stream(
@@ -136,7 +140,8 @@ stream = Stream(
136
  gr.Textbox(label="Transcript"),
137
  ],
138
  additional_outputs_handler=lambda current, new: current + " " + new,
139
- rtc_configuration=get_rtc_credentials(provider="hf") if APP_MODE == "deployed" else None,
 
140
  concurrency_limit=6
141
  )
142
 
@@ -148,10 +153,10 @@ stream.mount(app)
148
  async def index():
149
  if UI_TYPE == "base":
150
  html_content = open("static/index.html").read()
151
- else:
152
  html_content = open("static/index-screen.html").read()
153
 
154
- rtc_config = get_rtc_credentials(provider="hf") if APP_MODE == "deployed" else None
155
  return HTMLResponse(content=html_content.replace("__RTC_CONFIGURATION__", json.dumps(rtc_config)))
156
 
157
  @app.get("/transcript")
 
15
  AlgoOptions,
16
  SileroVadOptions,
17
  audio_to_bytes,
18
+ get_cloudflare_turn_credentials_async,
19
+ get_cloudflare_turn_credentials,
20
  )
21
  from transformers import (
22
  AutoModelForSpeechSeq2Seq,
 
101
  )
102
  yield AdditionalOutputs(outputs["text"].strip())
103
 
104
+ async def get_credentials():
105
+ return await get_cloudflare_turn_credentials_async(hf_token=os.getenv("HF_TOKEN"))
106
 
107
  logger.info("Initializing FastRTC stream")
108
  stream = Stream(
 
140
  gr.Textbox(label="Transcript"),
141
  ],
142
  additional_outputs_handler=lambda current, new: current + " " + new,
143
+ rtc_configuration=get_credentials if APP_MODE == "deployed" else None,
144
+ server_rtc_configuration=get_cloudflare_turn_credentials(ttl=360_000) if APP_MODE == "deployed" else None,
145
  concurrency_limit=6
146
  )
147
 
 
153
  async def index():
154
  if UI_TYPE == "base":
155
  html_content = open("static/index.html").read()
156
+ elif UI_TYPE == "screen":
157
  html_content = open("static/index-screen.html").read()
158
 
159
+ rtc_config = get_credentials if APP_MODE == "deployed" else None
160
  return HTMLResponse(content=html_content.replace("__RTC_CONFIGURATION__", json.dumps(rtc_config)))
161
 
162
  @app.get("/transcript")