JS6969 commited on
Commit
5e4989a
·
verified ·
1 Parent(s): dbbd091

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -34
app.py CHANGED
@@ -748,39 +748,73 @@ def _render_header_html(auto: bool, px: int, scale: float) -> str:
748
  {logo_b64_img()}
749
  <div class="cf-text">
750
  <h1 class="cf-title">ForgeCaptions</h1>
751
- <div class="cf-sub">Batch captioning</div>
752
- <div class="cf-sub">Scrollable editor & autosave</div>
753
- <div class="cf-sub">CSV / Excel / TXT export · CSV/XLSX import</div>
754
  </div>
755
  </div>
756
  <hr>
757
  <style>
758
- .cf-logo {{ height: auto; width: auto; object-fit: contain; }}
759
  </style>
760
  <script>
761
  (function() {{
762
  const AUTO = {auto_js};
763
  const PX = {int(px)};
764
  const SCALE = {float(scale)};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
765
  function fit() {{
766
- const logo = document.querySelector(".cf-logo");
767
- const text = document.querySelector(".cf-text");
768
  if (!logo || !text) return;
769
  if (AUTO) {{
770
- const h = text.getBoundingClientRect().height || 200;
771
- const target = Math.max(80, Math.min(520, Math.round(h * SCALE)));
772
- logo.style.height = target + "px";
773
  }} else {{
774
- logo.style.height = Math.max(80, Math.min(520, PX)) + "px";
775
  }}
776
  }}
777
- const textNode = document.querySelector(".cf-text");
 
 
 
 
 
 
 
 
 
 
 
 
778
  if (window.ResizeObserver && textNode) {{
779
- const ro = new ResizeObserver(fit);
780
  ro.observe(textNode);
781
  }}
782
- window.addEventListener("resize", fit, {{ passive: true }});
783
- setTimeout(fit, 0);
 
 
 
784
  }})();
785
  </script>
