chatbot-space / app.py
abidlabs's picture
abidlabs HF staff
Create app.py
6aa7293 verified
raw
history blame contribute delete
714 Bytes
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)