JS6969 commited on
Commit
0728db3
·
verified ·
1 Parent(s): 1379618

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -24
app.py CHANGED
@@ -599,9 +599,9 @@ def export_txt_zip(table_value: Any, dataset_name: str) -> str:
599
  def _render_header_html(auto: bool, px: int, scale: float) -> str:
600
  auto_js = "true" if auto else "false"
601
  return f"""
602
- <div class="cf-hero">
603
- {logo_b64_img()}
604
- <div class="cf-text">
605
  <h1 class="cf-title">ForgeCaptions</h1>
606
  <div class="cf-sub">Batch captioning</div>
607
  <div class="cf-sub">Scrollable editor & autosave</div>
@@ -610,37 +610,64 @@ def _render_header_html(auto: bool, px: int, scale: float) -> str:
610
  </div>
611
  <hr>
612
  <style>
613
- .cf-logo {{ height: auto; width: auto; object-fit: contain; }}
 
 
 
 
 
 
 
 
614
  </style>
615
  <script>
616
  (function() {{
617
- const AUTO = {auto_js};
618
- const PX = {int(px)};
619
  const SCALE = {float(scale)};
 
620
  function fit() {{
 
 
621
  const logo = document.querySelector(".cf-logo");
622
- const text = document.querySelector(".cf-text");
623
- if (!logo || !text) return;
624
- if (AUTO) {{
625
- const h = text.getBoundingClientRect().height || 180;
626
- const target = Math.max(80, Math.min(420, Math.round(h * SCALE)));
627
- logo.style.height = target + "px";
628
- }} else {{
629
- logo.style.height = Math.max(80, Math.min(420, PX)) + "px";
630
- }}
 
 
 
 
 
631
  }}
632
- const textNode = document.querySelector(".cf-text");
633
- if (window.ResizeObserver && textNode) {{
634
- const ro = new ResizeObserver(fit);
635
- ro.observe(textNode);
636
  }}
 
637
  window.addEventListener("resize", fit, {{ passive: true }});
 
 
 
 
 
 
 
638
  setTimeout(fit, 0);
 
 
639
  }})();
640
  </script>
641
  """
642
 
643
 
 
644
  # ------------------------------
645
  # 11) UI (Blocks)
646
  # ------------------------------
@@ -649,11 +676,17 @@ BASE_CSS = """
649
  .gradio-container{max-width:100%!important}
650
 
651
  /* Header */
652
- .cf-hero{display:flex; align-items:center; justify-content:center; gap:16px;
653
- margin:4px 0 12px; text-align:center;}
654
- .cf-hero .cf-text{text-align:center;}
655
- .cf-title{margin:0;font-size:3.25rem;line-height:1;letter-spacing:.2px}
656
- .cf-sub{margin:6px 0 0;font-size:1.1rem;color:#cfd3da}
 
 
 
 
 
 
657
 
658
  /* Results area + robust scrollbars */
659
  .cf-scroll{border:1px solid #e6e6e6; border-radius:10px; padding:8px}
 
599
  def _render_header_html(auto: bool, px: int, scale: float) -> str:
600
  auto_js = "true" if auto else "false"
601
  return f"""
602
+ <div class="cf-hero" id="cfHero">
603
+ {logo_b64_img() or '<div class="cf-logo"></div>'}
604
+ <div class="cf-text" id="cfText">
605
  <h1 class="cf-title">ForgeCaptions</h1>
606
  <div class="cf-sub">Batch captioning</div>
607
  <div class="cf-sub">Scrollable editor & autosave</div>
 
610
  </div>
611
  <hr>
612
  <style>
613
+ /* Let the hero stretch to tallest child; we’ll force exact height via JS */
614
+ #cfHero {{ align-items: stretch; }}
615
+ .cf-logo {{
616
+ display: block;
617
+ width: auto;
618
+ height: auto; /* JS will set explicit px height */
619
+ object-fit: contain;
620
+ max-height: 480px; /* safety clamp */
621
+ }}
622
  </style>
623
  <script>
624
  (function() {{
625
+ const AUTO = {auto_js};
626
+ const PX = {int(px)};
627
  const SCALE = {float(scale)};
628
+
629
  function fit() {{
630
+ const hero = document.getElementById("cfHero");
631
+ const text = document.getElementById("cfText");
632
  const logo = document.querySelector(".cf-logo");
633
+ if (!hero || !text || !logo) return;
634
+
635
+ // Include vertical margins so we truly match the whole text stack
636
+ const cs = getComputedStyle(text);
637
+ const rect = text.getBoundingClientRect();
638
+ const fullH = rect.height + parseFloat(cs.marginTop) + parseFloat(cs.marginBottom);
639
+
640
+ const target = AUTO
641
+ ? Math.max(80, Math.min(480, Math.round(fullH * SCALE)))
642
+ : Math.max(80, Math.min(480, PX));
643
+
644
+ hero.style.minHeight = target + "px"; // ensure the flex row is that tall
645
+ logo.style.height = target + "px"; // logo matches exactly
646
+ logo.style.width = "auto"; // preserve aspect ratio
647
  }}
648
+
649
+ // Recompute on font load, hydration, resizes, and text changes
650
+ if (document.fonts && document.fonts.ready) {{
651
+ document.fonts.ready.then(fit);
652
  }}
653
+ window.addEventListener("load", fit, {{ passive: true }});
654
  window.addEventListener("resize", fit, {{ passive: true }});
655
+
656
+ const textEl = document.getElementById("cfText");
657
+ if (window.ResizeObserver && textEl) {{
658
+ new ResizeObserver(fit).observe(textEl);
659
+ }}
660
+
661
+ // A couple of deferred passes to catch late reflows
662
  setTimeout(fit, 0);
663
+ setTimeout(fit, 200);
664
+ setTimeout(fit, 800);
665
  }})();
666
  </script>
667
  """
668
 
669
 
670
+
671
  # ------------------------------
672
  # 11) UI (Blocks)
673
  # ------------------------------
 
676
  .gradio-container{max-width:100%!important}
677
 
678
  /* Header */
679
+ .cf-hero{
680
+ display:flex;
681
+ align-items:stretch; /* was center; stretch lets the logo fill the row */
682
+ justify-content:center;
683
+ gap:16px;
684
+ margin:4px 0 12px;
685
+ text-align:center;
686
+ }
687
+ .cf-hero .cf-text{ text-align:center; }
688
+ .cf-title{ margin:0; font-size:3.25rem; line-height:1; letter-spacing:.2px; }
689
+ .cf-sub{ margin:6px 0 0; font-size:1.1rem; color:#cfd3da; }
690
 
691
  /* Results area + robust scrollbars */
692
  .cf-scroll{border:1px solid #e6e6e6; border-radius:10px; padding:8px}