svjack commited on
Commit
44d3d88
·
verified ·
1 Parent(s): 99a90a8

Create genshin_impact_couple_app.py

Browse files
Files changed (1) hide show
  1. genshin_impact_couple_app.py +270 -0
genshin_impact_couple_app.py ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import glob
3
+ import time
4
+ import pathlib
5
+ import shlex
6
+ import subprocess
7
+ import gradio as gr
8
+ from huggingface_hub import snapshot_download
9
+ from datasets import load_from_disk
10
+ import random
11
+
12
+ # 下载数据集
13
+ repo_id = "svjack/3DitScene_cache"
14
+ folder_path = "Genshin-Impact-Couple-with-Tags-IID-Gender-Only-Two-Joy-Caption_Head10"
15
+ local_dir = snapshot_download(
16
+ repo_id=repo_id,
17
+ repo_type="dataset",
18
+ allow_patterns=f"{folder_path}/*",
19
+ cache_dir=os.getcwd(),
20
+ local_dir="."
21
+ )
22
+
23
+ # 加载数据集
24
+ dataset = load_from_disk(folder_path)
25
+
26
+ # 提取 image 和 joy-caption
27
+ examples = []
28
+ for example in dataset:
29
+ examples.append({
30
+ 'image': example['image'],
31
+ 'joy-caption': example['joy-caption']
32
+ })
33
+
34
+ # 定义可用的 gen_camerapath 和 render_camerapath 选项
35
+ gen_camerapath_options = ['lookaround', 'lookdown', 'rotate360']
36
+ render_camerapath_options = ['back_and_forth', 'llff', 'headbanging']
37
+
38
+ # 为每个例子随机分配 gen_camerapath 和 render_camerapath
39
+ examples_with_combinations = []
40
+ for example in examples:
41
+ gen_camerapath = random.choice(gen_camerapath_options)
42
+ render_camerapath = random.choice(render_camerapath_options)
43
+ examples_with_combinations.append({
44
+ 'image': example['image'],
45
+ 'joy-caption': example['joy-caption'],
46
+ 'gen_camerapath': gen_camerapath,
47
+ 'render_camerapath': render_camerapath
48
+ })
49
+
50
+ root = pathlib.Path(__file__).parent
51
+ example_root = os.path.join(root, 'examples')
52
+ ckpt_root = os.path.join(root, 'stablediffusion')
53
+
54
+ d = example_root
55
+ if len(glob.glob(os.path.join(d, '*.ply'))) < 8:
56
+ snapshot_download(repo_id="ironjr/LucidDreamerDemo", repo_type="model", local_dir=d)
57
+
58
+ d = os.path.join(ckpt_root, 'Blazing Drive V11m')
59
+ if not os.path.exists(d):
60
+ snapshot_download(repo_id="ironjr/BlazingDriveV11m", repo_type="model", local_dir=d)
61
+ d = os.path.join(ckpt_root, 'RealCartoon-Pixar V5')
62
+ if not os.path.exists(d):
63
+ snapshot_download(repo_id="ironjr/RealCartoon-PixarV5", repo_type="model", local_dir=d)
64
+ d = os.path.join(ckpt_root, 'Realistic Vision V5.1')
65
+ if not os.path.exists(d):
66
+ snapshot_download(repo_id="ironjr/RealisticVisionV5-1", repo_type="model", local_dir=d)
67
+ d = os.path.join(ckpt_root, 'SD1-5')
68
+
69
+ if not os.path.exists(d):
70
+ snapshot_download(repo_id="runwayml/stable-diffusion-inpainting", repo_type="model", local_dir=d)
71
+
72
+ try:
73
+ import simple_knn
74
+ except ModuleNotFoundError:
75
+ subprocess.run(shlex.split(f'pip install {root}/dist/simple_knn-0.0.0-cp39-cp39-linux_x86_64.whl'))
76
+ try:
77
+ import depth_diff_gaussian_rasterization_min
78
+ except ModuleNotFoundError:
79
+ subprocess.run(shlex.split(f'pip install {root}/dist/depth_diff_gaussian_rasterization_min-0.0.0-cp39-cp39-linux_x86_64.whl'))
80
+
81
+ from luciddreamer import LucidDreamer
82
+
83
+ css = """
84
+ #run-button {
85
+ background: coral;
86
+ color: white;
87
+ }
88
+ """
89
+
90
+ save_dir = "local_save"
91
+ os.makedirs(save_dir, exist_ok=True)
92
+
93
+ ld = LucidDreamer(save_dir=save_dir)
94
+
95
+ with gr.Blocks(css=css) as demo:
96
+
97
+ gr.HTML(
98
+ """
99
+ <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
100
+ <div>
101
+ <h1>LucidDreamer: Domain-free Generation of 3D Gaussian Splatting Scenes - Genshin Impact Couple</h1>
102
+ <h5 style="margin: 0;">If you like our project, please visit our Github, too! ✨✨✨ More features are waiting!</h5>
103
+ </br>
104
+ <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
105
+ <a href='https://arxiv.org/abs/2311.13384'>
106
+ <img src="https://img.shields.io/badge/Arxiv-2311.13384-red">
107
+ </a>
108
+ &nbsp;
109
+ <a href='https://luciddreamer-cvlab.github.io'>
110
+ <img src='https://img.shields.io/badge/Project-LucidDreamer-green' alt='Project Page'>
111
+ </a>
112
+ &nbsp;
113
+ <a href='https://github.com/luciddreamer-cvlab/LucidDreamer'>
114
+ <img src='https://img.shields.io/github/stars/luciddreamer-cvlab/LucidDreamer?label=Github&color=blue'>
115
+ </a>
116
+ &nbsp;
117
+ <a href='https://twitter.com/_ironjr_'>
118
+ <img src='https://img.shields.io/twitter/url?label=_ironjr_&url=https%3A%2F%2Ftwitter.com%2F_ironjr_'>
119
+ </a>
120
+ </div>
121
+ <div style="display: flex; justify-content: center; align-items: center; text-align: left; border: 1px solid lightgray; padding: 10px; margin-top: 20px; margin-left: 100px; margin-right: 100px; border-radius: 10px">
122
+ <p style="align-items: center;">
123
+ <a style="display:inline-block" target="_blank" href="https://huggingface.co/spaces/ironjr/LucidDreamer-mini"><img src="https://huggingface.co/datasets/huggingface/badges/raw/main/open-in-hf-spaces-sm.svg"></a>
124
+ <a class="duplicate-button" style="display:inline-block" target="_blank" href="https://huggingface.co/spaces/ironjr/LucidDreamer?duplicate=true"><img style="margin-top:0;margin-bottom:0" src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&amp;style=flat&amp;logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&amp;logoWidth=14" alt="Duplicate Space"></a>
125
+ </p>
126
+ <p style="margin-left: 15px">
127
+ <b>Attention</b>: In case of high traffic, you can alternatively use our backup server (first button: without custom SD support) or clone this repository to run on your own machine (second button). We gratefully welcome any type of your contributions!
128
+ </p>
129
+ </div>
130
+ </div>
131
+ </div>
132
+ """
133
+ )
134
+
135
+ with gr.Row():
136
+
137
+ result_gallery = gr.Video(label='RGB Video', show_label=True, autoplay=True, format='mp4')
138
+
139
+ result_depth = gr.Video(label='Depth Video', show_label=True, autoplay=True, format='mp4')
140
+
141
+ result_ply_file = gr.File(label='Gaussian splatting PLY', show_label=True)
142
+
143
+ with gr.Row():
144
+
145
+ input_image = gr.Image(
146
+ label='Image prompt',
147
+ sources='upload',
148
+ type='pil',
149
+ )
150
+
151
+ with gr.Column():
152
+ model_name = gr.Radio(
153
+ label='SD checkpoint',
154
+ choices=['SD1.5 (default)', 'Blazing Drive V11m', 'Realistic Vision V5.1', 'RealCartoon-Pixar V5',],
155
+ value='SD1.5 (default)'
156
+ )
157
+
158
+ prompt = gr.Textbox(
159
+ label='Text prompt',
160
+ value='A cozy livingroom',
161
+ )
162
+ n_prompt = gr.Textbox(
163
+ label='Negative prompt',
164
+ value='photo frame, frame, boarder, simple color, inconsistent, humans, people',
165
+ )
166
+ gen_camerapath = gr.Radio(
167
+ label='Camera trajectory for generation (STEP 1)',
168
+ choices=['lookaround', 'lookdown', 'rotate360'],
169
+ value='lookaround',
170
+ )
171
+
172
+ with gr.Row():
173
+ seed = gr.Slider(
174
+ label='Seed',
175
+ minimum=1,
176
+ maximum=2147483647,
177
+ step=1,
178
+ randomize=True,
179
+ )
180
+ diff_steps = gr.Slider(
181
+ label='SD inpainting steps',
182
+ minimum=1,
183
+ maximum=50,
184
+ step=1,
185
+ value=30,
186
+ )
187
+
188
+ render_camerapath = gr.Radio(
189
+ label='Camera trajectory for rendering (STEP 2)',
190
+ choices=['back_and_forth', 'llff', 'headbanging'],
191
+ value='llff',
192
+ )
193
+
194
+ with gr.Column():
195
+ run_button = gr.Button(value='Run! (it may take a while)', elem_id='run-button')
196
+
197
+ gr.HTML(
198
+ """
199
+ <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
200
+ <div>
201
+ <h3>...or you can run in two steps</h3>
202
+ <h5>(hint: press STEP 2 if you have already baked Gaussians in STEP 1).</h5>
203
+ </div>
204
+ </div>
205
+ """
206
+ )
207
+
208
+ with gr.Row():
209
+ gaussian_button = gr.Button(value='STEP 1: Generate Gaussians')
210
+ render_button = gr.Button(value='STEP 2: Render A Video')
211
+
212
+ gr.HTML(
213
+ """
214
+ <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
215
+ <div>
216
+ <h5>...or you can just watch a quick preload we have baked already.</h5>
217
+ </div>
218
+ </div>
219
+ """
220
+ )
221
+
222
+ example_name = gr.Radio(
223
+ label='Quick load',
224
+ choices=['DON\'T'],
225
+ value='DON\'T',
226
+ )
227
+
228
+ ips = [example_name, input_image, prompt, n_prompt, gen_camerapath, seed, diff_steps, render_camerapath, model_name]
229
+
230
+ run_button.click(fn=ld.run, inputs=ips[1:] + ips[:1], outputs=[result_ply_file, result_gallery, result_depth])
231
+ gaussian_button.click(fn=ld.create, inputs=ips[1:-2] + ips[-1:] + ips[:1], outputs=[result_ply_file])
232
+ render_button.click(fn=ld.render_video, inputs=ips[-2:-1] + ips[:1], outputs=[result_gallery, result_depth])
233
+
234
+ # 替换 examples
235
+ gr.Examples(
236
+ examples=[
237
+ [
238
+ 'DON\'T',
239
+ example['image'],
240
+ example['joy-caption'],
241
+ 'photo frame, frame, boarder, simple color, inconsistent, humans, people',
242
+ example['gen_camerapath'], # 随机分配的 gen_camerapath
243
+ 10, # seed
244
+ 25, # diff_steps
245
+ example['render_camerapath'], # 随机分配的 render_camerapath
246
+ 'RealCartoon-Pixar V5',
247
+ ] for example in examples_with_combinations
248
+ ],
249
+ inputs=ips,
250
+ outputs=[result_ply_file, result_gallery, result_depth],
251
+ fn=ld.run,
252
+ cache_examples=False,
253
+ )
254
+
255
+ gr.HTML(
256
+ """
257
+ <div style="display: flex; justify-content: center; align-items: center; text-align: left;">
258
+ </br>
259
+ <div>
260
+ <h5 style="margin: 0;">Acknowledgement and Disclaimer</h5>
261
+ </br>
262
+ <p>We deeply thank <a href="https://twitter.com/br_d">br_d</a>, <a href="https://ko-fi.com/7whitefire7">7whitefire7</a>, and <a href="https://huggingface.co/SG161222">SG161222</a> for their awesome Stable Diffusion models. We also appreciate <a href="https://twitter.com/ai_pictures21">ai_pictures21</a> and <a href="https://twitter.com/recatm">recatm</a> for the beautiful illustrations used in the examples. Please note that the authors of this work do not own the model checkpoints and the illustrations in this demo. LucidDreamer algorithm cannot be used for commercial purpose. Please contact the authors for permission requests.</p>
263
+ </div>
264
+ </div>
265
+ """
266
+ )
267
+
268
+
269
+ if __name__ == '__main__':
270
+ demo.launch(share=True)