File size: 1,930 Bytes
76c14bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
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.).