Claude commited on
Commit
fe5b004
Β·
1 Parent(s): 5b83ba1

feat: auto-populate book ID, safe title, and OCR page scope from ingest fields

Browse files
Files changed (1) hide show
  1. smoke_signal_tab.py +42 -0
smoke_signal_tab.py CHANGED
@@ -2753,6 +2753,48 @@ def smoke_signal_tab():
2753
  inputs=[scope_book_id, scope_include, scope_exclude, scope_title],
2754
  outputs=[ingest_status, manifest_table, ingest_log],
2755
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2756
 
2757
  ingest_btn.click(
2758
  ingest_pdfs,
 
2753
  inputs=[scope_book_id, scope_include, scope_exclude, scope_title],
2754
  outputs=[ingest_status, manifest_table, ingest_log],
2755
  )
2756
+ # Push saved scope values live to OCR page selection fields
2757
+ scope_save_btn.click(
2758
+ lambda inc, exc: (inc or "", exc or ""),
2759
+ inputs=[scope_include, scope_exclude],
2760
+ outputs=[ocr_page_selection, ocr_page_exclusion],
2761
+ )
2762
+
2763
+ # ── Auto-populate: book code + year β†’ both book ID fields ──────
2764
+ def _make_book_id(code, year):
2765
+ code = (code or "").strip().lower()[:3]
2766
+ year = (year or "").strip()[:4]
2767
+ if code and year:
2768
+ return f"{code}{year}", f"{code}{year}"
2769
+ return "", ""
2770
+
2771
+ book_code_input.change(
2772
+ _make_book_id,
2773
+ inputs=[book_code_input, pub_year_input],
2774
+ outputs=[update_book_id, scope_book_id],
2775
+ )
2776
+ pub_year_input.change(
2777
+ _make_book_id,
2778
+ inputs=[book_code_input, pub_year_input],
2779
+ outputs=[update_book_id, scope_book_id],
2780
+ )
2781
+
2782
+ # ── Auto-populate: PDF filename β†’ safe book title ─────────────
2783
+ def _safe_title_from_upload(files):
2784
+ if not files:
2785
+ return ""
2786
+ first = files[0] if isinstance(files, list) else files
2787
+ name = Path(first).stem if isinstance(first, str) else ""
2788
+ # slugify: lowercase, replace spaces/underscores with hyphens, strip non-alphanum
2789
+ import re as _re
2790
+ slug = _re.sub(r"[^a-z0-9]+", "-", name.lower()).strip("-")
2791
+ return slug
2792
+
2793
+ pdf_upload.change(
2794
+ _safe_title_from_upload,
2795
+ inputs=[pdf_upload],
2796
+ outputs=[scope_title],
2797
+ )
2798
 
2799
  ingest_btn.click(
2800
  ingest_pdfs,