multimodalart HF Staff commited on
Commit
5807c79
·
verified ·
1 Parent(s): f4ff30a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -21
app.py CHANGED
@@ -460,27 +460,42 @@ def create_chatbot_demo():
460
 
461
  # --- Connect UI elements ---
462
 
463
- # User Input Submission (Textbox Enter or Send Button Click)
464
- submit_triggers = [user_input.submit, send_btn.click]
465
-
466
- # 1. Add user message to UI immediately
467
- for trigger in submit_triggers:
468
- trigger.then(
469
- add_user_message_to_history,
470
- inputs=[user_input, chat_history],
471
- outputs=[chat_history, chatbot_ui, user_input, output_vis] # Update chat, clear input, clear vis
472
- ).then( # 2. Trigger bot response generation (as a generator)
473
- generate_dream_response,
474
- inputs=[
475
- chat_history, gen_length, steps, constraints_input,
476
- temperature, top_p, top_k, remasking_strategy, alg_temp,
477
- visualization_delay
478
- ],
479
- outputs=[chatbot_ui, output_vis] # Stream updates to chatbot and visualization
480
- # Note: The final text response is implicitly handled by updating chatbot_ui
481
- )
482
-
483
- # Clear Button Action
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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=[],