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