rahul7star commited on
Commit
869955a
Β·
verified Β·
1 Parent(s): 99363bd

Update app_quant_latent.py

Browse files
Files changed (1) hide show
  1. app_quant_latent.py +31 -34
app_quant_latent.py CHANGED
@@ -580,7 +580,7 @@ def generate_image(prompt, height, width, steps, seed, guidance_scale=0.0):
580
 
581
  latents = pipe.scheduler.step(noise_pred, t, latents)["prev_sample"]
582
 
583
- # Convert latents to image
584
  try:
585
  latent_img = latent_to_image(latents)
586
  except Exception:
@@ -588,29 +588,28 @@ def generate_image(prompt, height, width, steps, seed, guidance_scale=0.0):
588
 
589
  latent_gallery.append(latent_img)
590
 
591
- # πŸ”₯ STREAM UPDATE: (final_image=None for now)
592
- yield {
593
- "final_image": None,
594
- "latent_gallery": latent_gallery,
595
- "logs_box": "\n".join(LOGS),
596
- }
597
 
598
- # ----------------------
599
- # Final decode
600
- # ----------------------
601
  final_img = pipe.decode_latents(latents)[0]
602
  final_gallery.append(final_img)
603
  LOGS.append("βœ… Advanced latent pipeline succeeded.")
604
 
605
- # πŸ”₯ Final output
606
- yield {
607
- "final_image": final_img,
608
- "latent_gallery": latent_gallery,
609
- "logs_box": "\n".join(LOGS),
610
- }
611
 
612
  # ==========================================================
613
- # STANDARD PIPELINE (fallback)
614
  # ==========================================================
615
  except Exception as e:
616
  LOGS.append(f"⚠️ Advanced latent mode failed: {e}")
@@ -626,25 +625,23 @@ def generate_image(prompt, height, width, steps, seed, guidance_scale=0.0):
626
  )
627
 
628
  final_img = output.images[0]
629
- final_gallery.append(final_img)
630
  latent_gallery.append(final_img)
631
  LOGS.append("βœ… Standard pipeline succeeded.")
632
 
633
- yield {
634
- "final_image": final_img,
635
- "latent_gallery": latent_gallery,
636
- "logs_box": "\n".join(LOGS),
637
- }
638
 
639
  except Exception as e:
640
  LOGS.append(f"❌ Total failure: {e}")
641
  placeholder_img = placeholder
642
-
643
- yield {
644
- "final_image": placeholder_img,
645
- "latent_gallery": [placeholder_img],
646
- "logs_box": "\n".join(LOGS),
647
- }
648
 
649
 
650
 
@@ -963,11 +960,11 @@ with gr.Blocks(title="Z-Image-Turbo") as demo:
963
  run_btn.click(
964
  fn=generate_image,
965
  inputs=[prompt, height, width, steps, seed],
966
- outputs={
967
- "final_image": final_image,
968
- "latent_gallery": latent_gallery,
969
- "logs_box": logs_box,
970
- }
971
  )
972
 
 
973
  demo.launch()
 
580
 
581
  latents = pipe.scheduler.step(noise_pred, t, latents)["prev_sample"]
582
 
583
+ # convert latent β†’ image
584
  try:
585
  latent_img = latent_to_image(latents)
586
  except Exception:
 
588
 
589
  latent_gallery.append(latent_img)
590
 
591
+ # πŸ”₯ STREAM update
592
+ yield (
593
+ None, # final_image
594
+ latent_gallery, # latent gallery list
595
+ "\n".join(LOGS), # logs
596
+ )
597
 
598
+ # ---------------------
599
+ # FINAL decode
600
+ # ---------------------
601
  final_img = pipe.decode_latents(latents)[0]
602
  final_gallery.append(final_img)
603
  LOGS.append("βœ… Advanced latent pipeline succeeded.")
604
 
605
+ yield (
606
+ final_img,
607
+ latent_gallery,
608
+ "\n".join(LOGS),
609
+ )
 
610
 
611
  # ==========================================================
612
+ # FALLBACK STANDARD PIPELINE
613
  # ==========================================================
614
  except Exception as e:
615
  LOGS.append(f"⚠️ Advanced latent mode failed: {e}")
 
625
  )
626
 
627
  final_img = output.images[0]
 
628
  latent_gallery.append(final_img)
629
  LOGS.append("βœ… Standard pipeline succeeded.")
630
 
631
+ yield (
632
+ final_img,
633
+ latent_gallery,
634
+ "\n".join(LOGS),
635
+ )
636
 
637
  except Exception as e:
638
  LOGS.append(f"❌ Total failure: {e}")
639
  placeholder_img = placeholder
640
+ yield (
641
+ placeholder_img,
642
+ [placeholder_img],
643
+ "\n".join(LOGS),
644
+ )
 
645
 
646
 
647
 
 
960
  run_btn.click(
961
  fn=generate_image,
962
  inputs=[prompt, height, width, steps, seed],
963
+ run_btn.click(
964
+ generate_image,
965
+ inputs=[prompt, height, width, steps, seed],
966
+ outputs=[final_image, latent_gallery, logs_box]
 
967
  )
968
 
969
+
970
  demo.launch()