File size: 3,719 Bytes
8b8c9d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""

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()