|
|
|
|
|
""" |
|
|
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() |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
print("📋 检查 packages.txt:") |
|
|
print("-"*60) |
|
|
if os.path.exists("packages.txt"): |
|
|
pkg_items = [ |
|
|
"ffmpeg", |
|
|
] |
|
|
check_file_content("packages.txt", pkg_items) |
|
|
|
|
|
print() |
|
|
|
|
|
|
|
|
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() |
|
|
|