oscnet commited on
Commit
81a2e17
·
1 Parent(s): 9984a7d

Deploy Zero123++

Browse files
Files changed (4) hide show
  1. .gitignore +16 -0
  2. README.md +55 -5
  3. app.py +180 -0
  4. requirements.txt +6 -0
.gitignore ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.so
5
+ .Python
6
+ *.egg-info/
7
+ dist/
8
+ build/
9
+ *.log
10
+ .env
11
+ .venv
12
+ venv/
13
+ *.weights
14
+ *.pt
15
+ *.pth
16
+ .DS_Store
README.md CHANGED
@@ -1,12 +1,62 @@
1
  ---
2
- title: Zero123
3
- emoji: 🏃
4
- colorFrom: pink
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 5.49.1
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Zero123++ Multi-view Generator
3
+ emoji: 🎨
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
  sdk_version: 5.49.1
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
  ---
12
 
13
+ # Zero123++ Multi-view Generator
14
+
15
+ 将单张图片转换为 6 个不同角度的一致性多视图图像。
16
+
17
+ ## 功能特点
18
+
19
+ - 📷 单图生成多视图
20
+ - 🎯 6 个固定角度视图
21
+ - 🚀 基于 Zero123++ v1.1 模型
22
+ - ✨ 简洁的 Gradio 界面
23
+
24
+ ## 使用方法
25
+
26
+ 1. 上传一张图片(建议正方形,>= 320x320)
27
+ 2. 点击"生成多视图"按钮
28
+ 3. 等待 30-60 秒
29
+ 4. 下载生成的多视图图像
30
+
31
+ ## 输出说明
32
+
33
+ 生成的图像包含 6 个视图,排列为 2 行 3 列:
34
+
35
+ **视角参数:**
36
+ - 方位角: 30°, 90°, 150°, 210°, 270°, 330°
37
+ - 仰角: 30°, -20°, 30°, -20°, 30°, -20°
38
+
39
+ ## 技术细节
40
+
41
+ - 模型: [sudo-ai/zero123plus-v1.1](https://huggingface.co/sudo-ai/zero123plus-v1.1)
42
+ - 框架: Diffusers + Gradio
43
+ - 硬件: 需要 GPU (推荐至少 T4 或更高)
44
+
45
+ ## 引用
46
+
47
+ 如果使用了这个模型,请引用:
48
+
49
+ ```bibtex
50
+ @misc{shi2023zero123plus,
51
+ title={Zero123++: a Single Image to Consistent Multi-view Diffusion Base Model},
52
+ author={Ruoxi Shi and Hansheng Chen and Zhuoyang Zhang and Minghua Liu and Chao Xu and Xinyue Wei and Linghao Chen and Chong Zeng and Hao Su},
53
+ year={2023},
54
+ eprint={2310.15110},
55
+ archivePrefix={arXiv},
56
+ primaryClass={cs.CV}
57
+ }
58
+ ```
59
+
60
+ ## 许可证
61
+
62
+ MIT License
app.py ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Zero123++ Gradio Demo
4
+ 用于 Hugging Face Spaces 部署
5
+ """
6
+
7
+ import gradio as gr
8
+ import torch
9
+ from PIL import Image
10
+ from diffusers import DiffusionPipeline, EulerAncestralDiscreteScheduler
11
+ import os
12
+
13
+ # 全局变量存储 pipeline
14
+ pipeline = None
15
+
16
+ def load_model():
17
+ """加载模型"""
18
+ global pipeline
19
+
20
+ if pipeline is not None:
21
+ return
22
+
23
+ print("正在加载模型...")
24
+
25
+ # 检查 CUDA 可用性
26
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
27
+ dtype = torch.float16 if torch.cuda.is_available() else torch.float32
28
+
29
+ # 加载 pipeline
30
+ pipeline = DiffusionPipeline.from_pretrained(
31
+ "sudo-ai/zero123plus-v1.1",
32
+ custom_pipeline="sudo-ai/zero123plus-pipeline",
33
+ torch_dtype=dtype
34
+ )
35
+
36
+ # 设置调度器
37
+ pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(
38
+ pipeline.scheduler.config,
39
+ timestep_spacing='trailing'
40
+ )
41
+
42
+ pipeline.to(device)
43
+ print(f"✓ 模型加载完成 (设备: {device})")
44
+
45
+ def process_image(input_image, remove_bg=False):
46
+ """
47
+ 处理输入图像,生成多视图
48
+
49
+ 输入:
50
+ input_image: PIL Image
51
+ remove_bg: 是否移除背景 (暂未实现)
52
+
53
+ 输出:
54
+ result_image: PIL Image (多视图合成图)
55
+ """
56
+ if input_image is None:
57
+ return None
58
+
59
+ # 确保模型已加载
60
+ load_model()
61
+
62
+ try:
63
+ # 预处理图像 - 转为正方形
64
+ img = input_image
65
+
66
+ # 如果不是正方形,裁剪为正方形
67
+ if img.size[0] != img.size[1]:
68
+ size = min(img.size)
69
+ img = img.crop((
70
+ (img.size[0] - size) // 2,
71
+ (img.size[1] - size) // 2,
72
+ (img.size[0] + size) // 2,
73
+ (img.size[1] + size) // 2
74
+ ))
75
+
76
+ # 调整到推荐尺寸
77
+ target_size = 320
78
+ if img.size[0] != target_size:
79
+ img = img.resize((target_size, target_size), Image.LANCZOS)
80
+
81
+ # 运行推理
82
+ print("正在生成多视图...")
83
+ result = pipeline(img).images[0]
84
+
85
+ return result
86
+
87
+ except Exception as e:
88
+ print(f"错误: {e}")
89
+ raise gr.Error(f"处理失败: {str(e)}")
90
+
91
+ # 创建 Gradio 界面
92
+ def create_demo():
93
+ with gr.Blocks(title="Zero123++ Demo") as demo:
94
+ gr.Markdown("""
95
+ # Zero123++ 多视图生成
96
+
97
+ 将单张图片转换为 6 个不同角度的视图
98
+
99
+ **输入要求:**
100
+ - 建议使用正方形图片
101
+ - 推荐分辨率 >= 320x320
102
+ - 脚本会自动裁剪和调整非正方形图片
103
+
104
+ **输出说明:**
105
+ - 生成 6 个视图 (2行 x 3列)
106
+ - 方位角: 30°, 90°, 150°, 210°, 270°, 330°
107
+ - 仰角: 30°, -20°, 30°, -20°, 30°, -20°
108
+ """)
109
+
110
+ with gr.Row():
111
+ with gr.Column():
112
+ input_image = gr.Image(
113
+ label="输入图片",
114
+ type="pil",
115
+ height=400
116
+ )
117
+
118
+ # remove_bg = gr.Checkbox(
119
+ # label="移除背景 (实验性)",
120
+ # value=False
121
+ # )
122
+
123
+ generate_btn = gr.Button("生成多视图", variant="primary")
124
+
125
+ with gr.Column():
126
+ output_image = gr.Image(
127
+ label="多视图输出",
128
+ type="pil",
129
+ height=400
130
+ )
131
+
132
+ gr.Examples(
133
+ examples=[
134
+ ["examples/example1.png"],
135
+ ["examples/example2.png"],
136
+ ],
137
+ inputs=input_image,
138
+ label="示例图片"
139
+ )
140
+
141
+ gr.Markdown("""
142
+ ### 技术说明
143
+ - 模型: [sudo-ai/zero123plus-v1.1](https://huggingface.co/sudo-ai/zero123plus-v1.1)
144
+ - 首次运行需要加载模型,可能需要 20-30 秒
145
+ - 生成时间约 30-60 秒 (取决于硬件)
146
+
147
+ ### 引用
148
+ ```bibtex
149
+ @misc{shi2023zero123plus,
150
+ title={Zero123++: a Single Image to Consistent Multi-view Diffusion Base Model},
151
+ author={Ruoxi Shi and Hansheng Chen and Zhuoyang Zhang and Minghua Liu and Chao Xu and Xinyue Wei and Linghao Chen and Chong Zeng and Hao Su},
152
+ year={2023},
153
+ eprint={2310.15110},
154
+ archivePrefix={arXiv},
155
+ primaryClass={cs.CV}
156
+ }
157
+ ```
158
+ """)
159
+
160
+ # 绑定事件
161
+ generate_btn.click(
162
+ fn=process_image,
163
+ inputs=[input_image],
164
+ outputs=output_image
165
+ )
166
+
167
+ return demo
168
+
169
+ if __name__ == "__main__":
170
+ # 预加载模型
171
+ load_model()
172
+
173
+ # 启动 demo
174
+ demo = create_demo()
175
+ demo.queue()
176
+ demo.launch(
177
+ server_name="0.0.0.0",
178
+ server_port=7860,
179
+ share=False
180
+ )
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch>=2.0.0
2
+ diffusers>=0.20.2
3
+ transformers>=4.30.0
4
+ accelerate>=0.20.0
5
+ gradio>=4.0.0
6
+ pillow>=10.0.0