kdevoe commited on
Commit
0ba38df
·
verified ·
1 Parent(s): e8c2ecc

Reversing shift + enter and shift inputs

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -34,6 +34,10 @@ def chat_with_flan(input_text):
34
  # Set up the Gradio interface with the input box below the output box
35
  with gr.Blocks() as interface:
36
  chatbot_output = gr.Textbox(label="Conversation", lines=15, placeholder="Chat history will appear here...", interactive=False)
 
 
 
 
37
  user_input = gr.Textbox(label="Your Input", placeholder="Type your message here...", lines=2)
38
 
39
  def update_chat(input_text, chat_history):
@@ -42,6 +46,20 @@ with gr.Blocks() as interface:
42
 
43
  # Arrange input/output components with live updating
44
  user_input.submit(update_chat, inputs=[user_input, chatbot_output], outputs=[chatbot_output, user_input])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  # Launch the Gradio app
47
  interface.launch()
 
34
  # Set up the Gradio interface with the input box below the output box
35
  with gr.Blocks() as interface:
36
  chatbot_output = gr.Textbox(label="Conversation", lines=15, placeholder="Chat history will appear here...", interactive=False)
37
+
38
+ # Add the instruction message above the input box
39
+ gr.Markdown("**Instructions:** Press `Enter` to submit, and `Shift + Enter` for a new line.")
40
+
41
  user_input = gr.Textbox(label="Your Input", placeholder="Type your message here...", lines=2)
42
 
43
  def update_chat(input_text, chat_history):
 
46
 
47
  # Arrange input/output components with live updating
48
  user_input.submit(update_chat, inputs=[user_input, chatbot_output], outputs=[chatbot_output, user_input])
49
+
50
+ # JavaScript code to reverse the behavior: Enter to submit, Shift+Enter for new line
51
+ user_input.add_text_input_event_handlers(
52
+ {
53
+ "keydown": """
54
+ function(event) {
55
+ if (event.key === 'Enter' && !event.shiftKey) {
56
+ event.preventDefault();
57
+ document.querySelector('button[type=submit]').click();
58
+ }
59
+ }
60
+ """
61
+ }
62
+ )
63
 
64
  # Launch the Gradio app
65
  interface.launch()