lionelgarnier commited on
Commit
9e3e77c
·
1 Parent(s): aabfbe0

remove multi image

Browse files
Files changed (1) hide show
  1. app.py +16 -96
app.py CHANGED
@@ -110,8 +110,6 @@ def get_seed(randomize_seed: bool, seed: int) -> int:
110
  @spaces.GPU
111
  def image_to_3d(
112
  image: Image.Image,
113
- multiimages: List[Tuple[Image.Image, str]],
114
- is_multiimage: bool,
115
  seed: int,
116
  ss_guidance_strength: float,
117
  ss_sampling_steps: int,
@@ -125,8 +123,6 @@ def image_to_3d(
125
 
126
  Args:
127
  image (Image.Image): The input image.
128
- multiimages (List[Tuple[Image.Image, str]]): The input images in multi-image mode.
129
- is_multiimage (bool): Whether is in multi-image mode.
130
  seed (int): The random seed.
131
  ss_guidance_strength (float): The guidance strength for sparse structure generation.
132
  ss_sampling_steps (int): The number of sampling steps for sparse structure generation.
@@ -139,37 +135,20 @@ def image_to_3d(
139
  str: The path to the video of the 3D model.
140
  """
141
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
142
- if not is_multiimage:
143
- outputs = pipeline.run(
144
- image,
145
- seed=seed,
146
- formats=["gaussian", "mesh"],
147
- preprocess_image=False,
148
- sparse_structure_sampler_params={
149
- "steps": ss_sampling_steps,
150
- "cfg_strength": ss_guidance_strength,
151
- },
152
- slat_sampler_params={
153
- "steps": slat_sampling_steps,
154
- "cfg_strength": slat_guidance_strength,
155
- },
156
- )
157
- else:
158
- outputs = pipeline.run_multi_image(
159
- [image[0] for image in multiimages],
160
- seed=seed,
161
- formats=["gaussian", "mesh"],
162
- preprocess_image=False,
163
- sparse_structure_sampler_params={
164
- "steps": ss_sampling_steps,
165
- "cfg_strength": ss_guidance_strength,
166
- },
167
- slat_sampler_params={
168
- "steps": slat_sampling_steps,
169
- "cfg_strength": slat_guidance_strength,
170
- },
171
- mode=multiimage_algo,
172
- )
173
  video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
174
  video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
175
  video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
@@ -226,20 +205,6 @@ def extract_gaussian(state: dict, req: gr.Request) -> Tuple[str, str]:
226
  return gaussian_path, gaussian_path
227
 
228
 
229
- def prepare_multi_example() -> List[Image.Image]:
230
- multi_case = list(set([i.split('_')[0] for i in os.listdir("assets/example_multi_image")]))
231
- images = []
232
- for case in multi_case:
233
- _images = []
234
- for i in range(1, 4):
235
- img = Image.open(f'assets/example_multi_image/{case}_{i}.png')
236
- W, H = img.size
237
- img = img.resize((int(W / H * 512), 512))
238
- _images.append(np.array(img))
239
- images.append(Image.fromarray(np.concatenate(_images, axis=1)))
240
- return images
241
-
242
-
243
  def split_image(image: Image.Image) -> List[Image.Image]:
244
  """
245
  Split an image into multiple views.
@@ -266,16 +231,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
266
 
267
  with gr.Row():
268
  with gr.Column():
269
- with gr.Tabs() as input_tabs:
270
- with gr.Tab(label="Single Image", id=0) as single_image_input_tab:
271
- image_prompt = gr.Image(label="Image Prompt", format="png", image_mode="RGBA", type="pil", height=300)
272
- with gr.Tab(label="Multiple Images", id=1) as multiimage_input_tab:
273
- multiimage_prompt = gr.Gallery(label="Image Prompt", format="png", type="pil", height=300, columns=3)
274
- gr.Markdown("""
275
- Input different views of the object in separate images.
276
-
277
- *NOTE: this is an experimental algorithm without training a specialized model. It may not produce the best results for all images, especially those having different poses or inconsistent details.*
278
- """)
279
 
280
  with gr.Accordion(label="Generation Settings", open=False):
281
  seed = gr.Slider(0, MAX_SEED, label="Seed", value=0, step=1)
@@ -311,55 +267,19 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
311
  download_glb = gr.DownloadButton(label="Download GLB", interactive=False)
312
  download_gs = gr.DownloadButton(label="Download Gaussian", interactive=False)
313
 
314
- is_multiimage = gr.State(False)
315
  output_buf = gr.State()
316
 
317
- # Example images at the bottom of the page
318
- with gr.Row() as single_image_example:
319
- examples = gr.Examples(
320
- examples=[
321
- f'assets/example_image/{image}'
322
- for image in os.listdir("assets/example_image")
323
- ],
324
- inputs=[image_prompt],
325
- fn=preprocess_image,
326
- outputs=[image_prompt],
327
- run_on_click=True,
328
- examples_per_page=64,
329
- )
330
- with gr.Row(visible=False) as multiimage_example:
331
- examples_multi = gr.Examples(
332
- examples=prepare_multi_example(),
333
- inputs=[image_prompt],
334
- fn=split_image,
335
- outputs=[multiimage_prompt],
336
- run_on_click=True,
337
- examples_per_page=8,
338
- )
339
 
340
  # Handlers
341
  demo.load(start_session)
342
  demo.unload(end_session)
343
 
344
- single_image_input_tab.select(
345
- lambda: tuple([False, gr.Row.update(visible=True), gr.Row.update(visible=False)]),
346
- outputs=[is_multiimage, single_image_example, multiimage_example]
347
- )
348
- multiimage_input_tab.select(
349
- lambda: tuple([True, gr.Row.update(visible=False), gr.Row.update(visible=True)]),
350
- outputs=[is_multiimage, single_image_example, multiimage_example]
351
- )
352
 
353
  image_prompt.upload(
354
  preprocess_image,
355
  inputs=[image_prompt],
356
  outputs=[image_prompt],
357
  )
358
- multiimage_prompt.upload(
359
- preprocess_images,
360
- inputs=[multiimage_prompt],
361
- outputs=[multiimage_prompt],
362
- )
363
 
364
  generate_btn.click(
365
  get_seed,
@@ -367,7 +287,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
367
  outputs=[seed],
368
  ).then(
369
  image_to_3d,
370
- inputs=[image_prompt, multiimage_prompt, is_multiimage, seed, ss_guidance_strength, ss_sampling_steps, slat_guidance_strength, slat_sampling_steps, multiimage_algo],
371
  outputs=[output_buf, video_output],
372
  ).then(
373
  lambda: tuple([gr.Button(interactive=True), gr.Button(interactive=True)]),
 
110
  @spaces.GPU
111
  def image_to_3d(
112
  image: Image.Image,
 
 
113
  seed: int,
114
  ss_guidance_strength: float,
115
  ss_sampling_steps: int,
 
123
 
124
  Args:
125
  image (Image.Image): The input image.
 
 
126
  seed (int): The random seed.
127
  ss_guidance_strength (float): The guidance strength for sparse structure generation.
128
  ss_sampling_steps (int): The number of sampling steps for sparse structure generation.
 
135
  str: The path to the video of the 3D model.
136
  """
137
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
138
+ outputs = pipeline.run(
139
+ image,
140
+ seed=seed,
141
+ formats=["gaussian", "mesh"],
142
+ preprocess_image=False,
143
+ sparse_structure_sampler_params={
144
+ "steps": ss_sampling_steps,
145
+ "cfg_strength": ss_guidance_strength,
146
+ },
147
+ slat_sampler_params={
148
+ "steps": slat_sampling_steps,
149
+ "cfg_strength": slat_guidance_strength,
150
+ },
151
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
153
  video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
154
  video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
 
205
  return gaussian_path, gaussian_path
206
 
207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  def split_image(image: Image.Image) -> List[Image.Image]:
209
  """
210
  Split an image into multiple views.
 
231
 
232
  with gr.Row():
233
  with gr.Column():
234
+ image_prompt = gr.Image(label="Image Prompt", format="png", image_mode="RGBA", type="pil", height=300)
 
 
 
 
 
 
 
 
 
235
 
236
  with gr.Accordion(label="Generation Settings", open=False):
237
  seed = gr.Slider(0, MAX_SEED, label="Seed", value=0, step=1)
 
267
  download_glb = gr.DownloadButton(label="Download GLB", interactive=False)
268
  download_gs = gr.DownloadButton(label="Download Gaussian", interactive=False)
269
 
 
270
  output_buf = gr.State()
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
  # Handlers
274
  demo.load(start_session)
275
  demo.unload(end_session)
276
 
 
 
 
 
 
 
 
 
277
 
278
  image_prompt.upload(
279
  preprocess_image,
280
  inputs=[image_prompt],
281
  outputs=[image_prompt],
282
  )
 
 
 
 
 
283
 
284
  generate_btn.click(
285
  get_seed,
 
287
  outputs=[seed],
288
  ).then(
289
  image_to_3d,
290
+ inputs=[image_prompt, seed, ss_guidance_strength, ss_sampling_steps, slat_guidance_strength, slat_sampling_steps, multiimage_algo],
291
  outputs=[output_buf, video_output],
292
  ).then(
293
  lambda: tuple([gr.Button(interactive=True), gr.Button(interactive=True)]),