Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -203,31 +203,21 @@ def generate_audio_elevenlabs(text):
|
|
203 |
|
204 |
def handle_mode_selection(mode, chat_history, question):
|
205 |
if mode == "Normal Chatbot":
|
206 |
-
#
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
219 |
-
# Get the response for the question
|
220 |
-
response = get_response(question)
|
221 |
-
user_message = question
|
222 |
-
|
223 |
-
# Iterate through each character of the response to simulate streaming
|
224 |
-
for i in range(1, len(response) + 1):
|
225 |
-
# Update the last entry in the chat history with the streaming response
|
226 |
-
chat_history[-1] = (user_message, response[:i])
|
227 |
-
yield chat_history, "", None # Yield updated chat history and reset input box
|
228 |
-
|
229 |
-
# Ensure the full response is shown at the end
|
230 |
-
yield chat_history, "", None
|
231 |
|
232 |
|
233 |
|
@@ -388,16 +378,14 @@ with gr.Blocks(theme="rawrsor1/Everforest") as demo:
|
|
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 |
|
|
|
203 |
|
204 |
def handle_mode_selection(mode, chat_history, question):
|
205 |
if mode == "Normal Chatbot":
|
206 |
+
# Normal chatbot mode: Show the response in the chatbot output
|
|
|
|
|
|
|
207 |
response = get_response(question)
|
208 |
+
chat_history.append((question, response))
|
209 |
+
return chat_history, "", None
|
210 |
+
elif mode == "Voice to Voice Conversation":
|
211 |
+
# Voice to Voice mode: Generate the response using Eleven Labs and return audio without showing text
|
212 |
+
response = get_response(question) # Get the response text (can be omitted if not needed for debugging)
|
213 |
+
audio_path = generate_audio_elevenlabs(response) # Convert the response to audio
|
214 |
chat_history.append((question, "[Voice Response]")) # Log that a voice response was generated (optional)
|
215 |
return chat_history, "", audio_path
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
|
222 |
|
223 |
|
|
|
378 |
fn=handle_mode_selection,
|
379 |
inputs=[mode_selection, chatbot, question_input],
|
380 |
outputs=[chatbot, question_input, audio_output],
|
381 |
+
api_name="api_handle_response"
|
|
|
382 |
)
|
383 |
|
384 |
question_input.submit(
|
385 |
fn=handle_mode_selection,
|
386 |
inputs=[mode_selection, chatbot, question_input],
|
387 |
outputs=[chatbot, question_input, audio_output],
|
388 |
+
api_name="api_handle_response_on_enter"
|
|
|
389 |
)
|
390 |
|
391 |
|