import gradio as gr from utils import get_chatbot_response import random def chat_response(message, history): """ Process user message and generate chatbot response Args: message (str): User's input message history (list): Chat history for context Returns: str: Generated response from the chatbot """ if not message.strip(): return "Please enter a message to chat!" # Get response from the utility function response = get_chatbot_response(message, history) return response def clear_chat(): """Clear the chat history""" return [] def refresh_suggestions(): """Generate new conversation starters""" suggestions = [ "What's the weather like today?", "Tell me a joke", "How does artificial intelligence work?", "What are some productivity tips?", "Explain quantum computing simply", "What are the latest trends in technology?", "How can I learn programming?", "What's the meaning of life?", "Tell me about space exploration", "What are some good books to read?" ] return random.choice(suggestions) # Create the Gradio Blocks interface with gr.Blocks( title="AI Chatbot", theme=gr.themes.Soft( primary_hue="blue", secondary_hue="gray", font=[gr.themes.GoogleFont("Inter"), "Arial", "sans-serif"] ), css=""" .gradio-container {max-width: 1200px !important;} .chatbot-container {height: 600px !important;} .header-text {text-align: center; margin-bottom: 20px;} .footer-text {text-align: center; margin-top: 20px; color: #666;} """, title="Intelligent Chatbot" ) as demo: # Header gr.HTML("""
""") # Main chat interface with gr.Row(): with gr.Column(scale=3): chat_interface = gr.ChatInterface( fn=chat_response, title="", description="", examples=[ "Hello! How are you?", "What's the weather like?", "Tell me a joke", "Explain AI in simple terms", "What are some productivity tips?", "How do I learn programming?", "What's the meaning of life?", "Tell me about space", "What books do you recommend?", "How does the internet work?" ], example_labels=[ "Greeting", "Weather", "Joke", "AI Explanation", "Productivity", "Programming", "Philosophy", "Space", "Books", "Technology" ], retry_btn="Send Again ↻", undo_btn="Undo Last Message ↶", clear_btn="Clear Chat 🗑️", submit_btn="Send ➤" ) with gr.Column(scale=1): # Side panel with conversation starters and info gr.HTML("""Model: AI Assistant v1.0
Features: Multi-turn conversations
Topics: General knowledge, tech, science, jokes & more!