# app_gradio_enhanced.py import gradio as gr from client_agent import answer_sync def chat_fn(message: str, history: list[dict]): """Enhanced chat function with better error handling""" try: reply = answer_sync(message) return reply except Exception as e: return f"â ī¸ Error: {str(e)}" # Custom CSS for professional styling custom_css = """ /* Main container styling */ .gradio-container { max-width: 1200px !important; margin: 0 auto !important; } /* Header styling */ .header-text { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; text-align: center; font-weight: bold; margin-bottom: 1rem; } /* Chat message styling */ .message-wrap { border-radius: 12px !important; margin: 8px 0 !important; padding: 12px 16px !important; } .user-message { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important; color: white !important; } .bot-message { background: #f8f9fa !important; border-left: 4px solid #667eea !important; } /* Input styling */ .input-container { border-radius: 25px !important; border: 2px solid #e9ecef !important; transition: all 0.3s ease !important; } .input-container:focus-within { border-color: #667eea !important; box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important; } /* Button styling */ .submit-btn { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important; border: none !important; border-radius: 20px !important; padding: 10px 20px !important; font-weight: 600 !important; transition: all 0.3s ease !important; } .submit-btn:hover { transform: translateY(-2px) !important; box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3) !important; } /* Status indicators */ .status-indicator { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 20px; font-size: 14px; font-weight: 500; } .status-online { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; } /* Loading animation */ @keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } } .loading { animation: pulse 1.5s infinite; } /* Responsive design */ @media (max-width: 768px) { .gradio-container { padding: 10px !important; } .message-wrap { margin: 4px 0 !important; padding: 8px 12px !important; } } /* Dark mode support */ .dark .bot-message { background: #2d3748 !important; color: #e2e8f0 !important; border-left-color: #667eea !important; } .dark .input-container { background: #2d3748 !important; border-color: #4a5568 !important; color: #e2e8f0 !important; } """ def create_enhanced_interface(): """Create an enhanced Gradio interface with professional styling""" with gr.Blocks( css=custom_css, theme=gr.themes.Soft( primary_hue="blue", secondary_hue="purple", neutral_hue="slate", font=[ gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif" ] ), title="đ Docs Navigator - AI-Powered Documentation Assistant", analytics_enabled=False ) as interface: # Header section with gr.Row(): gr.Markdown( """ # đ Docs Navigator MCP ### AI-Powered Documentation Assistant Ask questions about your documentation and get intelligent, contextual answers powered by Claude and MCP. """, elem_classes=["header-text"] ) # Status indicator with gr.Row(): gr.HTML( """
đ§ Powered by Model Context Protocol (MCP) | đ¤ Claude AI | đ¨ Gradio
đĄ Tip: Ask specific questions about your documentation for the best results!