#!/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(""" """, 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"] })