Pointf5ive commited on
Commit
e31e277
·
1 Parent(s): 6233ead

fix: re-render page image on demand if /tmp wiped after restart

Browse files
Files changed (2) hide show
  1. requirements.txt +1 -0
  2. smoke_signal_tab.py +24 -1
requirements.txt CHANGED
@@ -11,3 +11,4 @@ openpyxl>=3.1
11
  pymupdf>=1.23.0
12
  surya-ocr>=0.4.0
13
  Pillow>=10.0.0
 
 
11
  pymupdf>=1.23.0
12
  surya-ocr>=0.4.0
13
  Pillow>=10.0.0
14
+ pymupdf>=1.23
smoke_signal_tab.py CHANGED
@@ -709,7 +709,7 @@ def run_ocr() -> tuple:
709
  if df.empty:
710
  return _ocr_status_html(), debug + "No sources. Complete Steps 1-2 first."
711
 
712
- eligible = df[df["status"] == "profiled"]
713
  if eligible.empty:
714
  return _ocr_status_html(), debug + "No profiled PDFs. Complete Step 2 first."
715
 
@@ -934,6 +934,29 @@ def get_review_item(idx: int) -> tuple:
934
  candidate = SS_ROOT / crop_path
935
  if candidate.exists():
936
  img_path = str(candidate)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
937
 
938
  info = (f"<div style='font-family:monospace;font-size:11px;color:var(--ss-muted)'>"
939
  f"{item['book_id']} · page {item['page']} · "
 
709
  if df.empty:
710
  return _ocr_status_html(), debug + "No sources. Complete Steps 1-2 first."
711
 
712
+ eligible = df[df["status"].isin(["profiled", "ocred", "rendered"])]
713
  if eligible.empty:
714
  return _ocr_status_html(), debug + "No profiled PDFs. Complete Step 2 first."
715
 
 
934
  candidate = SS_ROOT / crop_path
935
  if candidate.exists():
936
  img_path = str(candidate)
937
+ else:
938
+ # /tmp wiped after restart — re-render page from PDF on demand
939
+ try:
940
+ import fitz
941
+ book_id = item.get("book_id","")
942
+ page_num = int(item.get("page", 1))
943
+ pdf_path = SOURCE_DIR / f"{book_id}.pdf"
944
+ if not pdf_path.exists():
945
+ # try original filename from manifest
946
+ mdf = pd.read_csv(MANIFEST_CSV)
947
+ row = mdf[mdf["book_id"] == book_id]
948
+ if not row.empty:
949
+ pdf_path = SOURCE_DIR / row.iloc[0]["filename"]
950
+ if pdf_path.exists():
951
+ candidate.parent.mkdir(parents=True, exist_ok=True)
952
+ doc = fitz.open(str(pdf_path))
953
+ pg = doc[page_num - 1]
954
+ pix = pg.get_pixmap(dpi=150)
955
+ pix.save(str(candidate))
956
+ doc.close()
957
+ img_path = str(candidate)
958
+ except Exception:
959
+ img_path = None
960
 
961
  info = (f"<div style='font-family:monospace;font-size:11px;color:var(--ss-muted)'>"
962
  f"{item['book_id']} · page {item['page']} · "