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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -41
app.py CHANGED
@@ -168,49 +168,27 @@ rtc_configuration = {
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()
 
168
  "iceCandidatePoolSize": 10
169
  }
170
 
171
+ # Create the Stream component outside of any Blocks context
172
+ chatbot = gr.Chatbot(type="messages", visible=False) # Will be used for state only
173
+
174
+ stream = Stream(
175
+ modality="audio",
176
+ mode="send-receive",
177
+ handler=ReplyOnPause(response, input_sample_rate=16000),
178
+ additional_outputs_handler=lambda a, b: b,
179
+ additional_inputs=[chatbot],
180
+ additional_outputs=[chatbot],
181
+ rtc_configuration=rtc_configuration,
182
+ concurrency_limit=5 if get_space() else None,
183
+ time_limit=90 if get_space() else None,
184
+ ui_args={"title": "LLM Voice Chat (Powered by DeepSeek & ElevenLabs)"}
185
+ )
186
+
187
+ # Create a basic Gradio interface
188
+ demo = stream.ui
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
 
190
  # Launch the app
191
+ if __name__ == "__main__":
192
  # Local development
193
  os.environ["GRADIO_SSR_MODE"] = "false"
194
  demo.launch(server_port=7860)