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)