File size: 630 Bytes
c3a1883
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import time

import gradio as gr


def chatbot_tab():
    with gr.Tab("chat bot"):
        chatbot = gr.Chatbot(label='对话框', elem_id='ddd1233')
        msg = gr.Textbox()
        clear = gr.Button("Clear")

        def user(user_message, history):
            return "", history + [[user_message, None]]

        def bot(history):
            history[-1][1] = f"你说: {history[-1][0]}"
            time.sleep(1)
            return history

        msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
            bot, chatbot, chatbot
        )
        clear.click(lambda: None, None, chatbot, queue=False)