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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -17
app.py CHANGED
@@ -34,32 +34,19 @@ 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
-
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):
44
  updated_history = chat_with_flan(input_text)
45
  return updated_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()
 
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
+ # Input box for the user
42
+ user_input = gr.Textbox(label="Your Input", placeholder="Type your message here...", lines=2, show_label=True)
43
 
44
  def update_chat(input_text, chat_history):
45
  updated_history = chat_with_flan(input_text)
46
  return updated_history, ""
47
 
48
+ # Submit when pressing Enter
49
  user_input.submit(update_chat, inputs=[user_input, chatbot_output], outputs=[chatbot_output, user_input])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  # Launch the Gradio app
52
  interface.launch()