Spaces:
Sleeping
Sleeping
Pointf5ive commited on
Commit ·
db859e4
1
Parent(s): d94ff96
Improve Smoke Signal profile/OCR diagnostics for rights/status gating
Browse files- smoke_signal_tab.py +20 -0
smoke_signal_tab.py
CHANGED
|
@@ -602,6 +602,8 @@ def run_profile() -> tuple:
|
|
| 602 |
except ImportError:
|
| 603 |
return _profile_status_html(), "PyMuPDF not installed. Run: pip install pymupdf"
|
| 604 |
|
|
|
|
|
|
|
| 605 |
for _, row in pending.iterrows():
|
| 606 |
book_id = row["book_id"]
|
| 607 |
filename = row["filename"]
|
|
@@ -612,6 +614,7 @@ def run_profile() -> tuple:
|
|
| 612 |
continue
|
| 613 |
if row.get("rights_class") in ("unknown", "excluded"):
|
| 614 |
log.append(log_line(f"↩ {book_id}: skipped — rights={row['rights_class']}"))
|
|
|
|
| 615 |
continue
|
| 616 |
|
| 617 |
try:
|
|
@@ -663,6 +666,14 @@ def run_profile() -> tuple:
|
|
| 663 |
except Exception as e:
|
| 664 |
log.append(log_line(f"✗ {book_id}: {e}"))
|
| 665 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 666 |
save_manifest_df(df)
|
| 667 |
return _profile_status_html(), "\n".join(log)
|
| 668 |
|
|
@@ -711,6 +722,15 @@ def run_ocr() -> tuple:
|
|
| 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 |
|
| 716 |
log = []
|
|
|
|
| 602 |
except ImportError:
|
| 603 |
return _profile_status_html(), "PyMuPDF not installed. Run: pip install pymupdf"
|
| 604 |
|
| 605 |
+
skipped_rights = 0
|
| 606 |
+
|
| 607 |
for _, row in pending.iterrows():
|
| 608 |
book_id = row["book_id"]
|
| 609 |
filename = row["filename"]
|
|
|
|
| 614 |
continue
|
| 615 |
if row.get("rights_class") in ("unknown", "excluded"):
|
| 616 |
log.append(log_line(f"↩ {book_id}: skipped — rights={row['rights_class']}"))
|
| 617 |
+
skipped_rights += 1
|
| 618 |
continue
|
| 619 |
|
| 620 |
try:
|
|
|
|
| 666 |
except Exception as e:
|
| 667 |
log.append(log_line(f"✗ {book_id}: {e}"))
|
| 668 |
|
| 669 |
+
if skipped_rights:
|
| 670 |
+
log.append(
|
| 671 |
+
log_line(
|
| 672 |
+
f"⚠ {skipped_rights} source(s) skipped due rights_class=unknown/excluded. "
|
| 673 |
+
"Set rights in Step 1 and rerun Profile."
|
| 674 |
+
)
|
| 675 |
+
)
|
| 676 |
+
|
| 677 |
save_manifest_df(df)
|
| 678 |
return _profile_status_html(), "\n".join(log)
|
| 679 |
|
|
|
|
| 722 |
|
| 723 |
eligible = df[df["status"].isin(["profiled", "ocred", "rendered"])]
|
| 724 |
if eligible.empty:
|
| 725 |
+
unknown_or_excluded = df[df["rights_class"].isin(["unknown", "excluded"])] if "rights_class" in df.columns else df.iloc[0:0]
|
| 726 |
+
pending = df[df["status"] == "pending"] if "status" in df.columns else df.iloc[0:0]
|
| 727 |
+
debug += (
|
| 728 |
+
f"Eligible rows={len(eligible)}\n"
|
| 729 |
+
f"Pending rows={len(pending)}\n"
|
| 730 |
+
f"Unknown/excluded rights={len(unknown_or_excluded)}\n"
|
| 731 |
+
"Tip: In Step 1, update rights_class away from unknown/excluded, "
|
| 732 |
+
"then rerun Step 2 Profile.\n"
|
| 733 |
+
)
|
| 734 |
return _ocr_status_html(), debug + "No profiled PDFs. Complete Step 2 first."
|
| 735 |
|
| 736 |
log = []
|