ababio commited on
Commit
e58b03e
1 Parent(s): 92fd2a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -74,18 +74,24 @@ def bot(history):
74
  history[-1][1] = ""
75
  for character in bot_message:
76
  history[-1][1] += character
77
- time.sleep(0.01) # Reduced sleep time to make response appear faster
78
  yield history
79
 
80
- # Define Gradio Blocks interface
81
  with gr.Blocks() as demo:
82
  chatbot = gr.Chatbot()
83
- msg = gr.Textbox()
 
84
  clear = gr.Button("Clear")
85
 
86
- msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
87
- bot, chatbot, chatbot
88
- )
 
 
 
 
 
89
  clear.click(lambda: None, None, chatbot, queue=False)
90
 
91
  if __name__ == "__main__":
 
74
  history[-1][1] = ""
75
  for character in bot_message:
76
  history[-1][1] += character
77
+ time.sleep(0.01) # Adjust the speed here
78
  yield history
79
 
80
+ # Define Gradio Blocks interface with a submit button
81
  with gr.Blocks() as demo:
82
  chatbot = gr.Chatbot()
83
+ msg = gr.Textbox(placeholder="Type your message here...")
84
+ submit_btn = gr.Button("Submit")
85
  clear = gr.Button("Clear")
86
 
87
+ def handle_message(user_message, history):
88
+ history = user(user_message, history)
89
+ return bot(history)
90
+
91
+ # Bind the submit button to handle_message function
92
+ submit_btn.click(handle_message, [msg, chatbot], chatbot, queue=False)
93
+
94
+ # Bind the clear button to clear the chat history
95
  clear.click(lambda: None, None, chatbot, queue=False)
96
 
97
  if __name__ == "__main__":