#!/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())