File size: 3,675 Bytes
b309c22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Installation script for Smart Auto-Complete
"""

import os
import subprocess
import sys
import shutil

def run_command(command, description):
    """Run a shell command and handle errors"""
    print(f"πŸ“¦ {description}...")
    try:
        result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
        print(f"βœ… {description} completed successfully")
        return True
    except subprocess.CalledProcessError as e:
        print(f"❌ {description} failed: {e}")
        if e.stdout:
            print(f"STDOUT: {e.stdout}")
        if e.stderr:
            print(f"STDERR: {e.stderr}")
        return False

def check_python_version():
    """Check if Python version is compatible"""
    print("🐍 Checking Python version...")
    version = sys.version_info
    
    if version.major < 3 or (version.major == 3 and version.minor < 8):
        print(f"❌ Python 3.8+ required, found {version.major}.{version.minor}")
        return False
    
    print(f"βœ… Python {version.major}.{version.minor}.{version.micro} is compatible")
    return True

def install_dependencies():
    """Install Python dependencies"""
    print("πŸ“¦ Installing dependencies...")
    
    # Check if pip is available
    if not shutil.which('pip'):
        print("❌ pip not found. Please install pip first.")
        return False
    
    # Install requirements
    return run_command("pip install -r requirements.txt", "Installing Python packages")

def setup_environment():
    """Set up environment file"""
    print("βš™οΈ Setting up environment...")
    
    if not os.path.exists('.env'):
        if os.path.exists('.env.example'):
            shutil.copy('.env.example', '.env')
            print("βœ… Created .env file from .env.example")
            print("πŸ“ Please edit .env file and add your API keys")
        else:
            print("❌ .env.example not found")
            return False
    else:
        print("βœ… .env file already exists")
    
    return True

def run_tests():
    """Run setup tests"""
    print("πŸ§ͺ Running setup tests...")
    
    try:
        # Run the test script
        result = subprocess.run([sys.executable, 'test_setup.py'], 
                              capture_output=True, text=True, check=True)
        print("βœ… All tests passed!")
        return True
    except subprocess.CalledProcessError as e:
        print("❌ Tests failed:")
        print(e.stdout)
        print(e.stderr)
        return False

def main():
    """Main installation function"""
    print("πŸš€ Smart Auto-Complete Installation")
    print("=" * 50)
    
    # Change to script directory
    script_dir = os.path.dirname(os.path.abspath(__file__))
    os.chdir(script_dir)
    
    steps = [
        ("Checking Python version", check_python_version),
        ("Installing dependencies", install_dependencies),
        ("Setting up environment", setup_environment),
        ("Running tests", run_tests)
    ]
    
    for step_name, step_func in steps:
        print(f"\nπŸ“‹ Step: {step_name}")
        if not step_func():
            print(f"\n❌ Installation failed at: {step_name}")
            return 1
    
    print("\n" + "=" * 50)
    print("πŸŽ‰ Installation completed successfully!")
    print("\nπŸ“ Next steps:")
    print("1. Edit .env file and add your API keys:")
    print("   - OPENAI_API_KEY=your_openai_key_here")
    print("   - ANTHROPIC_API_KEY=your_anthropic_key_here")
    print("2. Run the application:")
    print("   python app.py")
    print("3. Open http://localhost:7860 in your browser")
    
    return 0

if __name__ == "__main__":
    sys.exit(main())