Rcarvalo commited on
Commit
7f443a6
Β·
verified Β·
1 Parent(s): 94db0f7

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -5,6 +5,7 @@ Based on the original liquid-audio demo
5
 
6
  from queue import Queue
7
  from threading import Thread
 
8
 
9
  import gradio as gr
10
  import numpy as np
@@ -13,6 +14,25 @@ from fastrtc import AdditionalOutputs, ReplyOnPause, WebRTC
13
 
14
  from liquid_audio import ChatState, LFM2AudioModel, LFM2AudioProcessor, LFMModality
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  # Load models
17
  HF_REPO = "LiquidAI/LFM2-Audio-1.5B"
18
 
@@ -163,6 +183,7 @@ with gr.Blocks(title="LFM2-Audio Real-time Speech-to-Speech") as demo:
163
  modality="audio",
164
  mode="send-receive",
165
  full_screen=False,
 
166
  )
167
 
168
  with gr.Row():
 
5
 
6
  from queue import Queue
7
  from threading import Thread
8
+ import os
9
 
10
  import gradio as gr
11
  import numpy as np
 
14
 
15
  from liquid_audio import ChatState, LFM2AudioModel, LFM2AudioProcessor, LFMModality
16
 
17
+ # Configure WebRTC with STUN/TURN servers
18
+ # This is CRITICAL for WebRTC connections to work through firewalls/NAT
19
+ rtc_configuration = {
20
+ "iceServers": [
21
+ {
22
+ "urls": [
23
+ "stun:stun.l.google.com:19302",
24
+ "stun:stun1.l.google.com:19302",
25
+ ]
26
+ }
27
+ ]
28
+ }
29
+
30
+ # For production deployment on Hugging Face Spaces, you can use Cloudflare TURN:
31
+ # Uncomment these lines and set TURN_KEY_ID and TURN_KEY_API_TOKEN as Secrets
32
+ # from fastrtc import get_cloudflare_turn_credentials_async
33
+ # if os.getenv("TURN_KEY_ID") and os.getenv("TURN_KEY_API_TOKEN"):
34
+ # rtc_configuration = get_cloudflare_turn_credentials_async()
35
+
36
  # Load models
37
  HF_REPO = "LiquidAI/LFM2-Audio-1.5B"
38
 
 
183
  modality="audio",
184
  mode="send-receive",
185
  full_screen=False,
186
+ rtc_configuration=rtc_configuration,
187
  )
188
 
189
  with gr.Row():