rahul7star commited on
Commit
ea69df1
·
verified ·
1 Parent(s): 69e894e

Update app_quant_latent.py

Browse files
Files changed (1) hide show
  1. app_quant_latent.py +14 -5
app_quant_latent.py CHANGED
@@ -102,14 +102,18 @@ log_system_stats("BEFORE TRANSFORMER LOAD")
102
  # FUNCTION TO CONVERT LATENTS TO IMAGE
103
  # ============================================================
104
  def latent_to_image(latent):
 
 
 
105
  try:
106
  img_tensor = pipe.vae.decode(latent)
107
  img_tensor = (img_tensor / 2 + 0.5).clamp(0, 1)
108
- pil_img = T.ToPILImage()(img_tensor[0])
109
  return pil_img
110
  except Exception as e:
111
  log(f"⚠️ Failed to decode latent: {e}")
112
- return None
 
113
 
114
 
115
 
@@ -574,15 +578,16 @@ def generate_image(prompt, height, width, steps, seed, guidance_scale=0.0):
574
 
575
  # Convert latent to preview image
576
  try:
577
- latent_img = latent_to_image(latents, pipe.vae)[0]
578
  except Exception:
579
  latent_img = placeholder
 
580
  latent_gallery.append(latent_img)
581
 
582
- # Yield intermediate update: latents updated, final gallery empty
583
  yield None, latent_gallery, final_gallery, LOGS
584
 
585
- # decode final image
586
  final_img = pipe.decode_latents(latents)[0]
587
  final_gallery.append(final_img)
588
  LOGS.append("✅ Advanced latent pipeline succeeded.")
@@ -619,6 +624,10 @@ def generate_image(prompt, height, width, steps, seed, guidance_scale=0.0):
619
  final_gallery.append(placeholder)
620
  latent_gallery.append(placeholder)
621
  yield placeholder, latent_gallery, final_gallery, LOGS
 
 
 
 
622
  @spaces.GPU
623
  def generate_image_backup(prompt, height, width, steps, seed, guidance_scale=0.0, return_latents=False):
624
  """
 
102
  # FUNCTION TO CONVERT LATENTS TO IMAGE
103
  # ============================================================
104
  def latent_to_image(latent):
105
+ """
106
+ Convert a latent tensor to a PIL image using pipe.vae
107
+ """
108
  try:
109
  img_tensor = pipe.vae.decode(latent)
110
  img_tensor = (img_tensor / 2 + 0.5).clamp(0, 1)
111
+ pil_img = T.ToPILImage()(img_tensor[0].cpu()) # <--- single image
112
  return pil_img
113
  except Exception as e:
114
  log(f"⚠️ Failed to decode latent: {e}")
115
+ # fallback blank image
116
+ return Image.new("RGB", (latent.shape[-1]*8, latent.shape[-2]*8), color=(255,255,255))
117
 
118
 
119
 
 
578
 
579
  # Convert latent to preview image
580
  try:
581
+ latent_img = latent_to_image(latents) # returns single PIL image
582
  except Exception:
583
  latent_img = placeholder
584
+
585
  latent_gallery.append(latent_img)
586
 
587
+ # Yield intermediate update: final gallery empty for now
588
  yield None, latent_gallery, final_gallery, LOGS
589
 
590
+ # decode final image after all timesteps
591
  final_img = pipe.decode_latents(latents)[0]
592
  final_gallery.append(final_img)
593
  LOGS.append("✅ Advanced latent pipeline succeeded.")
 
624
  final_gallery.append(placeholder)
625
  latent_gallery.append(placeholder)
626
  yield placeholder, latent_gallery, final_gallery, LOGS
627
+
628
+
629
+
630
+
631
  @spaces.GPU
632
  def generate_image_backup(prompt, height, width, steps, seed, guidance_scale=0.0, return_latents=False):
633
  """