Longxiang-ai commited on
Commit
2935b6d
·
1 Parent(s): 8a40da0

新增部署打包工具,支持将DreamRenderer应用打包并生成Git部署命令

Browse files
Files changed (1) hide show
  1. package_for_deploy.py +99 -0
package_for_deploy.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ 打包DreamRenderer应用用于部署到Hugging Face Spaces
4
+ """
5
+
6
+ import os
7
+ import shutil
8
+ import zipfile
9
+ from datetime import datetime
10
+
11
+ def create_deployment_package():
12
+ """创建部署包"""
13
+
14
+ # 需要打包的文件
15
+ files_to_package = [
16
+ 'README.md',
17
+ 'requirements.txt',
18
+ 'app.py',
19
+ 'dream_renderer.py',
20
+ 'bbox_component.html'
21
+ ]
22
+
23
+ # 创建部署目录
24
+ deploy_dir = 'dreamrenderer_deploy'
25
+ if os.path.exists(deploy_dir):
26
+ shutil.rmtree(deploy_dir)
27
+ os.makedirs(deploy_dir)
28
+
29
+ print("📦 正在打包DreamRenderer应用...")
30
+
31
+ # 复制文件
32
+ for file in files_to_package:
33
+ if os.path.exists(file):
34
+ shutil.copy2(file, deploy_dir)
35
+ print(f"✅ 已复制: {file}")
36
+ else:
37
+ print(f"❌ 文件不存在: {file}")
38
+ return False
39
+
40
+ # 创建ZIP包
41
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
42
+ zip_filename = f'dreamrenderer_{timestamp}.zip'
43
+
44
+ with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
45
+ for file in files_to_package:
46
+ if os.path.exists(os.path.join(deploy_dir, file)):
47
+ zipf.write(os.path.join(deploy_dir, file), file)
48
+
49
+ print(f"\n🎉 部署包创建成功!")
50
+ print(f"📁 文件夹: {deploy_dir}/")
51
+ print(f"📦 ZIP包: {zip_filename}")
52
+
53
+ # 显示部署说明
54
+ print("\n" + "="*60)
55
+ print("📋 部署说明:")
56
+ print("="*60)
57
+ print("1. 访问: https://huggingface.co/spaces")
58
+ print("2. 点击 'Create new Space'")
59
+ print("3. 配置:")
60
+ print(" - Space name: dreamrenderer")
61
+ print(" - SDK: Gradio")
62
+ print(" - Hardware: ZeroGPU ⚠️")
63
+ print("4. 上传以下文件(按顺序):")
64
+ for i, file in enumerate(files_to_package, 1):
65
+ print(f" {i}. {file}")
66
+ print("5. 等待构建完成")
67
+ print("="*60)
68
+
69
+ return True
70
+
71
+ def create_git_commands():
72
+ """生成git命令"""
73
+ print("\n🔧 Git部署命令:")
74
+ print("="*40)
75
+ print("# 如果你选择使用Git方式部署,运行以下命令:")
76
+ print("git clone https://huggingface.co/spaces/YOUR_USERNAME/dreamrenderer")
77
+ print("cd dreamrenderer")
78
+ print("")
79
+ print("# 复制文件")
80
+ current_path = os.getcwd()
81
+ files = ['README.md', 'requirements.txt', 'app.py', 'dream_renderer.py', 'bbox_component.html']
82
+ for file in files:
83
+ print(f"cp {current_path}/{file} .")
84
+ print("")
85
+ print("# 提交")
86
+ print("git add .")
87
+ print('git commit -m "Initial DreamRenderer implementation"')
88
+ print("git push")
89
+ print("="*40)
90
+
91
+ if __name__ == "__main__":
92
+ print("🚀 DreamRenderer 部署打包工具")
93
+ print("="*50)
94
+
95
+ if create_deployment_package():
96
+ create_git_commands()
97
+ print("\n✨ 准备完毕!现在你可以部署到Hugging Face Spaces了!")
98
+ else:
99
+ print("\n❌ 打包失败,请检查文件完整性")