Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Local setup script for Spend Analyzer MCP | |
| """ | |
| import os | |
| import sys | |
| import subprocess | |
| import logging | |
| def check_python_version(): | |
| """Check if Python version is compatible""" | |
| if sys.version_info < (3, 8): | |
| print("❌ Python 3.8 or higher is required") | |
| return False | |
| print(f"✅ Python {sys.version_info.major}.{sys.version_info.minor} detected") | |
| return True | |
| def install_dependencies(): | |
| """Install required dependencies""" | |
| print("📦 Installing dependencies...") | |
| try: | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) | |
| print("✅ Dependencies installed successfully") | |
| return True | |
| except subprocess.CalledProcessError as e: | |
| print(f"❌ Failed to install dependencies: {e}") | |
| return False | |
| def create_env_file(): | |
| """Create .env file template""" | |
| env_content = """# Spend Analyzer MCP Environment Variables | |
| # Copy this file to .env and fill in your actual values | |
| # Claude API Key (optional for local demo) | |
| ANTHROPIC_API_KEY=your_claude_api_key_here | |
| # Email Configuration (optional for local demo) | |
| EMAIL_USER=your_email@gmail.com | |
| EMAIL_PASS=your_app_password_here | |
| IMAP_SERVER=imap.gmail.com | |
| # Modal Configuration (optional) | |
| MODAL_TOKEN_ID=your_modal_token_id | |
| MODAL_TOKEN_SECRET=your_modal_token_secret | |
| """ | |
| if not os.path.exists('.env.template'): | |
| with open('.env.template', 'w') as f: | |
| f.write(env_content) | |
| print("✅ Created .env.template file") | |
| print("📝 Please copy .env.template to .env and fill in your API keys") | |
| else: | |
| print("✅ .env file already exists") | |
| def test_imports(): | |
| """Test if all required modules can be imported""" | |
| print("🧪 Testing imports...") | |
| required_modules = [ | |
| 'gradio', | |
| 'pandas', | |
| 'plotly', | |
| 'numpy' | |
| ] | |
| failed_imports = [] | |
| for module in required_modules: | |
| try: | |
| __import__(module) | |
| print(f" ✅ {module}") | |
| except ImportError: | |
| print(f" ❌ {module}") | |
| failed_imports.append(module) | |
| if failed_imports: | |
| print(f"\n❌ Failed to import: {', '.join(failed_imports)}") | |
| print("💡 Try running: pip install -r requirements.txt") | |
| return False | |
| print("✅ All required modules imported successfully") | |
| return True | |
| def create_demo_data(): | |
| """Create demo data for testing""" | |
| demo_data = { | |
| "transactions": [ | |
| { | |
| "date": "2024-01-15", | |
| "description": "STARBUCKS COFFEE", | |
| "amount": -4.50, | |
| "category": "Food & Dining" | |
| }, | |
| { | |
| "date": "2024-01-14", | |
| "description": "AMAZON PURCHASE", | |
| "amount": -29.99, | |
| "category": "Shopping" | |
| }, | |
| { | |
| "date": "2024-01-13", | |
| "description": "SALARY DEPOSIT", | |
| "amount": 3000.00, | |
| "category": "Income" | |
| } | |
| ] | |
| } | |
| import json | |
| with open('demo_data.json', 'w') as f: | |
| json.dump(demo_data, f, indent=2) | |
| print("✅ Created demo_data.json for testing") | |
| def main(): | |
| """Main setup function""" | |
| print("🚀 Setting up Spend Analyzer MCP locally...\n") | |
| # Check Python version | |
| if not check_python_version(): | |
| return False | |
| # Install dependencies | |
| if not install_dependencies(): | |
| return False | |
| # Test imports | |
| if not test_imports(): | |
| return False | |
| # Create environment file template | |
| create_env_file() | |
| # Create demo data | |
| create_demo_data() | |
| print("\n🎉 Local setup completed successfully!") | |
| print("\n📋 Next steps:") | |
| print("1. Copy .env.template to .env and add your API keys (optional for demo)") | |
| print("2. Run: python gradio_interface.py") | |
| print("3. Open http://localhost:7860 in your browser") | |
| print("\n💡 The app will work in demo mode without API keys") | |
| return True | |
| if __name__ == "__main__": | |
| success = main() | |
| sys.exit(0 if success else 1) | |