import gradio as gr def respond(message, chat_history): # Append the user message to the chat history chat_history.append({"role": "user", "content": message}) # Echo back the user message as the assistant's response chat_history.append({"role": "assistant", "content": message}) return "", chat_history # Return an empty string for the input box and the updated chat history with gr.Blocks() as demo: chatbot = gr.Chatbot(type="messages") msg = gr.Textbox(label="User Input") # Set up the event listener for the user's message submission msg.submit(respond, [msg, chatbot], [msg, chatbot]) # Launch the Gradio app if __name__ == "__main__": demo.launch(show_error=True)