File size: 3,691 Bytes
cdf446f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Hugging Face Space 部署检查脚本
检查所有必需的文件和配置是否正确
"""

import os
import sys
from pathlib import Path

def check_file_exists(filepath, required=True):
    """检查文件是否存在"""
    exists = os.path.exists(filepath)
    status = "✅" if exists else ("❌" if required else "⚠️")
    req_text = "必需" if required else "可选"
    print(f"{status} {filepath} ({req_text}): {'存在' if exists else '缺失'}")
    return exists

def check_file_content(filepath, required_content):
    """检查文件内容"""
    try:
        with open(filepath, 'r', encoding='utf-8') as f:
            content = f.read()
            for item in required_content:
                if item in content:
                    print(f"  ✅ 包含: {item}")
                else:
                    print(f"  ❌ 缺失: {item}")
                    return False
        return True
    except Exception as e:
        print(f"  ❌ 读取文件失败: {e}")
        return False

def main():
    print("="*60)
    print("Hugging Face Space 部署检查")
    print("="*60)
    print()
    
    # 检查必需文件
    print("📋 检查必需文件:")
    print("-"*60)
    
    files_ok = True
    files_ok &= check_file_exists("app.py", required=True)
    files_ok &= check_file_exists("requirements.txt", required=True)
    files_ok &= check_file_exists("packages.txt", required=True)
    files_ok &= check_file_exists("README.md", required=True)
    
    print()
    
    # 检查可选文件
    print("📋 检查可选文件:")
    print("-"*60)
    check_file_exists("config.py", required=False)
    check_file_exists(".gitignore", required=False)
    
    print()
    
    # 检查 README.md 配置
    print("📋 检查 README.md 配置:")
    print("-"*60)
    if os.path.exists("README.md"):
        readme_items = [
            "title:",
            "sdk: gradio",
            "app_file: app.py",
        ]
        check_file_content("README.md", readme_items)
    
    print()
    
    # 检查 requirements.txt
    print("📋 检查 requirements.txt:")
    print("-"*60)
    if os.path.exists("requirements.txt"):
        req_items = [
            "gradio",
            "torch",
            "transformers",
            "huggingface_hub",
        ]
        check_file_content("requirements.txt", req_items)
    
    print()
    
    # 检查 packages.txt
    print("📋 检查 packages.txt:")
    print("-"*60)
    if os.path.exists("packages.txt"):
        pkg_items = [
            "ffmpeg",
        ]
        check_file_content("packages.txt", pkg_items)
    
    print()
    
    # 检查 app.py
    print("📋 检查 app.py:")
    print("-"*60)
    if os.path.exists("app.py"):
        app_items = [
            "import gradio",
            "AutoModel.from_pretrained",
            "FunAudioLLM/CosyVoice-300M",
            "demo.launch()",
        ]
        check_file_content("app.py", app_items)
    
    print()
    print("="*60)
    
    if files_ok:
        print("✅ 所有必需文件检查通过!")
        print()
        print("📦 下一步:")
        print("1. 访问 https://huggingface.co/spaces")
        print("2. 创建新的 Space,选择 Gradio SDK")
        print("3. 上传以下文件:")
        print("   - app.py")
        print("   - requirements.txt")
        print("   - packages.txt")
        print("   - README.md")
        print("4. 等待构建完成(约5-10分钟)")
        print("5. 测试应用功能")
    else:
        print("❌ 检查失败!请修复上述问题后重试。")
        sys.exit(1)
    
    print("="*60)

if __name__ == "__main__":
    main()