Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -203,17 +203,18 @@ def generate_audio_elevenlabs(text):
|
|
203 |
|
204 |
def handle_mode_selection(mode, chat_history, question):
|
205 |
if mode == "Normal Chatbot":
|
206 |
-
#
|
207 |
-
chat_history.append((question, ""))
|
208 |
return chat_with_streaming(chat_history, question)
|
209 |
elif mode == "Voice to Voice Conversation":
|
210 |
-
# Voice to Voice mode
|
211 |
response = get_response(question)
|
212 |
audio_path = generate_audio_elevenlabs(response)
|
213 |
-
chat_history.append((question, "[Voice Response]"))
|
214 |
return chat_history, "", audio_path
|
215 |
|
216 |
|
|
|
|
|
217 |
def chat_with_streaming(chat_history, question):
|
218 |
# Get the response for the question
|
219 |
response = get_response(question)
|
@@ -227,6 +228,7 @@ def chat_with_streaming(chat_history, question):
|
|
227 |
|
228 |
# Ensure the full response is shown at the end
|
229 |
yield chat_history, "", None
|
|
|
230 |
|
231 |
|
232 |
|
@@ -386,14 +388,16 @@ with gr.Blocks(theme="rawrsor1/Everforest") as demo:
|
|
386 |
fn=handle_mode_selection,
|
387 |
inputs=[mode_selection, chatbot, question_input],
|
388 |
outputs=[chatbot, question_input, audio_output],
|
389 |
-
api_name="api_handle_response"
|
|
|
390 |
)
|
391 |
|
392 |
question_input.submit(
|
393 |
fn=handle_mode_selection,
|
394 |
inputs=[mode_selection, chatbot, question_input],
|
395 |
outputs=[chatbot, question_input, audio_output],
|
396 |
-
api_name="api_handle_response_on_enter"
|
|
|
397 |
)
|
398 |
|
399 |
|
|
|
203 |
|
204 |
def handle_mode_selection(mode, chat_history, question):
|
205 |
if mode == "Normal Chatbot":
|
206 |
+
# For Normal Chatbot mode, return a generator for streaming
|
|
|
207 |
return chat_with_streaming(chat_history, question)
|
208 |
elif mode == "Voice to Voice Conversation":
|
209 |
+
# For Voice to Voice mode, generate audio and return audio output directly
|
210 |
response = get_response(question)
|
211 |
audio_path = generate_audio_elevenlabs(response)
|
212 |
+
chat_history.append((question, "[Voice Response]")) # Log that a voice response was generated (optional)
|
213 |
return chat_history, "", audio_path
|
214 |
|
215 |
|
216 |
+
|
217 |
+
|
218 |
def chat_with_streaming(chat_history, question):
|
219 |
# Get the response for the question
|
220 |
response = get_response(question)
|
|
|
228 |
|
229 |
# Ensure the full response is shown at the end
|
230 |
yield chat_history, "", None
|
231 |
+
|
232 |
|
233 |
|
234 |
|
|
|
388 |
fn=handle_mode_selection,
|
389 |
inputs=[mode_selection, chatbot, question_input],
|
390 |
outputs=[chatbot, question_input, audio_output],
|
391 |
+
api_name="api_handle_response",
|
392 |
+
_js=None
|
393 |
)
|
394 |
|
395 |
question_input.submit(
|
396 |
fn=handle_mode_selection,
|
397 |
inputs=[mode_selection, chatbot, question_input],
|
398 |
outputs=[chatbot, question_input, audio_output],
|
399 |
+
api_name="api_handle_response_on_enter",
|
400 |
+
_js=None
|
401 |
)
|
402 |
|
403 |
|