import gradio as gr def handle_chat(message, history): if history is None: history = [] history.append({"role": "user", "content": message}) history.append({"role": "assistant", "content": f"You said: {message}"}) return history, history with gr.Blocks() as demo: chatbot = gr.Chatbot(type="messages") state = gr.State([]) with gr.Row(): msg = gr.Textbox(placeholder="Type a message...") submit = gr.Button("Send") submit.click(handle_chat, [msg, state], [chatbot, state]) msg.submit(handle_chat, [msg, state], [chatbot, state]) demo.launch()