Spaces:
Sleeping
Sleeping
| """ | |
| Setup script for BuildTheFuture application | |
| Handles installation and initial configuration | |
| """ | |
| import os | |
| import sys | |
| import subprocess | |
| import shutil | |
| from pathlib import Path | |
| def check_python_version(): | |
| """Check if Python version is compatible""" | |
| if sys.version_info < (3, 8): | |
| print("β Python 3.8 or higher is required") | |
| print(f"Current version: {sys.version}") | |
| return False | |
| print(f"β Python version: {sys.version.split()[0]}") | |
| 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 setup_environment(): | |
| """Set up environment file""" | |
| env_file = Path(".env") | |
| env_example = Path("env_example.txt") | |
| if env_file.exists(): | |
| print("β .env file already exists") | |
| return True | |
| if env_example.exists(): | |
| shutil.copy(env_example, env_file) | |
| print("β Created .env file from template") | |
| print("β οΈ Please edit .env file and add your API keys") | |
| return True | |
| else: | |
| print("β env_example.txt not found") | |
| return False | |
| def create_directories(): | |
| """Create necessary directories""" | |
| directories = ["samples", "outputs", "logs"] | |
| for directory in directories: | |
| Path(directory).mkdir(exist_ok=True) | |
| print(f"β Created directory: {directory}") | |
| def run_tests(): | |
| """Run basic tests""" | |
| print("π§ͺ Running tests...") | |
| try: | |
| result = subprocess.run([sys.executable, "test_app.py"], | |
| capture_output=True, text=True) | |
| if result.returncode == 0: | |
| print("β All tests passed") | |
| return True | |
| else: | |
| print("β οΈ Some tests failed:") | |
| print(result.stdout) | |
| print(result.stderr) | |
| return False | |
| except Exception as e: | |
| print(f"β Test execution failed: {e}") | |
| return False | |
| def main(): | |
| """Main setup function""" | |
| print("ποΈ BuildTheFuture Setup") | |
| print("=" * 50) | |
| steps = [ | |
| ("Checking Python version", check_python_version), | |
| ("Installing dependencies", install_dependencies), | |
| ("Setting up environment", setup_environment), | |
| ("Creating directories", create_directories), | |
| ("Running tests", run_tests), | |
| ] | |
| for step_name, step_func in steps: | |
| print(f"\n{step_name}...") | |
| if not step_func(): | |
| print(f"β Setup failed at: {step_name}") | |
| return False | |
| print("\n" + "=" * 50) | |
| print("π Setup completed successfully!") | |
| print("\nNext steps:") | |
| print("1. Edit .env file and add your API keys:") | |
| print(" - GEMINI_API_KEY (required)") | |
| print(" - ELEVENLABS_API_KEY (optional)") | |
| print("2. Run the application:") | |
| print(" python app.py") | |
| print("3. Or create sample images first:") | |
| print(" python demo.py") | |
| return True | |
| if __name__ == "__main__": | |
| success = main() | |
| sys.exit(0 if success else 1) | |