Spaces:
Sleeping
Sleeping
| """ | |
| Deployment script for BuildTheFuture application | |
| Supports deployment to Fal.ai and other platforms | |
| """ | |
| import os | |
| import subprocess | |
| import sys | |
| from pathlib import Path | |
| def check_requirements(): | |
| """Check if all required dependencies are installed""" | |
| try: | |
| import gradio | |
| import google.generativeai | |
| import ultralytics | |
| import cv2 | |
| import PIL | |
| import numpy | |
| import requests | |
| print("β All required packages are installed") | |
| return True | |
| except ImportError as e: | |
| print(f"β Missing package: {e}") | |
| print("Please run: pip install -r requirements.txt") | |
| return False | |
| def check_env_vars(): | |
| """Check if required environment variables are set""" | |
| required_vars = ["GEMINI_API_KEY"] | |
| optional_vars = ["ELEVENLABS_API_KEY", "FAL_API_KEY"] | |
| missing_required = [] | |
| missing_optional = [] | |
| for var in required_vars: | |
| if not os.getenv(var): | |
| missing_required.append(var) | |
| for var in optional_vars: | |
| if not os.getenv(var): | |
| missing_optional.append(var) | |
| if missing_required: | |
| print(f"β Missing required environment variables: {', '.join(missing_required)}") | |
| print("Please set these in your .env file") | |
| return False | |
| if missing_optional: | |
| print(f"β οΈ Missing optional environment variables: {', '.join(missing_optional)}") | |
| print("These are optional but recommended for full functionality") | |
| print("β Environment variables configured") | |
| return True | |
| def deploy_local(): | |
| """Deploy locally""" | |
| print("π Starting local deployment...") | |
| try: | |
| subprocess.run([sys.executable, "app.py"], check=True) | |
| except subprocess.CalledProcessError as e: | |
| print(f"β Local deployment failed: {e}") | |
| return False | |
| except KeyboardInterrupt: | |
| print("\nβΉοΈ Deployment stopped by user") | |
| return True | |
| def deploy_fal(): | |
| """Deploy to Fal.ai""" | |
| print("π Deploying to Fal.ai...") | |
| try: | |
| # Check if fal-client is installed | |
| import fal_client | |
| print("β Fal.ai client is available") | |
| # Deploy the application | |
| result = subprocess.run(["fal", "app", "deploy"], | |
| capture_output=True, text=True, check=True) | |
| print("β Successfully deployed to Fal.ai") | |
| print(result.stdout) | |
| return True | |
| except ImportError: | |
| print("β fal-client not installed. Run: pip install fal-client") | |
| return False | |
| except subprocess.CalledProcessError as e: | |
| print(f"β Fal.ai deployment failed: {e}") | |
| print(e.stderr) | |
| return False | |
| def main(): | |
| """Main deployment function""" | |
| print("ποΈ BuildTheFuture Deployment Script") | |
| print("=" * 50) | |
| # Check requirements | |
| if not check_requirements(): | |
| return | |
| # Check environment variables | |
| if not check_env_vars(): | |
| return | |
| # Ask user for deployment target | |
| print("\nSelect deployment target:") | |
| print("1. Local development") | |
| print("2. Fal.ai production") | |
| print("3. Both") | |
| choice = input("\nEnter your choice (1-3): ").strip() | |
| if choice == "1": | |
| deploy_local() | |
| elif choice == "2": | |
| deploy_fal() | |
| elif choice == "3": | |
| print("Deploying to both targets...") | |
| deploy_fal() | |
| print("\n" + "="*50) | |
| deploy_local() | |
| else: | |
| print("β Invalid choice. Please run the script again.") | |
| if __name__ == "__main__": | |
| main() | |