Spaces:
Runtime error
Runtime error
#!/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() |