Smart-Auto-Complete / install.py
Sandipan Haldar
adding submission
b309c22
#!/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())