Pijush2023 commited on
Commit
4451481
·
verified ·
1 Parent(s): e53b56a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -219,11 +219,12 @@ def chat_with_bot(messages, user_message):
219
 
220
 
221
  # Function to generate audio with Eleven Labs TTS from the last bot response
222
- def generate_audio_from_last_response(messages):
223
- # Ensure the messages list is not empty and the last message has a bot response
224
- if messages and isinstance(messages[-1], tuple) and len(messages[-1]) == 2 and messages[-1][1]:
225
- last_response = messages[-1][1]
226
- return generate_audio_elevenlabs(last_response)
 
227
  return None
228
 
229
 
@@ -260,7 +261,7 @@ with gr.Blocks() as demo:
260
 
261
  # Define interactions
262
  get_response_btn.click(fn=chat_with_bot, inputs=[chatbot, question_input], outputs=chatbot)
263
- generate_audio_btn.click(fn=generate_audio_from_last_response, inputs=question_input, outputs=audio_output)
264
  clean_btn.click(fn=clear_fields, inputs=[], outputs=[chatbot, question_input, audio_output])
265
 
266
  # Launch the Gradio interface
 
219
 
220
 
221
  # Function to generate audio with Eleven Labs TTS from the last bot response
222
+ def generate_audio_from_last_response(history):
223
+ # Get the most recent bot response from the chat history
224
+ if history and len(history) > 0:
225
+ recent_response = history[-1][1] # The second item in the tuple is the bot response text
226
+ if recent_response:
227
+ return generate_audio_elevenlabs(recent_response)
228
  return None
229
 
230
 
 
261
 
262
  # Define interactions
263
  get_response_btn.click(fn=chat_with_bot, inputs=[chatbot, question_input], outputs=chatbot)
264
+ generate_audio_btn.click(fn=generate_audio_from_last_response, inputs=chatbot, outputs=audio_output)
265
  clean_btn.click(fn=clear_fields, inputs=[], outputs=[chatbot, question_input, audio_output])
266
 
267
  # Launch the Gradio interface