File size: 3,966 Bytes
150be64
 
80fda88
 
150be64
 
80fda88
 
aa8d4d0
 
150be64
80fda88
 
 
150be64
80fda88
 
 
 
 
 
 
aa8d4d0
5668917
80fda88
 
 
 
 
 
 
 
 
 
 
 
 
 
5668917
150be64
80fda88
 
 
 
 
 
5668917
80fda88
 
 
 
 
 
 
150be64
80fda88
 
 
 
5668917
80fda88
 
 
5668917
80fda88
 
 
733fb25
 
 
 
 
 
 
 
 
 
 
 
 
 
aa8d4d0
733fb25
 
 
80fda88
 
 
 
 
 
 
150be64
80fda88
 
 
733fb25
 
 
 
 
 
aa8d4d0
733fb25
aa8d4d0
733fb25
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
#!/usr/bin/env python3
"""

Huggingface Spaces entry point for MoneyPrinterTurbo

Stage 2: Streamlit Integration

"""
import os
import sys
import subprocess
import traceback
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)
    print("βœ… Storage directories created successfully")

def load_env_variables():
    """Load environment variables into config"""
    print("πŸ”‘ Loading environment variables...")
    try:
        # Try to load environment variables into config
        env_vars = {
            'MONEYPRINTER_API_KEY': 'api_key',
            'DEEPSEEK_API_KEY': 'deepseek_api_key', 
            'MOONSHOT_API_KEY': 'moonshot_api_key',
            'OPENAI_API_KEY': 'openai_api_key',
            'PEXELS_API_KEY': 'pexels_api_keys',
            'PIXABAY_API_KEY': 'pixabay_api_keys',
            'AZURE_SPEECH_KEY': 'azure_speech_key',
            'AZURE_SPEECH_REGION': 'azure_speech_region'
        }
        
        loaded_count = 0
        for env_key, config_key in env_vars.items():
            value = os.getenv(env_key)
            if value:
                print(f"βœ… Loaded {env_key}")
                loaded_count += 1
        
        if loaded_count > 0:
            print(f"🎯 Successfully loaded {loaded_count} environment variables")
        else:
            print("πŸ’‘ No environment variables found - will use WebUI configuration")
            
    except Exception as e:
        print(f"⚠️ Warning loading environment variables: {e}")

def start_streamlit():
    """Start Streamlit app"""
    print("πŸš€ Starting MoneyPrinterTurbo Streamlit WebUI...")
    print("🎯 Stage 2: Basic Streamlit Integration")
    
    # Setup environment first
    setup_environment()
    load_env_variables()
    
    # Use SimpleMain.py for basic functionality
    streamlit_app = os.path.join(root_dir, "webui", "SimpleMain.py")
    
    if not os.path.exists(streamlit_app):
        print(f"❌ SimpleMain.py not found at: {streamlit_app}")
        # Fallback to creating a minimal inline app
        minimal_app = os.path.join(root_dir, "minimal_app.py")
        with open(minimal_app, 'w', encoding='utf-8') as f:
            f.write('''

import streamlit as st

st.set_page_config(page_title="MoneyPrinterTurbo", page_icon="🎬")

st.title("🎬 MoneyPrinterTurbo")

st.success("βœ… εΊ”η”¨ζˆεŠŸε―εŠ¨οΌ")

st.info("θΏ™ζ˜―δΈ€δΈͺζœ€ε°εŒ–η‰ˆζœ¬οΌŒη”¨δΊŽιͺŒθ― Streamlit ι›†ζˆγ€‚")

st.write("ε¦‚ζžœζ‚¨ηœ‹εˆ°θΏ™δΈͺ鑡青,说明 Stage 2 ιƒ¨η½²ζˆεŠŸοΌ")

''')
        streamlit_app = minimal_app
        print(f"βœ… Created fallback minimal app at: {minimal_app}")
    
    print(f"πŸ“„ Using Streamlit app: {streamlit_app}")
    
    # Start Streamlit using exec to replace current process
    os.execvp(sys.executable, [
        sys.executable, "-m", "streamlit", "run", 
        streamlit_app,
        "--server.port=7860",
        "--server.address=0.0.0.0",
        "--browser.gatherUsageStats=false"
    ])

if __name__ == "__main__":
    print("🎬 MoneyPrinterTurbo - Stage 2: Streamlit Integration")
    try:
        start_streamlit()
    except Exception as e:
        print(f"❌ Error starting application: {e}")
        traceback.print_exc()
        # Keep process alive for debugging
        print("πŸ”„ Keeping process alive for debugging...")
        while True:
            print("⏰ Process is alive, waiting...")
            time.sleep(30)