Spaces:
Runtime error
Runtime error
| """ | |
| Utility functions for the AI Chatbot application. | |
| """ | |
| def format_chat_message(role: str, content: str) -> dict: | |
| """Format a chat message for the chatbot component.""" | |
| return {"role": role, "content": content} | |
| def validate_message(message: str) -> bool: | |
| """Validate that a message is safe and appropriate.""" | |
| # Simple validation - in production you'd want more robust checks | |
| forbidden_words = ["hate", "violence", "harm"] # Basic content filtering | |
| return not any(word in message.lower() for word in forbidden_words) | |
| def get_timestamp() -> str: | |
| """Get current timestamp for logging.""" | |
| from datetime import datetime | |
| return datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
| } | |
| This AI chatbot application features: | |
| ## π¨ Modern Design | |
| - **Custom Soft theme** with indigo primary colors | |
| - **Google Inter font** for clean typography | |
| - **Responsive layout** that works on different screen sizes | |
| - **Professional UI** with proper spacing and sizing | |
| ## π€ Core Features | |
| - **Interactive chat interface** with message history | |
| - **Streaming responses** for natural conversation flow | |
| - **Message actions**: Like and Retry functionality | |
| - **Chat examples** for users to try | |
| - **Clear chat functionality** | |
| ## π Gradio 6 Best Practices | |
| - β **Theme in demo.launch()** - Correct Gradio 6 syntax | |
| - β **Proper event handling** with api_visibility parameter | |
| - β **Responsive components** with appropriate sizing | |
| - β **Error handling** and user feedback | |
| - β **Clean code structure** with proper documentation | |
| ## π± User Experience | |
| - **Intuitive input** with placeholder text | |
| - **Visual feedback** through info/warning messages | |
| - **Copy and share** buttons for chat messages | |
| - **Accessibility** with proper labels and descriptions | |
| The chatbot uses simulated AI responses with pattern matching, but you can easily replace this with actual AI model integrations (OpenAI, Hugging Face, etc.). |