Pijush2023 commited on
Commit
91833b3
·
verified ·
1 Parent(s): 6f63f06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -138,7 +138,7 @@ _search_query = RunnableBranch(
138
 
139
 
140
  template = """I am a guide for Birmingham, Alabama. I can provide recommendations and insights about the city, including events and activities.
141
- Ask your question directly, and I'll provide a precise and quick response.
142
  {context}
143
  Question: {question}
144
  Answer:"""
@@ -218,6 +218,15 @@ def chat_with_bot(messages, user_message):
218
  yield messages # Final yield to ensure full response is displayed
219
 
220
 
 
 
 
 
 
 
 
 
 
221
  # Create the Gradio Blocks interface
222
  with gr.Blocks() as demo:
223
  chatbot = gr.Chatbot([], elem_id="RADAR", bubble_full_width=False)
@@ -250,7 +259,7 @@ with gr.Blocks() as demo:
250
 
251
  # Define interactions
252
  get_response_btn.click(fn=chat_with_bot, inputs=[chatbot, question_input], outputs=chatbot)
253
- generate_audio_btn.click(fn=generate_audio_elevenlabs, inputs=question_input, outputs=audio_output)
254
  clean_btn.click(fn=clear_fields, inputs=[], outputs=[chatbot, question_input, audio_output])
255
 
256
  # Launch the Gradio interface
 
138
 
139
 
140
  template = """I am a guide for Birmingham, Alabama. I can provide recommendations and insights about the city, including events and activities.
141
+ Ask your question directly, and I'll provide a precise and quick,short and crisp response in a conversational way without any Greet.
142
  {context}
143
  Question: {question}
144
  Answer:"""
 
218
  yield messages # Final yield to ensure full response is displayed
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
+ # Get the last bot response from the conversation history
224
+ if messages and messages[-1][1]: # Check if there is a bot response
225
+ last_response = messages[-1][1]
226
+ return generate_audio_elevenlabs(last_response)
227
+ return None
228
+
229
+
230
  # Create the Gradio Blocks interface
231
  with gr.Blocks() as demo:
232
  chatbot = gr.Chatbot([], elem_id="RADAR", bubble_full_width=False)
 
259
 
260
  # Define interactions
261
  get_response_btn.click(fn=chat_with_bot, inputs=[chatbot, question_input], outputs=chatbot)
262
+ generate_audio_btn.click(fn=generate_audio_from_last_response, inputs=question_input, outputs=audio_output)
263
  clean_btn.click(fn=clear_fields, inputs=[], outputs=[chatbot, question_input, audio_output])
264
 
265
  # Launch the Gradio interface