File size: 2,748 Bytes
6d4ec85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""

Huggingface Spaces entry point for MoneyPrinterTurbo

This file replaces main.py for HF Spaces deployment

"""
import os
import sys
import subprocess
import time

# Add the root directory to Python path
root_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, root_dir)

def setup_environment():
    """Setup environment for Huggingface Spaces"""
    print("πŸ“ Creating storage directories...")
    # Create necessary directories
    os.makedirs(os.path.join(root_dir, "storage", "tasks"), exist_ok=True)
    os.makedirs(os.path.join(root_dir, "storage", "cache_videos"), exist_ok=True)
    os.makedirs(os.path.join(root_dir, "storage", "temp"), exist_ok=True)
    
    # Set environment variables for Huggingface Spaces
    os.environ["STREAMLIT_SERVER_PORT"] = "7860"
    os.environ["STREAMLIT_SERVER_ADDRESS"] = "0.0.0.0"
    os.environ["STREAMLIT_BROWSER_GATHER_USAGE_STATS"] = "false"
    os.environ["STREAMLIT_SERVER_ENABLE_CORS"] = "true"

def setup_api_keys_from_env():
    """Setup API keys from environment variables (minimal version)"""
    try:
        from app.config import config
        
        # Only load essential API keys for faster startup
        if os.getenv("MONEYPRINTER_API_KEY"):
            config.app["api_key"] = os.getenv("MONEYPRINTER_API_KEY")
            config.app["api_enabled"] = True
            print("βœ… API access configured")
        
        # Save minimal config
        config.save_config()
        
    except Exception as e:
        print(f"⚠️ Warning: {e}")
        print("πŸ’‘ Configure API keys in WebUI after startup")

def start_streamlit():
    """Start Streamlit app optimized for HF Spaces"""
    print("πŸš€ Starting MoneyPrinterTurbo WebUI...")
    
    # Explicitly specify port 7860 for HF Spaces
    streamlit_cmd = [
        sys.executable, "-m", "streamlit", "run", 
        os.path.join(root_dir, "webui", "Main.py"),
        "--server.port", "7860",
        "--server.address", "0.0.0.0",
        "--browser.gatherUsageStats", "false",
        "--server.enableCORS", "true",
        "--server.enableXsrfProtection", "false",
        "--server.enableWebsocketCompression", "false"
    ]
    
    print(f"🎯 Starting Streamlit on port 7860...")
    print(f"πŸ“ Command: {' '.join(streamlit_cmd)}")
    
    # Replace current process with Streamlit
    os.execvp(sys.executable, streamlit_cmd)

if __name__ == "__main__":
    print("πŸš€ MoneyPrinterTurbo - Huggingface Spaces")
    
    # Minimal setup for fast startup
    setup_environment()
    setup_api_keys_from_env()
    
    # Start Streamlit (this replaces the current process)
    start_streamlit()