opsiclear-admin commited on
Commit
7814973
·
verified ·
1 Parent(s): 4ebb70a

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +9 -31
app.py CHANGED
@@ -385,15 +385,6 @@ def preprocess_image(input: Image.Image) -> Image.Image:
385
  return output
386
 
387
 
388
- def preprocess_images(images):
389
- """
390
- Preprocess a list of input images for multi-image conditioning.
391
- """
392
- images = [image[0] for image in images]
393
- processed_images = [preprocess_image(img) for img in images]
394
- return processed_images
395
-
396
-
397
  def pack_state(latents: Tuple[SparseTensor, SparseTensor, int]) -> dict:
398
  shape_slat, tex_slat, res = latents
399
  return {
@@ -487,18 +478,9 @@ def split_image(image: Image.Image) -> List[Image.Image]:
487
  return [preprocess_image(image) for image in images]
488
 
489
 
490
- def preprocess_for_generate(multiimages):
491
- """Preprocess images before GPU generation. No GPU needed — background
492
- removal is a network call to the BRIA RMBG Space."""
493
- if not multiimages:
494
- raise gr.Error("Please upload images or select an example first.")
495
- images = [image[0] for image in multiimages]
496
- return [preprocess_image(img) for img in images]
497
-
498
-
499
  @spaces.GPU(duration=120)
500
  def image_to_3d(
501
- processed_images,
502
  seed,
503
  resolution,
504
  ss_guidance_strength,
@@ -518,6 +500,13 @@ def image_to_3d(
518
  req: gr.Request,
519
  progress=gr.Progress(track_tqdm=True),
520
  ):
 
 
 
 
 
 
 
521
  # --- Sampling ---
522
  outputs, latents = pipeline.run_multi_image(
523
  processed_images,
@@ -750,7 +739,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="orange", neutral_hue="slate"),
750
  )
751
 
752
  output_buf = gr.State()
753
- processed_buf = gr.State()
754
  selected_img_idx = gr.State(value=None)
755
 
756
 
@@ -776,24 +764,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="orange", neutral_hue="slate"),
776
  outputs=[multiimage_prompt, selected_img_idx],
777
  )
778
 
779
- multiimage_prompt.upload(
780
- preprocess_images,
781
- inputs=[multiimage_prompt],
782
- outputs=[multiimage_prompt],
783
- )
784
-
785
  generate_btn.click(
786
  get_seed,
787
  inputs=[randomize_seed, seed],
788
  outputs=[seed],
789
- ).then(
790
- preprocess_for_generate,
791
- inputs=[multiimage_prompt],
792
- outputs=[processed_buf],
793
  ).then(
794
  image_to_3d,
795
  inputs=[
796
- processed_buf, seed, resolution,
797
  ss_guidance_strength, ss_guidance_rescale, ss_sampling_steps, ss_rescale_t,
798
  shape_slat_guidance_strength, shape_slat_guidance_rescale, shape_slat_sampling_steps, shape_slat_rescale_t,
799
  tex_slat_guidance_strength, tex_slat_guidance_rescale, tex_slat_sampling_steps, tex_slat_rescale_t,
 
385
  return output
386
 
387
 
 
 
 
 
 
 
 
 
 
388
  def pack_state(latents: Tuple[SparseTensor, SparseTensor, int]) -> dict:
389
  shape_slat, tex_slat, res = latents
390
  return {
 
478
  return [preprocess_image(image) for image in images]
479
 
480
 
 
 
 
 
 
 
 
 
 
481
  @spaces.GPU(duration=120)
482
  def image_to_3d(
483
+ multiimages,
484
  seed,
485
  resolution,
486
  ss_guidance_strength,
 
500
  req: gr.Request,
501
  progress=gr.Progress(track_tqdm=True),
502
  ):
503
+ if not multiimages:
504
+ raise gr.Error("Please upload images or select an example first.")
505
+
506
+ # Preprocess images (background removal for images without alpha)
507
+ images = [image[0] for image in multiimages]
508
+ processed_images = [preprocess_image(img) for img in images]
509
+
510
  # --- Sampling ---
511
  outputs, latents = pipeline.run_multi_image(
512
  processed_images,
 
739
  )
740
 
741
  output_buf = gr.State()
 
742
  selected_img_idx = gr.State(value=None)
743
 
744
 
 
764
  outputs=[multiimage_prompt, selected_img_idx],
765
  )
766
 
 
 
 
 
 
 
767
  generate_btn.click(
768
  get_seed,
769
  inputs=[randomize_seed, seed],
770
  outputs=[seed],
 
 
 
 
771
  ).then(
772
  image_to_3d,
773
  inputs=[
774
+ multiimage_prompt, seed, resolution,
775
  ss_guidance_strength, ss_guidance_rescale, ss_sampling_steps, ss_rescale_t,
776
  shape_slat_guidance_strength, shape_slat_guidance_rescale, shape_slat_sampling_steps, shape_slat_rescale_t,
777
  tex_slat_guidance_strength, tex_slat_guidance_rescale, tex_slat_sampling_steps, tex_slat_rescale_t,