File size: 4,207 Bytes
499796e |
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
#!/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 protected]
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)
|