rahul7star commited on
Commit
f99be6b
Β·
verified Β·
1 Parent(s): b77c9ec

Update app_quant_latent.py

Browse files
Files changed (1) hide show
  1. app_quant_latent.py +46 -22
app_quant_latent.py CHANGED
@@ -464,6 +464,28 @@ except Exception as e:
464
  log_system_stats("AFTER PIPELINE BUILD")
465
 
466
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
467
 
468
 
469
 
@@ -526,6 +548,7 @@ def generate_image(prompt, height, width, steps, seed, guidance_scale=0.0):
526
 
527
  image = output.images[0]
528
  gallery = [image]
 
529
  LOGS.append("βœ… Advanced latent pipeline succeeded.")
530
 
531
  except Exception as e:
@@ -677,38 +700,39 @@ def generate_image_backup(prompt, height, width, steps, seed, guidance_scale=0.0
677
  # outputs=[final_image, latent_gallery, logs_box]
678
  # )
679
 
680
- with gr.Blocks(title="Z-Image- experiment - dont run")as demo:
681
-
682
- gr.Markdown("## πŸ”₯ Z-Image Turbo β€” Output & Logs Viewer")
683
-
684
- with gr.Tabs():
685
- with gr.TabItem("Output"):
686
  with gr.Row():
687
  with gr.Column(scale=1):
688
- prompt = gr.Textbox(label="Prompt", lines=2, value="boat in ocean")
689
  height = gr.Slider(256, 2048, value=1024, step=8, label="Height")
690
  width = gr.Slider(256, 2048, value=1024, step=8, label="Width")
691
- steps = gr.Slider(1, 50, value=20, step=1, label="Steps")
692
  seed = gr.Number(value=42, label="Seed")
693
- generate_btn = gr.Button("πŸš€ Generate Image")
694
 
695
  with gr.Column(scale=1):
696
  final_image = gr.Image(label="Final Image")
697
- latent_gallery = gr.Gallery(label="Latent Steps", columns=4, height=256, preview=True)
 
 
 
 
 
 
 
 
698
 
699
  with gr.TabItem("Logs"):
700
- logs_box = gr.HTML(value=f"<pre'>{LOGS}</pre>", label="Full Logs")
701
-
702
- def run_and_update_logs(prompt, height, width, steps, seed):
703
- img, gallery, logs = generate_image(prompt, height, width, steps, seed)
704
- combined_logs = "\n".join(logs) + "\n\n" + LOGS # append global logs
705
- return img, gallery, f"<pre id='logbox'>{combined_logs}</pre>"
706
-
707
- generate_btn.click(
708
- fn=run_and_update_logs,
709
- inputs=[prompt, height, width, steps, seed],
710
- outputs=[final_image, latent_gallery, logs_box]
711
- )
712
 
713
 
714
 
 
464
  log_system_stats("AFTER PIPELINE BUILD")
465
 
466
 
467
+ # -----------------------------
468
+ # Monkey-patch prepare_latents
469
+ # -----------------------------
470
+ original_prepare_latents = pipe.prepare_latents
471
+
472
+ def logged_prepare_latents(self, batch_size, num_channels_latents, height, width, dtype, device, generator, latents=None):
473
+ # Call original method
474
+ result_latents = original_prepare_latents(
475
+ batch_size, num_channels_latents, height, width, dtype, device, generator, latents
476
+ )
477
+
478
+ # Save info for logging
479
+ log_msg = f"πŸ”Ή prepare_latents called | shape={result_latents.shape}, dtype={result_latents.dtype}, device={result_latents.device}"
480
+ if hasattr(self, "_latents_log"):
481
+ self._latents_log.append(log_msg)
482
+ else:
483
+ self._latents_log = [log_msg]
484
+
485
+ return result_latents
486
+
487
+ # Apply patch
488
+ pipe.prepare_latents = logged_prepare_latents.__get__(pipe)
489
 
490
 
491
 
 
548
 
549
  image = output.images[0]
550
  gallery = [image]
551
+ LOGS.extend(getattr(pipe, "_latents_log", []))
552
  LOGS.append("βœ… Advanced latent pipeline succeeded.")
553
 
554
  except Exception as e:
 
700
  # outputs=[final_image, latent_gallery, logs_box]
701
  # )
702
 
703
+ with gr.Blocks(title="Z-Image-Turbo") as demo:
704
+ with gr.Tabs():
705
+ with gr.TabItem("Image & Latents"):
 
 
 
706
  with gr.Row():
707
  with gr.Column(scale=1):
708
+ prompt = gr.Textbox(label="Prompt", value="boat in Ocean")
709
  height = gr.Slider(256, 2048, value=1024, step=8, label="Height")
710
  width = gr.Slider(256, 2048, value=1024, step=8, label="Width")
711
+ steps = gr.Slider(1, 50, value=20, step=1, label="Inference Steps")
712
  seed = gr.Number(value=42, label="Seed")
713
+ run_btn = gr.Button("Generate Image")
714
 
715
  with gr.Column(scale=1):
716
  final_image = gr.Image(label="Final Image")
717
+ latent_gallery = gr.Gallery(
718
+ label="Latent Steps", columns=4, height=256, preview=True
719
+ )
720
+
721
+ run_btn.click(
722
+ generate_image,
723
+ inputs=[prompt, height, width, steps, seed],
724
+ outputs=[final_image, latent_gallery, None]
725
+ )
726
 
727
  with gr.TabItem("Logs"):
728
+ logs_box = gr.Textbox(label="All Logs", lines=25)
729
+
730
+ run_btn.click(
731
+ generate_image,
732
+ inputs=[prompt, height, width, steps, seed],
733
+ outputs=[None, None, logs_box]
734
+ )
735
+
 
 
 
 
736
 
737
 
738