| import gradio as gr |
|
|
| |
| def respond(message, chat_history): |
| |
| if "hello" in message.lower(): |
| response = "Hello! How can I assist you today?" |
| elif "how are you" in message.lower(): |
| response = "I'm just a chatbot, but I'm here to help you!" |
| elif "what is your name" in message.lower(): |
| response = "I'm a chatbot. You can call me Assistant." |
| else: |
| response = "I'm not sure how to answer that. Can you please rephrase your question?" |
|
|
| |
| chat_history.append({"role": "user", "content": message}) |
| chat_history.append({"role": "assistant", "content": response}) |
| return "", chat_history |
|
|
| |
| with gr.Blocks() as demo: |
| chatbot = gr.Chatbot(type="messages") |
| msg = gr.Textbox(label="Enter your message") |
| clear = gr.Button("Clear") |
|
|
| |
| msg.submit(respond, [msg, chatbot], [msg, chatbot]) |
| clear.click(lambda: [], None, chatbot, queue=False) |
|
|
| |
| demo.launch(show_error=True) |