Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -193,16 +193,16 @@ def generate_audio_elevenlabs(text):
|
|
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 |
-
|
197 |
-
|
|
|
198 |
|
199 |
|
200 |
# Define function to generate a streaming response
|
201 |
-
def chat_with_bot(messages
|
202 |
-
#
|
203 |
-
messages
|
204 |
-
|
205 |
-
# Generate the response in a streaming manner
|
206 |
response = get_response(user_message)
|
207 |
|
208 |
# Simulate streaming response by iterating over each character in the response
|
@@ -211,7 +211,7 @@ def chat_with_bot(messages, user_message):
|
|
211 |
yield messages # Stream each character
|
212 |
time.sleep(0.05) # Adjust delay as needed for real-time effect
|
213 |
|
214 |
-
yield messages # Final yield to ensure full response is displayed
|
215 |
|
216 |
|
217 |
# Function to generate audio with Eleven Labs TTS from the last bot response
|
@@ -266,7 +266,7 @@ with gr.Blocks(theme="rawrsor1/Everforest") as demo:
|
|
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
|
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 |
|
|
|
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 |
+
if message.strip():
|
197 |
+
history.append((message, None)) # Add the user's message to the chat history only if it's not empty
|
198 |
+
return history, "" # Clear the input box
|
199 |
|
200 |
|
201 |
# Define function to generate a streaming response
|
202 |
+
def chat_with_bot(messages):
|
203 |
+
user_message = messages[-1][0] # Get the last user message (input)
|
204 |
+
messages[-1] = (user_message, "") # Prepare the placeholder for the bot's response
|
205 |
+
|
|
|
206 |
response = get_response(user_message)
|
207 |
|
208 |
# Simulate streaming response by iterating over each character in the response
|
|
|
211 |
yield messages # Stream each character
|
212 |
time.sleep(0.05) # Adjust delay as needed for real-time effect
|
213 |
|
214 |
+
yield messages # Final yield to ensure the full response is displayed
|
215 |
|
216 |
|
217 |
# Function to generate audio with Eleven Labs TTS from the last bot response
|
|
|
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], 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 |
|