|
|
|
|
|
"""
|
|
|
MoneyPrinterTurbo - 简化版Streamlit应用
|
|
|
一键启动,无需复杂配置
|
|
|
"""
|
|
|
|
|
|
import os
|
|
|
import sys
|
|
|
import subprocess
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
|
|
|
|
|
|
|
|
|
project_root = Path(__file__).parent
|
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
|
|
def check_dependencies():
|
|
|
"""检查基础依赖是否安装"""
|
|
|
required_packages = ['streamlit', 'toml', 'loguru']
|
|
|
missing_packages = []
|
|
|
|
|
|
for package in required_packages:
|
|
|
try:
|
|
|
__import__(package)
|
|
|
print(f"✅ {package} 已安装")
|
|
|
except ImportError:
|
|
|
missing_packages.append(package)
|
|
|
print(f"❌ {package} 缺失")
|
|
|
|
|
|
if missing_packages:
|
|
|
print(f"\n🔧 需要安装: {', '.join(missing_packages)}")
|
|
|
print("自动安装中...")
|
|
|
try:
|
|
|
subprocess.run([
|
|
|
sys.executable, "-m", "pip", "install",
|
|
|
*missing_packages, "protobuf==3.20.3"
|
|
|
], check=True, capture_output=True)
|
|
|
print("✅ 依赖安装完成")
|
|
|
return True
|
|
|
except subprocess.CalledProcessError:
|
|
|
print("❌ 自动安装失败,请手动运行:")
|
|
|
print(f"pip install {' '.join(missing_packages)} protobuf==3.20.3")
|
|
|
return False
|
|
|
return True
|
|
|
|
|
|
def setup_directories():
|
|
|
"""创建必要的目录"""
|
|
|
dirs = [
|
|
|
"storage/tasks",
|
|
|
"storage/temp",
|
|
|
"storage/cache_videos"
|
|
|
]
|
|
|
for dir_path in dirs:
|
|
|
os.makedirs(dir_path, exist_ok=True)
|
|
|
print(f"📁 创建目录: {dir_path}")
|
|
|
|
|
|
def find_streamlit_file():
|
|
|
"""查找可用的Streamlit文件"""
|
|
|
candidates = [
|
|
|
("webui/SimpleMain.py", "📱 简化版界面"),
|
|
|
("webui/Main.py", "🖥️ 完整版界面"),
|
|
|
("app.py", "☁️ HF Spaces版界面")
|
|
|
]
|
|
|
|
|
|
for file_path, description in candidates:
|
|
|
full_path = project_root / file_path
|
|
|
if full_path.exists():
|
|
|
print(f"找到界面文件: {description}")
|
|
|
return full_path
|
|
|
|
|
|
print("❌ 未找到任何界面文件")
|
|
|
return None
|
|
|
|
|
|
def main():
|
|
|
"""主启动函数"""
|
|
|
print("🚀 MoneyPrinterTurbo 简化启动器")
|
|
|
print("=" * 50)
|
|
|
|
|
|
|
|
|
print("📦 检查依赖...")
|
|
|
if not check_dependencies():
|
|
|
input("按回车键退出...")
|
|
|
return
|
|
|
|
|
|
|
|
|
print("\n📁 设置目录...")
|
|
|
setup_directories()
|
|
|
|
|
|
|
|
|
print("\n🔍 查找界面文件...")
|
|
|
target_file = find_streamlit_file()
|
|
|
if not target_file:
|
|
|
input("按回车键退出...")
|
|
|
return
|
|
|
|
|
|
|
|
|
print(f"\n🌐 启动Streamlit...")
|
|
|
print(f"📍 访问地址: http://localhost:8501")
|
|
|
print("=" * 50)
|
|
|
|
|
|
cmd = [
|
|
|
sys.executable, "-m", "streamlit", "run", str(target_file),
|
|
|
"--server.port=8501",
|
|
|
"--server.address=localhost",
|
|
|
"--browser.gatherUsageStats=false",
|
|
|
"--server.enableCORS=true",
|
|
|
"--theme.base=light"
|
|
|
]
|
|
|
|
|
|
try:
|
|
|
subprocess.run(cmd, check=True)
|
|
|
except KeyboardInterrupt:
|
|
|
print("\n👋 应用已停止")
|
|
|
except FileNotFoundError:
|
|
|
print("❌ Streamlit未安装,请运行: pip install streamlit")
|
|
|
except Exception as e:
|
|
|
print(f"❌ 启动失败: {e}")
|
|
|
print("💡 尝试手动运行: streamlit run webui/Main.py")
|
|
|
|
|
|
input("按回车键退出...")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
main() |