Spaces:
Runtime error
Runtime error
| 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. |