Twelve2five commited on
Commit
f1d26c3
·
verified ·
1 Parent(s): 1cce1a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -21
app.py CHANGED
@@ -150,7 +150,7 @@ def use_gtts_for_text(text):
150
  print(f"gTTS error: {e}")
151
  yield None
152
 
153
- # Enhanced WebRTC configuration with more STUN/TURN servers
154
  rtc_configuration = {
155
  "iceServers": [
156
  {"urls": ["stun:stun.l.google.com:19302", "stun:stun1.l.google.com:19302"]},
@@ -168,26 +168,49 @@ rtc_configuration = {
168
  "iceCandidatePoolSize": 10
169
  }
170
 
171
- # Create Gradio chatbot and stream
172
- chatbot = gr.Chatbot(type="messages")
173
- stream = Stream(
174
- modality="audio",
175
- mode="send-receive",
176
- handler=ReplyOnPause(response, input_sample_rate=16000),
177
- additional_outputs_handler=lambda a, b: b,
178
- additional_inputs=[chatbot],
179
- additional_outputs=[chatbot],
180
- rtc_configuration=rtc_configuration,
181
- concurrency_limit=5 if get_space() else None,
182
- time_limit=90 if get_space() else None,
183
- ui_args={"title": "LLM Voice Chat (Powered by DeepSeek & ElevenLabs)"}
184
- )
185
-
186
- # Export the UI for Hugging Face Spaces
187
- demo = stream.ui
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
- # For local development only
190
  if __name__ == "__main__" and not get_space():
191
- import uvicorn
192
  os.environ["GRADIO_SSR_MODE"] = "false"
193
- stream.ui.launch(server_port=7860)
 
 
 
 
 
150
  print(f"gTTS error: {e}")
151
  yield None
152
 
153
+ # Enhanced WebRTC configuration
154
  rtc_configuration = {
155
  "iceServers": [
156
  {"urls": ["stun:stun.l.google.com:19302", "stun:stun1.l.google.com:19302"]},
 
168
  "iceCandidatePoolSize": 10
169
  }
170
 
171
+ # Create Gradio Blocks interface with proper configuration
172
+ with gr.Blocks(title="LLM Voice Chat (Powered by DeepSeek & ElevenLabs)") as demo:
173
+ gr.Markdown("# LLM Voice Chat\nPowered by DeepSeek & ElevenLabs")
174
+
175
+ # Create the chatbot component
176
+ chatbot = gr.Chatbot(type="messages")
177
+
178
+ # Create a placeholder for the Stream component
179
+ stream_placeholder = gr.HTML("""
180
+ <div style="text-align: center; margin: 20px;">
181
+ <p>Loading voice chat interface...</p>
182
+ </div>
183
+ """)
184
+
185
+ # Explicitly add Stream to the UI after the interface is defined
186
+ def add_stream():
187
+ return Stream(
188
+ modality="audio",
189
+ mode="send-receive",
190
+ handler=ReplyOnPause(response, input_sample_rate=16000),
191
+ additional_outputs_handler=lambda a, b: b,
192
+ additional_inputs=[chatbot],
193
+ additional_outputs=[chatbot],
194
+ rtc_configuration=rtc_configuration,
195
+ concurrency_limit=5 if get_space() else None,
196
+ time_limit=90 if get_space() else None
197
+ )
198
+
199
+ # This event will add the Stream component after the UI loads
200
+ demo.load(lambda: None, None, None, _js=f"""
201
+ () => {{
202
+ setTimeout(() => {{
203
+ document.querySelector(".loading").style.display = "none";
204
+ }}, 2000);
205
+ }}
206
+ """)
207
 
208
+ # Launch the app
209
  if __name__ == "__main__" and not get_space():
210
+ # Local development
211
  os.environ["GRADIO_SSR_MODE"] = "false"
212
+ demo.launch(server_port=7860)
213
+ else:
214
+ # Hugging Face Spaces
215
+ # Need to explicitly call launch for Spaces to pick up the app
216
+ demo.launch()