File size: 1,271 Bytes
3f116b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import gradio as gr

def chatbot(input_text, history=[]):
    if not input_text:
        return history, ""
    history = history + [f"User: {input_text}"]
    response = f"You said: {input_text}"  # Simple response
    history = history + [f"Bot: {response}"]
    return history, ""

with gr.Blocks() as demo:
    gr.Markdown("# Simple Chatbot\nBuilt with anycoder")
    chatbot_ui = gr.Chatbot()
    input_box = gr.Textbox(placeholder="Type your message...", label="Message")
    with gr.Row():
        send_btn = gr.Button("Send", variant="primary")
        clear_btn = gr.Button("Clear")

    send_btn.click(chatbot, [input_box, chatbot_ui], [chatbot_ui, input_box])
    clear_btn.click(lambda: ("", []), [], [chatbot_ui, input_box])

if __name__ == "__main__":
    demo.launch()
This chatbot application includes:
- **Modern Interface**: Clean chat UI with chatbot component
- **Interactive Controls**: Send and clear buttons
- **State Management**: Maintains conversation history
- **User-Friendly**: Clear labels and placeholder text
- **Attribution**: "Built with anycoder" link as requested

The chatbot currently echoes user messages. You can easily extend the `chatbot` function to integrate with any LLM API or language model for more sophisticated responses.