Pijush2023 commited on
Commit
5f2ac1a
·
verified ·
1 Parent(s): dab84f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -191,15 +191,17 @@ def generate_audio_elevenlabs(text):
191
  logging.error(f"Error generating audio: {response.text}")
192
  return None
193
 
 
 
 
 
194
 
 
195
  # Define function to generate a streaming response
196
  def chat_with_bot(messages, user_message):
197
  # Add user message to the chat history
198
  messages.append((user_message, ""))
199
 
200
- # Clear the input box immediately
201
- yield messages, ""
202
-
203
  # Generate the response in a streaming manner
204
  response = get_response(user_message)
205
 
@@ -262,7 +264,9 @@ with gr.Blocks(theme="rawrsor1/Everforest") as demo:
262
  gr.Examples(examples=examples, fn=insert_prompt, inputs=question_input, outputs=question_input)
263
 
264
  # Define interactions
265
- get_response_btn.click(fn=chat_with_bot, inputs=[chatbot, question_input], outputs=chatbot)
 
 
266
  generate_audio_btn.click(fn=generate_audio_from_last_response, inputs=chatbot, outputs=audio_output)
267
  clean_btn.click(fn=clear_fields, inputs=[], outputs=[chatbot, question_input, audio_output])
268
 
 
191
  logging.error(f"Error generating audio: {response.text}")
192
  return None
193
 
194
+ # Function to add a user's message to the chat history and clear the input box
195
+ def add_message(history, message):
196
+ history.append((message, None)) # Add the user's message to the chat history
197
+ return history, gr.Textbox(value="", interactive=True, show_label=False) # Clear the input box
198
 
199
+
200
  # Define function to generate a streaming response
201
  def chat_with_bot(messages, user_message):
202
  # Add user message to the chat history
203
  messages.append((user_message, ""))
204
 
 
 
 
205
  # Generate the response in a streaming manner
206
  response = get_response(user_message)
207
 
 
264
  gr.Examples(examples=examples, fn=insert_prompt, inputs=question_input, outputs=question_input)
265
 
266
  # Define interactions
267
+ #get_response_btn.click(fn=chat_with_bot, inputs=[chatbot, question_input], outputs=chatbot)
268
+ get_response_btn.click(fn=add_message, inputs=[chatbot, question_input], outputs=[chatbot, question_input])\
269
+ .then(fn=chat_with_bot, inputs=[chatbot, question_input], outputs=chatbot)
270
  generate_audio_btn.click(fn=generate_audio_from_last_response, inputs=chatbot, outputs=audio_output)
271
  clean_btn.click(fn=clear_fields, inputs=[], outputs=[chatbot, question_input, audio_output])
272