Spaces:
Running
on
Zero
Running
on
Zero
| #!/usr/bin/env python3 | |
| """ | |
| 打包DreamRenderer应用用于部署到Hugging Face Spaces | |
| """ | |
| import os | |
| import shutil | |
| import zipfile | |
| from datetime import datetime | |
| def create_deployment_package(): | |
| """创建部署包""" | |
| # 需要打包的文件 | |
| files_to_package = [ | |
| 'README.md', | |
| 'requirements.txt', | |
| 'app.py', | |
| 'dream_renderer.py', | |
| 'bbox_component.html' | |
| ] | |
| # 创建部署目录 | |
| deploy_dir = 'dreamrenderer_deploy' | |
| if os.path.exists(deploy_dir): | |
| shutil.rmtree(deploy_dir) | |
| os.makedirs(deploy_dir) | |
| print("📦 正在打包DreamRenderer应用...") | |
| # 复制文件 | |
| for file in files_to_package: | |
| if os.path.exists(file): | |
| shutil.copy2(file, deploy_dir) | |
| print(f"✅ 已复制: {file}") | |
| else: | |
| print(f"❌ 文件不存在: {file}") | |
| return False | |
| # 创建ZIP包 | |
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | |
| zip_filename = f'dreamrenderer_{timestamp}.zip' | |
| with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf: | |
| for file in files_to_package: | |
| if os.path.exists(os.path.join(deploy_dir, file)): | |
| zipf.write(os.path.join(deploy_dir, file), file) | |
| print(f"\n🎉 部署包创建成功!") | |
| print(f"📁 文件夹: {deploy_dir}/") | |
| print(f"📦 ZIP包: {zip_filename}") | |
| # 显示部署说明 | |
| print("\n" + "="*60) | |
| print("📋 部署说明:") | |
| print("="*60) | |
| print("1. 访问: https://huggingface.co/spaces") | |
| print("2. 点击 'Create new Space'") | |
| print("3. 配置:") | |
| print(" - Space name: dreamrenderer") | |
| print(" - SDK: Gradio") | |
| print(" - Hardware: ZeroGPU ⚠️") | |
| print("4. 上传以下文件(按顺序):") | |
| for i, file in enumerate(files_to_package, 1): | |
| print(f" {i}. {file}") | |
| print("5. 等待构建完成") | |
| print("="*60) | |
| return True | |
| def create_git_commands(): | |
| """生成git命令""" | |
| print("\n🔧 Git部署命令:") | |
| print("="*40) | |
| print("# 如果你选择使用Git方式部署,运行以下命令:") | |
| print("git clone https://huggingface.co/spaces/YOUR_USERNAME/dreamrenderer") | |
| print("cd dreamrenderer") | |
| print("") | |
| print("# 复制文件") | |
| current_path = os.getcwd() | |
| files = ['README.md', 'requirements.txt', 'app.py', 'dream_renderer.py', 'bbox_component.html'] | |
| for file in files: | |
| print(f"cp {current_path}/{file} .") | |
| print("") | |
| print("# 提交") | |
| print("git add .") | |
| print('git commit -m "Initial DreamRenderer implementation"') | |
| print("git push") | |
| print("="*40) | |
| if __name__ == "__main__": | |
| print("🚀 DreamRenderer 部署打包工具") | |
| print("="*50) | |
| if create_deployment_package(): | |
| create_git_commands() | |
| print("\n✨ 准备完毕!现在你可以部署到Hugging Face Spaces了!") | |
| else: | |
| print("\n❌ 打包失败,请检查文件完整性") |