Spaces:
Sleeping
Sleeping
Claude commited on
Commit ·
5b83ba1
1
Parent(s): 60e63b2
fix: convert run_ocr to generator — live log streaming, no more silent hang
Browse files- smoke_signal_tab.py +6 -1
smoke_signal_tab.py
CHANGED
|
@@ -1906,6 +1906,7 @@ def run_ocr(page_selection: str = "", page_exclusion: str = "", replace_book_que
|
|
| 1906 |
)
|
| 1907 |
)
|
| 1908 |
|
|
|
|
| 1909 |
punct_mod = _load_punct_module()
|
| 1910 |
if punct_mod is None:
|
| 1911 |
log.append(log_line(f"⚠ Punctuation corrector unavailable ({_PUNCT_MODULE_ERROR or 'unknown'})"))
|
|
@@ -1932,6 +1933,7 @@ def run_ocr(page_selection: str = "", page_exclusion: str = "", replace_book_que
|
|
| 1932 |
for _, row in eligible.iterrows():
|
| 1933 |
book_id = row["book_id"]
|
| 1934 |
log.append(log_line(f"▶ {book_id}: starting OCR"))
|
|
|
|
| 1935 |
profile_path = PROFILES_DIR / f"{book_id}_page_profile.json"
|
| 1936 |
if not profile_path.exists():
|
| 1937 |
log.append(log_line(f"✗ {book_id}: no profile"))
|
|
@@ -2203,6 +2205,7 @@ def run_ocr(page_selection: str = "", page_exclusion: str = "", replace_book_que
|
|
| 2203 |
pass
|
| 2204 |
|
| 2205 |
log.append(log_line(f" → {book_id}: batch OCR complete — building review queue"))
|
|
|
|
| 2206 |
# Second pass: build page-level OCR output and review queue.
|
| 2207 |
for page_data in profile.get("pages", []):
|
| 2208 |
page_num = page_data["page_number"]
|
|
@@ -2331,6 +2334,7 @@ def run_ocr(page_selection: str = "", page_exclusion: str = "", replace_book_que
|
|
| 2331 |
df.loc[df["book_id"] == book_id, "status"] = "ocred"
|
| 2332 |
total_review = len(review_pages) + len(quarantine_pages)
|
| 2333 |
log.append(log_line(f"✓ {book_id}: {len(ocr_pages)} selected pp — review queue: {total_review} · queue write complete"))
|
|
|
|
| 2334 |
|
| 2335 |
qdf_new = pd.DataFrame(queue_rows)
|
| 2336 |
if QUEUE_CSV.exists():
|
|
@@ -2354,7 +2358,7 @@ def run_ocr(page_selection: str = "", page_exclusion: str = "", replace_book_que
|
|
| 2354 |
QUEUE_CSV.unlink()
|
| 2355 |
|
| 2356 |
save_manifest_df(df)
|
| 2357 |
-
|
| 2358 |
|
| 2359 |
|
| 2360 |
def _ocr_status_html() -> str:
|
|
@@ -2827,6 +2831,7 @@ def smoke_signal_tab():
|
|
| 2827 |
inputs=[ocr_page_selection, ocr_page_exclusion, ocr_replace_queue],
|
| 2828 |
outputs=[ocr_status, ocr_log],
|
| 2829 |
show_progress="hidden",
|
|
|
|
| 2830 |
)
|
| 2831 |
ocr_tab.select(
|
| 2832 |
_default_ocr_scope_values,
|
|
|
|
| 1906 |
)
|
| 1907 |
)
|
| 1908 |
|
| 1909 |
+
yield _ocr_status_html(), "\n".join(log) # stream: models loaded
|
| 1910 |
punct_mod = _load_punct_module()
|
| 1911 |
if punct_mod is None:
|
| 1912 |
log.append(log_line(f"⚠ Punctuation corrector unavailable ({_PUNCT_MODULE_ERROR or 'unknown'})"))
|
|
|
|
| 1933 |
for _, row in eligible.iterrows():
|
| 1934 |
book_id = row["book_id"]
|
| 1935 |
log.append(log_line(f"▶ {book_id}: starting OCR"))
|
| 1936 |
+
yield _ocr_status_html(), "\n".join(log) # stream: book start
|
| 1937 |
profile_path = PROFILES_DIR / f"{book_id}_page_profile.json"
|
| 1938 |
if not profile_path.exists():
|
| 1939 |
log.append(log_line(f"✗ {book_id}: no profile"))
|
|
|
|
| 2205 |
pass
|
| 2206 |
|
| 2207 |
log.append(log_line(f" → {book_id}: batch OCR complete — building review queue"))
|
| 2208 |
+
yield _ocr_status_html(), "\n".join(log) # stream: batch OCR done
|
| 2209 |
# Second pass: build page-level OCR output and review queue.
|
| 2210 |
for page_data in profile.get("pages", []):
|
| 2211 |
page_num = page_data["page_number"]
|
|
|
|
| 2334 |
df.loc[df["book_id"] == book_id, "status"] = "ocred"
|
| 2335 |
total_review = len(review_pages) + len(quarantine_pages)
|
| 2336 |
log.append(log_line(f"✓ {book_id}: {len(ocr_pages)} selected pp — review queue: {total_review} · queue write complete"))
|
| 2337 |
+
yield _ocr_status_html(), "\n".join(log) # stream: book done
|
| 2338 |
|
| 2339 |
qdf_new = pd.DataFrame(queue_rows)
|
| 2340 |
if QUEUE_CSV.exists():
|
|
|
|
| 2358 |
QUEUE_CSV.unlink()
|
| 2359 |
|
| 2360 |
save_manifest_df(df)
|
| 2361 |
+
yield _ocr_status_html(), "\n".join(log) # stream: final
|
| 2362 |
|
| 2363 |
|
| 2364 |
def _ocr_status_html() -> str:
|
|
|
|
| 2831 |
inputs=[ocr_page_selection, ocr_page_exclusion, ocr_replace_queue],
|
| 2832 |
outputs=[ocr_status, ocr_log],
|
| 2833 |
show_progress="hidden",
|
| 2834 |
+
trigger_mode="once",
|
| 2835 |
)
|
| 2836 |
ocr_tab.select(
|
| 2837 |
_default_ocr_scope_values,
|