Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -202,17 +202,34 @@ def generate_audio_elevenlabs(text):
|
|
202 |
return None
|
203 |
|
204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
# Create the Gradio Blocks interface
|
206 |
with gr.Blocks() as demo:
|
|
|
207 |
with gr.Row():
|
208 |
with gr.Column():
|
209 |
-
response_output = gr.Textbox(
|
210 |
-
label="Response",
|
211 |
-
placeholder="The response will appear here...",
|
212 |
-
interactive=False,
|
213 |
-
lines=10, # Sets the number of visible lines
|
214 |
-
max_lines=20 # Allows for a larger display area if needed
|
215 |
-
)
|
216 |
question_input = gr.Textbox(label="Ask a Question", placeholder="Type your question here...")
|
217 |
|
218 |
with gr.Column():
|
@@ -227,9 +244,14 @@ with gr.Blocks() as demo:
|
|
227 |
clean_btn = gr.Button("Clean")
|
228 |
|
229 |
# Define interactions
|
230 |
-
get_response_btn.click(fn=get_response, inputs=question_input, outputs=response_output)
|
|
|
|
|
|
|
|
|
|
|
231 |
generate_audio_btn.click(fn=generate_audio_elevenlabs, inputs=response_output, outputs=audio_output)
|
232 |
-
clean_btn.click(fn=clear_fields, inputs=[], outputs=[question_input, response_output])
|
233 |
|
234 |
# Launch the Gradio interface
|
235 |
demo.launch(show_error=True)
|
|
|
202 |
return None
|
203 |
|
204 |
|
205 |
+
def chat_with_bot(messages, user_message):
|
206 |
+
# Add user message to the chat history
|
207 |
+
messages.append((user_message, ""))
|
208 |
+
|
209 |
+
# Generate the response in a streaming manner
|
210 |
+
response = get_response(user_message)
|
211 |
+
|
212 |
+
# Simulate streaming by yielding each character of the response
|
213 |
+
for character in response:
|
214 |
+
messages[-1] = (user_message, messages[-1][1] + character)
|
215 |
+
yield messages # Update the chat history with the latest response incrementally
|
216 |
+
time.sleep(0.05) # Optional: Add a slight delay to simulate real-time streaming
|
217 |
+
|
218 |
+
yield messages # Ensure the final response is fully 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)
|
224 |
with gr.Row():
|
225 |
with gr.Column():
|
226 |
+
#response_output = gr.Textbox(
|
227 |
+
#label="Response",
|
228 |
+
#placeholder="The response will appear here...",
|
229 |
+
#interactive=False,
|
230 |
+
#lines=10, # Sets the number of visible lines
|
231 |
+
#max_lines=20 # Allows for a larger display area if needed
|
232 |
+
#)
|
233 |
question_input = gr.Textbox(label="Ask a Question", placeholder="Type your question here...")
|
234 |
|
235 |
with gr.Column():
|
|
|
244 |
clean_btn = gr.Button("Clean")
|
245 |
|
246 |
# Define interactions
|
247 |
+
#get_response_btn.click(fn=get_response, inputs=question_input, outputs=response_output)
|
248 |
+
#generate_audio_btn.click(fn=generate_audio_elevenlabs, inputs=response_output, outputs=audio_output)
|
249 |
+
#clean_btn.click(fn=clear_fields, inputs=[], outputs=[question_input, response_output])
|
250 |
+
|
251 |
+
# Define interactions
|
252 |
+
get_response_btn.click(fn=chat_with_bot, inputs=[chatbot, question_input], outputs=[chatbot, response_output])
|
253 |
generate_audio_btn.click(fn=generate_audio_elevenlabs, inputs=response_output, outputs=audio_output)
|
254 |
+
clean_btn.click(fn=clear_fields, inputs=[], outputs=[chatbot, question_input, response_output, audio_output])
|
255 |
|
256 |
# Launch the Gradio interface
|
257 |
demo.launch(show_error=True)
|