Spaces:
Paused
Paused
Update app_quant_latent.py
Browse files- app_quant_latent.py +18 -5
app_quant_latent.py
CHANGED
|
@@ -593,18 +593,31 @@ def generate_image(prompt, height, width, steps, seed, guidance_scale=0.0):
|
|
| 593 |
try:
|
| 594 |
latents = safe_get_latents(pipe, height, width, generator, device, LOGS)
|
| 595 |
|
| 596 |
-
# --- FIX:
|
| 597 |
try:
|
| 598 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 599 |
except Exception:
|
| 600 |
latent_img = placeholder
|
|
|
|
| 601 |
latent_gallery.append(latent_img)
|
| 602 |
|
| 603 |
# Yield initial latent preview
|
| 604 |
yield None, latent_gallery, LOGS
|
| 605 |
|
| 606 |
-
#
|
| 607 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 608 |
final_gallery.append(final_img)
|
| 609 |
LOGS.append("✅ Advanced latent pipeline succeeded.")
|
| 610 |
|
|
@@ -633,7 +646,7 @@ def generate_image(prompt, height, width, steps, seed, guidance_scale=0.0):
|
|
| 633 |
)
|
| 634 |
final_img = output.images[0]
|
| 635 |
final_gallery.append(final_img)
|
| 636 |
-
latent_gallery.append(final_img) # fallback
|
| 637 |
LOGS.append("✅ Standard pipeline succeeded.")
|
| 638 |
yield final_img, latent_gallery, LOGS
|
| 639 |
|
|
|
|
| 593 |
try:
|
| 594 |
latents = safe_get_latents(pipe, height, width, generator, device, LOGS)
|
| 595 |
|
| 596 |
+
# --- FIX: Convert latent tensor to PIL image ---
|
| 597 |
try:
|
| 598 |
+
with torch.no_grad():
|
| 599 |
+
latent_img_tensor = pipe.vae.decode(latents).sample # [1, 3, H, W]
|
| 600 |
+
latent_img_tensor = (latent_img_tensor / 2 + 0.5).clamp(0, 1) # normalize
|
| 601 |
+
latent_img_tensor = latent_img_tensor.cpu().permute(0, 2, 3, 1)[0] # HWC
|
| 602 |
+
latent_img = Image.fromarray((latent_img_tensor.numpy() * 255).astype('uint8'))
|
| 603 |
except Exception:
|
| 604 |
latent_img = placeholder
|
| 605 |
+
|
| 606 |
latent_gallery.append(latent_img)
|
| 607 |
|
| 608 |
# Yield initial latent preview
|
| 609 |
yield None, latent_gallery, LOGS
|
| 610 |
|
| 611 |
+
# --- Final image from latent ---
|
| 612 |
+
try:
|
| 613 |
+
with torch.no_grad():
|
| 614 |
+
final_img_tensor = pipe.vae.decode(latents).sample
|
| 615 |
+
final_img_tensor = (final_img_tensor / 2 + 0.5).clamp(0, 1)
|
| 616 |
+
final_img_tensor = final_img_tensor.cpu().permute(0, 2, 3, 1)[0]
|
| 617 |
+
final_img = Image.fromarray((final_img_tensor.numpy() * 255).astype('uint8'))
|
| 618 |
+
except Exception:
|
| 619 |
+
final_img = placeholder
|
| 620 |
+
|
| 621 |
final_gallery.append(final_img)
|
| 622 |
LOGS.append("✅ Advanced latent pipeline succeeded.")
|
| 623 |
|
|
|
|
| 646 |
)
|
| 647 |
final_img = output.images[0]
|
| 648 |
final_gallery.append(final_img)
|
| 649 |
+
latent_gallery.append(final_img) # fallback preview
|
| 650 |
LOGS.append("✅ Standard pipeline succeeded.")
|
| 651 |
yield final_img, latent_gallery, LOGS
|
| 652 |
|