Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
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
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
-
#
|
190 |
if __name__ == "__main__" and not get_space():
|
191 |
-
|
192 |
os.environ["GRADIO_SSR_MODE"] = "false"
|
193 |
-
|
|
|
|
|
|
|
|
|
|
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()
|