Update app.py
Browse files
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) #
|
| 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 |
-
|
| 87 |
-
|
| 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__":
|