Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -460,27 +460,42 @@ def create_chatbot_demo():
|
|
| 460 |
|
| 461 |
# --- Connect UI elements ---
|
| 462 |
|
| 463 |
-
#
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
clear_btn.click(
|
| 485 |
clear_conversation,
|
| 486 |
inputs=[],
|
|
|
|
| 460 |
|
| 461 |
# --- Connect UI elements ---
|
| 462 |
|
| 463 |
+
# Define the inputs for the generation function once
|
| 464 |
+
generation_inputs = [
|
| 465 |
+
chat_history, gen_length, steps, constraints_input,
|
| 466 |
+
temperature, top_p, top_k, remasking_strategy, alg_temp,
|
| 467 |
+
visualization_delay
|
| 468 |
+
]
|
| 469 |
+
# Define the outputs for the generation function
|
| 470 |
+
generation_outputs = [chatbot_ui, output_vis]
|
| 471 |
+
|
| 472 |
+
# Handle Textbox Submission (Enter key)
|
| 473 |
+
submit_listener = user_input.submit(
|
| 474 |
+
fn=add_user_message_to_history,
|
| 475 |
+
inputs=[user_input, chat_history],
|
| 476 |
+
outputs=[chat_history, chatbot_ui, user_input, output_vis] # Step 1: Add user msg
|
| 477 |
+
)
|
| 478 |
+
# Chain the bot response generation after the user message is added
|
| 479 |
+
submit_listener.then(
|
| 480 |
+
fn=generate_dream_response,
|
| 481 |
+
inputs=generation_inputs,
|
| 482 |
+
outputs=generation_outputs # Step 2: Generate response and stream vis
|
| 483 |
+
)
|
| 484 |
+
|
| 485 |
+
# Handle Send Button Click
|
| 486 |
+
click_listener = send_btn.click(
|
| 487 |
+
fn=add_user_message_to_history,
|
| 488 |
+
inputs=[user_input, chat_history],
|
| 489 |
+
outputs=[chat_history, chatbot_ui, user_input, output_vis] # Step 1: Add user msg
|
| 490 |
+
)
|
| 491 |
+
# Chain the bot response generation after the user message is added
|
| 492 |
+
click_listener.then(
|
| 493 |
+
fn=generate_dream_response,
|
| 494 |
+
inputs=generation_inputs,
|
| 495 |
+
outputs=generation_outputs # Step 2: Generate response and stream vis
|
| 496 |
+
)
|
| 497 |
+
|
| 498 |
+
# Clear Button Action remains the same
|
| 499 |
clear_btn.click(
|
| 500 |
clear_conversation,
|
| 501 |
inputs=[],
|