Spaces:
Running
Running
| """ | |
| LifeAdmin AI - Main Gradio Application | |
| Hackathon Project: Track 2 - MCP in Action | |
| Hugging Face MCP Birthday Hackathon | |
| An autonomous life management agent with real MCP tool servers, | |
| RAG-enabled document search, and voice control. | |
| """ | |
| import gradio as gr | |
| import asyncio | |
| import os | |
| from pathlib import Path | |
| from dotenv import load_dotenv | |
| # Load environment variables | |
| load_dotenv() | |
| from ui.manual_dashboard import create_manual_dashboard | |
| from ui.voice_agent_ui import create_voice_agent_ui | |
| from agent.agent_core import LifeAdminAgent | |
| from utils.llm_utils import setup_llm_fallback | |
| # Initialize directories | |
| Path("data/uploads").mkdir(parents=True, exist_ok=True) | |
| Path("data/outputs").mkdir(parents=True, exist_ok=True) | |
| Path("data/chroma_db").mkdir(parents=True, exist_ok=True) | |
| # Initialize agent | |
| print("π€ Initializing LifeAdmin AI Agent...") | |
| agent = LifeAdminAgent() | |
| print("β Agent initialized successfully!") | |
| # Custom CSS for beautiful UI | |
| custom_css = """ | |
| /* Main container styling */ | |
| .gradio-container { | |
| font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; | |
| max-width: 1400px !important; | |
| } | |
| /* Header styling */ | |
| .header-container { | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| padding: 2rem; | |
| border-radius: 1rem; | |
| color: white; | |
| margin-bottom: 2rem; | |
| box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3); | |
| } | |
| .header-container h1 { | |
| margin: 0; | |
| font-size: 2.5rem; | |
| font-weight: 700; | |
| text-shadow: 0 2px 4px rgba(0,0,0,0.1); | |
| } | |
| .header-container p { | |
| margin: 0.5rem 0 0 0; | |
| opacity: 0.95; | |
| } | |
| /* Tool card styling */ | |
| .tool-card { | |
| border: 2px solid #e2e8f0; | |
| border-radius: 0.75rem; | |
| padding: 1.25rem; | |
| transition: all 0.3s ease; | |
| background: white; | |
| margin: 0.5rem 0; | |
| } | |
| .tool-card:hover { | |
| border-color: #667eea; | |
| box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15); | |
| transform: translateY(-2px); | |
| } | |
| /* Thought bubble styling */ | |
| .thought-bubble { | |
| background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%); | |
| border-left: 4px solid #667eea; | |
| padding: 1rem; | |
| margin: 0.75rem 0; | |
| border-radius: 0.5rem; | |
| box-shadow: 0 2px 4px rgba(0,0,0,0.05); | |
| } | |
| /* Success banner */ | |
| .success-banner { | |
| background: linear-gradient(135deg, #c6f6d5 0%, #9ae6b4 100%); | |
| color: #22543d; | |
| padding: 1rem; | |
| border-radius: 0.5rem; | |
| border-left: 4px solid #38a169; | |
| font-weight: 500; | |
| } | |
| /* Error banner */ | |
| .error-banner { | |
| background: linear-gradient(135deg, #fed7d7 0%, #fc8181 100%); | |
| color: #742a2a; | |
| padding: 1rem; | |
| border-radius: 0.5rem; | |
| border-left: 4px solid #e53e3e; | |
| font-weight: 500; | |
| } | |
| /* Button styling */ | |
| .primary-button { | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important; | |
| border: none !important; | |
| color: white !important; | |
| font-weight: 600 !important; | |
| padding: 0.75rem 1.5rem !important; | |
| border-radius: 0.5rem !important; | |
| transition: all 0.3s ease !important; | |
| } | |
| .primary-button:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4) !important; | |
| } | |
| /* Tab styling */ | |
| .tab-nav button { | |
| font-weight: 500 !important; | |
| padding: 0.75rem 1.5rem !important; | |
| } | |
| .tab-nav button.selected { | |
| border-bottom: 3px solid #667eea !important; | |
| color: #667eea !important; | |
| } | |
| /* File upload area */ | |
| .upload-area { | |
| border: 2px dashed #cbd5e0; | |
| border-radius: 0.75rem; | |
| padding: 2rem; | |
| text-align: center; | |
| transition: all 0.3s ease; | |
| } | |
| .upload-area:hover { | |
| border-color: #667eea; | |
| background: #f7fafc; | |
| } | |
| /* Status indicator */ | |
| .status-indicator { | |
| display: inline-block; | |
| width: 10px; | |
| height: 10px; | |
| border-radius: 50%; | |
| margin-right: 0.5rem; | |
| animation: pulse 2s infinite; | |
| } | |
| @keyframes pulse { | |
| 0%, 100% { opacity: 1; } | |
| 50% { opacity: 0.5; } | |
| } | |
| .status-active { | |
| background: #48bb78; | |
| } | |
| .status-processing { | |
| background: #ed8936; | |
| } | |
| .status-error { | |
| background: #f56565; | |
| } | |
| /* Footer styling */ | |
| .footer { | |
| text-align: center; | |
| margin-top: 3rem; | |
| padding: 1.5rem; | |
| border-top: 1px solid #e2e8f0; | |
| color: #718096; | |
| } | |
| /* Responsive adjustments */ | |
| @media (max-width: 768px) { | |
| .header-container h1 { | |
| font-size: 1.75rem; | |
| } | |
| .gradio-container { | |
| padding: 1rem; | |
| } | |
| } | |
| /* Custom scrollbar */ | |
| ::-webkit-scrollbar { | |
| width: 8px; | |
| } | |
| ::-webkit-scrollbar-track { | |
| background: #f1f1f1; | |
| } | |
| ::-webkit-scrollbar-thumb { | |
| background: #667eea; | |
| border-radius: 4px; | |
| } | |
| ::-webkit-scrollbar-thumb:hover { | |
| background: #764ba2; | |
| } | |
| """ | |
| def create_app(): | |
| """Create and configure the Gradio application""" | |
| with gr.Blocks( | |
| theme=gr.themes.Soft( | |
| primary_hue="purple", | |
| secondary_hue="blue", | |
| neutral_hue="slate", | |
| font=[gr.themes.GoogleFont("Inter"), "system-ui", "sans-serif"], | |
| ), | |
| css=custom_css, | |
| title="LifeAdmin AI - Your Autonomous Life Management Agent", | |
| analytics_enabled=False | |
| ) as app: | |
| # Header | |
| with gr.Row(): | |
| gr.HTML(""" | |
| <div class="header-container"> | |
| <h1>π€ LifeAdmin AI</h1> | |
| <p style="font-size: 1.3rem; margin-top: 0.5rem;"> | |
| Your Autonomous Life Management Agent | |
| </p> | |
| <p style="font-size: 0.95rem; margin-top: 0.75rem; opacity: 0.9;"> | |
| Powered by 7 Real MCP Tool Servers β’ Built for Hugging Face Hackathon | |
| </p> | |
| <div style="margin-top: 1rem; display: flex; gap: 1.5rem; font-size: 0.9rem;"> | |
| <div style="display: flex; align-items: center; gap: 0.5rem;"> | |
| <span>β‘</span> | |
| <span>Autonomous Execution</span> | |
| </div> | |
| <div style="display: flex; align-items: center; gap: 0.5rem;"> | |
| <span>π€</span> | |
| <span>Voice Control</span> | |
| </div> | |
| <div style="display: flex; align-items: center; gap: 0.5rem;"> | |
| <span>π</span> | |
| <span>RAG-Powered Search</span> | |
| </div> | |
| <div style="display: flex; align-items: center; gap: 0.5rem;"> | |
| <span>πΎ</span> | |
| <span>Memory System</span> | |
| </div> | |
| </div> | |
| </div> | |
| """) | |
| # Main tabs | |
| with gr.Tabs() as tabs: | |
| # Manual Dashboard Mode | |
| with gr.Tab("π Manual Dashboard", id="manual"): | |
| gr.Markdown(""" | |
| ### π― Manual Mode | |
| Upload files and use individual tools with full control over parameters and outputs. | |
| Perfect for precise document processing and batch operations. | |
| """) | |
| create_manual_dashboard(agent) | |
| # Voice Agent Mode | |
| with gr.Tab("π€ Voice Agent", id="voice"): | |
| gr.Markdown(""" | |
| ### π€ Voice Agent Mode | |
| Speak your commands and let the AI agent autonomously plan and execute tasks. | |
| The agent will use multiple tools, manage context, and provide voice responses. | |
| """) | |
| create_voice_agent_ui(agent) | |
| # About & Documentation | |
| with gr.Tab("βΉοΈ About", id="about"): | |
| gr.Markdown(""" | |
| # About LifeAdmin AI | |
| ## π― What is LifeAdmin AI? | |
| LifeAdmin AI is an autonomous life management agent that helps you handle everyday administrative tasks through natural language and voice commands. Built for the **Hugging Face MCP Birthday Hackathon (Track 2: MCP in Action)**. | |
| ### Key Capabilities | |
| - π **Document Processing**: OCR, summarization, metadata extraction | |
| - π **Calendar Management**: Automatic event creation from extracted dates | |
| - βοΈ **Email Drafting**: Context-aware professional email generation | |
| - π **Form Filling**: Auto-fill templates with extracted data | |
| - ποΈ **File Organization**: Intelligent file classification and management | |
| - π **Document Search**: RAG-powered semantic search across all documents | |
| --- | |
| ## ποΈ Architecture | |
| ### System Components | |
| ``` | |
| βββββββββββββββββββββββββββββββββββββββ | |
| β Gradio 6 UI Layer β | |
| β Manual Dashboard | Voice Agent β | |
| βββββββββββββββββββββββββββββββββββββββ | |
| β | |
| βββββββββββββββββββββββββββββββββββββββ | |
| β Autonomous Agent Core β | |
| β Planning β Execution β Reflection β | |
| βββββββββββββββββββββββββββββββββββββββ | |
| β | |
| βββββββββββββββββββββββββββββββββββββββ | |
| β MCP Tool Servers (7) β | |
| β OCR | PDF | Forms | Calendar β | |
| β Email | Files | RAG Search β | |
| βββββββββββββββββββββββββββββββββββββββ | |
| β | |
| βββββββββββββββββββββββββββββββββββββββ | |
| β Supporting Infrastructure β | |
| β RAG Engine | Memory | LLM Chain β | |
| βββββββββββββββββββββββββββββββββββββββ | |
| ``` | |
| ### MCP Tool Servers | |
| 1. **OCR Server** - Extract text from images and scanned documents | |
| 2. **PDF Server** - Summarize and analyze PDF documents | |
| 3. **Form Filler** - Auto-fill DOCX/XLSX templates | |
| 4. **Calendar Server** - Generate ICS calendar events | |
| 5. **Email Server** - Draft context-aware emails | |
| 6. **File Manager** - Organize and classify files | |
| 7. **RAG Server** - Semantic document search | |
| --- | |
| ## π How to Use | |
| ### Manual Mode | |
| 1. **Upload Documents**: Drag and drop PDFs, images, or documents | |
| 2. **Select Tool**: Choose from available tools (OCR, Summarize, etc.) | |
| 3. **Configure Parameters**: Set language, summary length, tone, etc. | |
| 4. **Execute**: Click the execute button to run the tool | |
| 5. **Download Results**: Save generated files (ICS, emails, forms) | |
| ### Voice Mode | |
| 1. **Click Microphone**: Start voice recording | |
| 2. **Speak Command**: Give a natural language instruction | |
| 3. **Agent Plans**: Watch the agent create an execution plan | |
| 4. **Auto-Execute**: Agent runs necessary tools autonomously | |
| 5. **Listen to Response**: Hear the results via text-to-speech | |
| --- | |
| ## π‘ Example Commands | |
| ### For Voice Agent | |
| - *"Extract all deadlines from my PDFs and create calendar events"* | |
| - *"Summarize this invoice and draft a dispute email"* | |
| - *"Organize my receipts folder by date"* | |
| - *"Find all documents mentioning Project X and summarize them"* | |
| - *"Fill out this form using data from my uploaded documents"* | |
| - *"Create a calendar event for tomorrow at 2 PM titled Team Meeting"* | |
| ### For Manual Mode | |
| - Upload an invoice β Use OCR β Extract metadata β Create calendar event | |
| - Upload multiple PDFs β Summarize each β Draft summary email | |
| - Upload form template β Provide data β Generate filled form | |
| --- | |
| ## π οΈ Technical Stack | |
| ### Core Technologies | |
| - **Framework**: Gradio 6 (latest features, metadata traces) | |
| - **Agent**: Custom autonomous agent with planning & reflection | |
| - **MCP**: Real JSONRPC-based tool servers | |
| - **RAG**: ChromaDB + Sentence Transformers | |
| - **Memory**: SQLite persistent storage | |
| - **Voice**: ElevenLabs TTS + Groq Whisper STT | |
| ### LLM Providers (Fallback Chain) | |
| 1. OpenAI (GPT-4) - Best quality | |
| 2. Groq (Llama-3.3-70B) - Fast, recommended | |
| 3. Hyperbolic (Llama-3.3-70B) - Alternative | |
| 4. Hugging Face (Mixtral-8x7B) - Free fallback | |
| ### Document Processing | |
| - **OCR**: EasyOCR, Tesseract | |
| - **PDF**: PyPDF2, pdf2image | |
| - **Forms**: python-docx, openpyxl | |
| - **Calendar**: icalendar | |
| --- | |
| ## π Agent Workflow | |
| ### Three-Phase Autonomous Loop | |
| **Phase 1: Planning** | |
| - Analyze user request | |
| - Query RAG for relevant context | |
| - Check memory for user preferences | |
| - Create step-by-step execution plan | |
| - Select appropriate MCP tools | |
| **Phase 2: Execution** | |
| - Execute tasks sequentially | |
| - Call MCP tools via JSONRPC | |
| - Handle errors with retries | |
| - Store intermediate results | |
| - Update progress in UI | |
| **Phase 3: Reflection** | |
| - Review execution results | |
| - Synthesize final answer | |
| - Generate voice response (if voice mode) | |
| - Update long-term memory | |
| - Provide downloadable outputs | |
| --- | |
| ## π Hackathon Submission | |
| **Event**: Hugging Face MCP Birthday Hackathon | |
| **Track**: Track 2 - MCP in Action | |
| **Features**: | |
| - β Real MCP tool servers (not mocked) | |
| - β Autonomous agent with planning | |
| - β RAG integration for context | |
| - β Voice control interface | |
| - β Production-ready deployment | |
| - β Comprehensive documentation | |
| --- | |
| ## π Resources | |
| - [GitHub Repository](#) - Complete source code | |
| - [Documentation](#) - Detailed setup guide | |
| - [Demo Video](#) - 5-minute walkthrough | |
| - [MCP Specification](https://modelcontextprotocol.io) | |
| --- | |
| ## π Privacy & Security | |
| - **Local Processing**: All data processed locally by default | |
| - **No Telemetry**: No usage tracking or data collection | |
| - **Secure Storage**: Files stored locally in encrypted directories | |
| - **API Keys**: Stored securely in environment variables | |
| --- | |
| ## π Acknowledgments | |
| Built with amazing open-source tools: | |
| - Gradio by Hugging Face | |
| - Model Context Protocol by Anthropic | |
| - ChromaDB for vector search | |
| - ElevenLabs for voice synthesis | |
| - Groq for fast inference | |
| Special thanks to the Hugging Face and Anthropic teams for making this hackathon possible! | |
| --- | |
| **Made with β€οΈ for the Hugging Face MCP Birthday Hackathon** | |
| """) | |
| # Footer | |
| gr.HTML(""" | |
| <div class="footer"> | |
| <p style="font-size: 1.1rem; font-weight: 600; margin-bottom: 0.5rem;"> | |
| π Hugging Face MCP Birthday Hackathon Submission | |
| </p> | |
| <p style="margin-bottom: 0.25rem;"> | |
| Track 2: MCP in Action | Built with Gradio 6 & Real MCP Tool Servers | |
| </p> | |
| <p style="font-size: 0.9rem; color: #a0aec0;"> | |
| Open Source β’ Production Ready β’ Fully Autonomous | |
| </p> | |
| </div> | |
| """) | |
| return app | |
| if __name__ == "__main__": | |
| print("=" * 60) | |
| print("π Starting LifeAdmin AI") | |
| print("=" * 60) | |
| # Setup LLM fallback chain | |
| print("\nβοΈ Setting up LLM providers...") | |
| try: | |
| setup_llm_fallback() | |
| print("β LLM providers configured successfully!") | |
| except Exception as e: | |
| print(f"β οΈ Warning: {e}") | |
| print(" Please set at least one API key (GROQ_API_KEY, OPENAI_API_KEY, etc.)") | |
| # Check for voice mode requirements | |
| print("\nπ€ Checking voice mode requirements...") | |
| if os.getenv('ELEVENLABS_API_KEY'): | |
| print("β ElevenLabs API key found (TTS enabled)") | |
| else: | |
| print("β οΈ ElevenLabs API key not found (voice output disabled)") | |
| if os.getenv('GROQ_API_KEY'): | |
| print("β Groq API key found (STT enabled)") | |
| else: | |
| print("β οΈ Groq API key not found (voice input disabled)") | |
| # Create and launch app | |
| print("\nπ¨ Creating Gradio interface...") | |
| app = create_app() | |
| print("\nβ LifeAdmin AI is ready!") | |
| print("=" * 60) | |
| print("\nπ± Access the app at: http://localhost:7860") | |
| print("\nπ‘ Tips:") | |
| print(" - Use Manual Mode for precise control") | |
| print(" - Use Voice Mode for autonomous execution") | |
| print(" - Upload files to enable document-based commands") | |
| print("\n" + "=" * 60 + "\n") | |
| # Launch the application | |
| app.launch( | |
| server_name="0.0.0.0", | |
| server_port=int(os.getenv("GRADIO_SERVER_PORT", 7860)), | |
| share=False, | |
| show_error=True, | |
| show_api=False | |
| ) |