786
  """
@@ -816,7 +850,7 @@ with gr.Blocks(css=BASE_CSS, title="ForgeCaptions") as demo:
816
  settings = load_settings()
817
  header_html = gr.HTML(_render_header_html(settings.get("logo_auto", True),
818
  settings.get("logo_px", 200),
819
- settings.get("logo_scale", 1.10)))
820
 
821
  # ---- Controls group
822
  with gr.Group():
@@ -862,13 +896,6 @@ with gr.Blocks(css=BASE_CSS, title="ForgeCaptions") as demo:
862
  gpu_budget = gr.Slider(20, 110, value=55, step=5, label="Max seconds per GPU call")
863
  no_time_limit = gr.Checkbox(value=False, label="No time limit (ignore above)")
864
 
865
- # Logo controls
866
- logo_auto = gr.Checkbox(value=settings.get("logo_auto", True),
867
- label="Auto-match logo height to text")
868
- logo_px = gr.Slider(80, 520, value=settings.get("logo_px", 200),
869
- step=4, label="Logo height (px, if Auto off)")
870
- logo_scale = gr.Slider(0.7, 1.6, value=settings.get("logo_scale", 1.10),
871
- step=0.02, label="Logo scale × (if Auto on)")
872
 
873
  # Persist instruction + general settings
874
  def _refresh_instruction(styles, extra, name_value, trigv, begv, endv, excel_px, ms):
@@ -897,18 +924,6 @@ with gr.Blocks(css=BASE_CSS, title="ForgeCaptions") as demo:
897
  return gr.update()
898
  dataset_name.change(_save_dataset_name, inputs=[dataset_name], outputs=[])
899
 
900
- # Header controls live update
901
- def _update_header(auto, px, scale):
902
- cfg = load_settings()
903
- cfg["logo_auto"] = bool(auto)
904
- cfg["logo_px"] = int(px)
905
- cfg["logo_scale"] = float(scale)
906
- save_settings(cfg)
907
- return _render_header_html(cfg["logo_auto"], cfg["logo_px"], cfg["logo_scale"])
908
-
909
- logo_px.change(_update_header, inputs=[logo_auto, logo_px, logo_scale], outputs=[header_html])
910
- logo_auto.change(_update_header, inputs=[logo_auto, logo_px, logo_scale], outputs=[header_html])
911
- logo_scale.change(_update_header, inputs=[logo_auto, logo_px, logo_scale], outputs=[header_html])
912
 
913
  # ---- Shape Aliases (with plural matching + persist) ----
914
  with gr.Accordion("Shape Aliases", open=False):
 
748
  {logo_b64_img()}
749
  <div class="cf-text">
750
  <h1 class="cf-title">ForgeCaptions</h1>
751
+ <div class="cf-sub">JoyCaption Image Captioning </div>
752
+ <div class="cf-sub">Import CSV/XLSX Export CSV/XLSX/TXT</div>
753
+ <div class="cf-sub">Batch 10-20 per Zero GPU run Larger batches with GPU</div>
754
  </div>
755
  </div>
756
  <hr>
757
  <style>
758
+ .cf-logo {{ height: auto; width: auto; object-fit: contain; display:block; }}
759
  </style>
760
  <script>
761
  (function() {{
762
  const AUTO = {auto_js};
763
  const PX = {int(px)};
764
  const SCALE = {float(scale)};
765
+ const MIN = 80, MAX = 720; // hard clamps
766
+
767
+ function outerH(el) {{
768
+ if (!el) return 0;
769
+ const r = el.getBoundingClientRect();
770
+ const cs = getComputedStyle(el);
771
+ return r.height + parseFloat(cs.marginTop) + parseFloat(cs.marginBottom);
772
+ }}
773
+
774
+ function stackHeight(root) {{
775
+ // Sum title + every subtitle's full box height (including margins)
776
+ const title = root.querySelector('.cf-title');
777
+ const subs = root.querySelectorAll('.cf-sub');
778
+ let h = outerH(title);
779
+ subs.forEach(s => h += outerH(s));
780
+ // tiny buffer so the two columns don't look mismatched if rounding occurs
781
+ return Math.round(h + 2);
782
+ }}
783
+
784
  function fit() {{
785
+ const logo = document.querySelector('.cf-logo');
786
+ const text = document.querySelector('.cf-text');
787
  if (!logo || !text) return;
788
  if (AUTO) {{
789
+ const total = stackHeight(text);
790
+ const target = Math.max(MIN, Math.min(MAX, Math.round(total * SCALE)));
791
+ logo.style.height = target + 'px';
792
  }} else {{
793
+ logo.style.height = Math.max(MIN, Math.min(MAX, PX)) + 'px';
794
  }}
795
  }}
796
+
797
+ // Re-fit at the right times
798
+ const textNode = document.querySelector('.cf-text');
799
+
800
+ // 1) Once fonts are ready (prevents under-measuring before webfonts load)
801
+ if (document.fonts && document.fonts.ready) {{
802
+ document.fonts.ready.then(() => requestAnimationFrame(fit));
803
+ }}
804
+
805
+ // 2) On resize
806
+ window.addEventListener('resize', () => requestAnimationFrame(fit), {{ passive: true }});
807
+
808
+ // 3) Whenever the text block changes size (line wrapping, content edits)
809
  if (window.ResizeObserver && textNode) {{
810
+ const ro = new ResizeObserver(() => requestAnimationFrame(fit));
811
  ro.observe(textNode);
812
  }}
813
+
814
+ // 4) As a fallback, run a couple times after first paint
815
+ requestAnimationFrame(fit);
816
+ setTimeout(fit, 100);
817
+ setTimeout(fit, 400);
818
  }})();
819
  </script>
820
  """
 
850
  settings = load_settings()
851
  header_html = gr.HTML(_render_header_html(settings.get("logo_auto", True),
852
  settings.get("logo_px", 200),
853
+ settings.get("logo_scale", 1.0)))
854
 
855
  # ---- Controls group
856
  with gr.Group():
 
896
  gpu_budget = gr.Slider(20, 110, value=55, step=5, label="Max seconds per GPU call")
897
  no_time_limit = gr.Checkbox(value=False, label="No time limit (ignore above)")
898
 
 
 
 
 
 
 
 
899
 
900
  # Persist instruction + general settings
901
  def _refresh_instruction(styles, extra, name_value, trigv, begv, endv, excel_px, ms):
 
924
  return gr.update()
925
  dataset_name.change(_save_dataset_name, inputs=[dataset_name], outputs=[])
926
 
 
 
 
 
 
 
 
 
 
 
 
 
927
 
928
  # ---- Shape Aliases (with plural matching + persist) ----
929
  with gr.Accordion("Shape Aliases", open=False):