File size: 5,647 Bytes
150be64
 
1578acb
 
150be64
4ebe091
150be64
80fda88
1578acb
4ebe091
 
150be64
1578acb
 
 
 
 
 
 
 
5668917
1578acb
 
4ebe091
 
1578acb
 
 
 
 
 
 
 
 
 
 
4ebe091
 
1578acb
4ebe091
1578acb
4ebe091
 
 
 
 
 
1578acb
4ebe091
 
1578acb
 
 
4ebe091
 
 
1578acb
 
4ebe091
1578acb
 
4ebe091
1578acb
 
 
5668917
1578acb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5668917
1578acb
 
 
 
 
 
 
 
 
 
 
4ebe091
1578acb
 
 
80fda88
1578acb
 
 
 
 
 
 
 
 
 
733fb25
1578acb
 
 
 
4ebe091
1578acb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
733fb25
1578acb
 
 
 
 
4ebe091
1578acb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python3
"""

MoneyPrinterTurbo - Huggingface Spaces Edition

Optimized for FREE tier deployment

"""

import os
import sys
import streamlit as st
import toml
from pathlib import Path

# Add project root to Python path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

# Create necessary directories
os.makedirs("storage/tasks", exist_ok=True)
os.makedirs("storage/temp", exist_ok=True)
os.makedirs("storage/cache_videos", exist_ok=True)

def load_config():
    """Load configuration from environment variables"""
    config_path = "config.toml"
    
    # Default configuration
    config = {
        "app": {
            "max_concurrent_tasks": 1,
            "api_enabled": True,
            "log_level": "INFO"
        },
        "ui": {"hide_log": False, "language": "zh"},
        "azure": {},
        "siliconflow": {}
    }
    
    # Load environment variables
    env_vars = {
        "DEEPSEEK_API_KEY": ("app", "deepseek_api_key"),
        "MOONSHOT_API_KEY": ("app", "moonshot_api_key"), 
        "OPENAI_API_KEY": ("app", "openai_api_key"),
        "PEXELS_API_KEY": ("app", "pexels_api_keys"),
        "PIXABAY_API_KEY": ("app", "pixabay_api_keys"),
        "AZURE_SPEECH_KEY": ("azure", "speech_key"),
        "AZURE_SPEECH_REGION": ("azure", "speech_region"),
        "SILICONFLOW_API_KEY": ("siliconflow", "api_key"),
        "MONEYPRINTER_API_KEY": ("app", "api_key")
    }
    
    loaded_keys = []
    for env_key, (section, config_key) in env_vars.items():
        value = os.getenv(env_key)
        if value:
            if section not in config:
                config[section] = {}
            if config_key.endswith("_keys"):
                config[section][config_key] = [value]
            else:
                config[section][config_key] = value
            loaded_keys.append(env_key)
    
    # Save configuration
    with open(config_path, 'w', encoding='utf-8') as f:
        toml.dump(config, f)
    
    return config, loaded_keys

# Load configuration
config, loaded_env_vars = load_config()

# Set Streamlit page config
st.set_page_config(
    page_title="MoneyPrinterTurbo - HF Spaces",
    page_icon="🎬",
    layout="wide",
    initial_sidebar_state="expanded"
)

# Custom CSS
st.markdown("""

<style>

.main > div {

    padding-top: 2rem;

}

.stAlert {

    margin-top: 1rem;

}

</style>

""", unsafe_allow_html=True)

# Main UI
st.title("🎬 MoneyPrinterTurbo")
st.markdown("### AI视频生成工具 - Huggingface Spaces版")

# Status display
with st.container():
    col1, col2 = st.columns(2)
    
    with col1:
        st.success("✅ 应用已成功启动")
        st.info(f"📊 环境变量加载: {len(loaded_env_vars)} 个")
        
    with col2:
        st.warning("⚠️ 这是简化版界面")
        st.info("🔧 为FREE层级优化")

# Configuration status
st.subheader("📋 配置状态")
config_status = st.container()

with config_status:
    # Check API keys
    api_keys_status = []
    
    if config.get("app", {}).get("deepseek_api_key"):
        api_keys_status.append("✅ DeepSeek API")
    if config.get("app", {}).get("moonshot_api_key"):
        api_keys_status.append("✅ Moonshot API")
    if config.get("app", {}).get("openai_api_key"):
        api_keys_status.append("✅ OpenAI API")
    if config.get("app", {}).get("pexels_api_keys"):
        api_keys_status.append("✅ Pexels API")
    if config.get("azure", {}).get("speech_key"):
        api_keys_status.append("✅ Azure Speech")
    
    if api_keys_status:
        st.success("🔑 已配置的API密钥:")
        for status in api_keys_status:
            st.write(f"   {status}")
    else:
        st.error("❌ 未检测到API密钥配置")
        st.info("💡 请在Huggingface Spaces设置中添加环境变量")

# Instructions
st.subheader("🚀 使用说明")
st.markdown("""

1. **配置API密钥**: 在Huggingface Spaces的Settings中添加环境变量

2. **选择功能**: 使用下方的功能模块开始创建视频

3. **注意限制**: FREE层级有资源限制,建议生成较短的视频

""")

# Quick actions
st.subheader("⚡ 快速操作")

# Simple video generation form
with st.form("quick_video"):
    video_topic = st.text_input("视频主题", placeholder="例如: 介绍人工智能的发展历史")
    video_duration = st.slider("视频时长 (秒)", 30, 120, 60)
    
    col1, col2 = st.columns(2)
    with col1:
        video_style = st.selectbox("视频风格", ["科技", "生活", "教育", "娱乐"])
    with col2:
        video_language = st.selectbox("语言", ["中文", "英文"])
    
    submitted = st.form_submit_button("🎬 生成视频")
    
    if submitted:
        if not video_topic:
            st.error("请输入视频主题")
        elif not api_keys_status:
            st.error("请先配置API密钥")
        else:
            with st.spinner("正在生成视频..."):
                st.info("🔄 视频生成功能正在开发中")
                st.success("✅ 配置已保存,等待完整功能上线")

# Footer
st.markdown("---")
st.markdown("💡 **提示**: 完整版功能正在适配中,敬请期待!")

# Debug info (for development)
if st.checkbox("显示调试信息"):
    st.subheader("🔍 调试信息")
    st.json({
        "loaded_env_vars": loaded_env_vars,
        "config_sections": list(config.keys()),
        "storage_dirs": ["storage/tasks", "storage/temp", "storage/cache_videos"]
    })