File size: 3,737 Bytes
d33f5e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python3
"""

MoneyPrinterTurbo - 简化版Streamlit应用

一键启动,无需复杂配置

"""

import os
import sys
import subprocess
from pathlib import Path

# 修复protobuf兼容性问题
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"

# 添加项目根目录到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
    
    # 启动Streamlit
    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()