|
|
|
"""
|
|
Huggingface Spaces entry point for MoneyPrinterTurbo
|
|
Stage 2: Streamlit Integration
|
|
"""
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import traceback
|
|
import time
|
|
|
|
|
|
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...")
|
|
|
|
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:
|
|
|
|
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()
|
|
load_env_variables()
|
|
|
|
|
|
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}")
|
|
|
|
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}")
|
|
|
|
|
|
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()
|
|
|
|
print("π Keeping process alive for debugging...")
|
|
while True:
|
|
print("β° Process is alive, waiting...")
|
|
time.sleep(30) |