Spaces:
Sleeping
Sleeping
Pointf5ive commited on
Commit ·
9737ee7
1
Parent(s): 85cfc31
Gate fallback OCR by minimum confidence to reduce gibberish queue
Browse files- smoke_signal_tab.py +11 -2
smoke_signal_tab.py
CHANGED
|
@@ -767,6 +767,10 @@ try:
|
|
| 767 |
SS_TESSERACT_PSM = max(1, int(os.environ.get("SS_TESSERACT_PSM", "11")))
|
| 768 |
except Exception:
|
| 769 |
SS_TESSERACT_PSM = 11
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
|
| 771 |
|
| 772 |
def _load_surya_runtime():
|
|
@@ -971,6 +975,11 @@ def _run_tesseract_batch(images):
|
|
| 971 |
word_count += wc
|
| 972 |
|
| 973 |
avg_conf = round(conf_weighted / max(word_count, 1), 4) if regions else 0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 974 |
# Filter obvious OCR noise from illustration texture (common in no-text pages).
|
| 975 |
full_text = " ".join(r["text"] for r in regions).strip()
|
| 976 |
letters = sum(1 for c in full_text if c.isalpha())
|
|
@@ -1049,7 +1058,7 @@ def run_ocr(progress=gr.Progress(track_tqdm=False)) -> tuple:
|
|
| 1049 |
log.append(
|
| 1050 |
log_line(
|
| 1051 |
f"ℹ Tesseract fallback config: workers={SS_TESSERACT_WORKERS} timeout={SS_TESSERACT_TIMEOUT_SEC}s "
|
| 1052 |
-
f"psm={SS_TESSERACT_PSM} dpi={SS_RENDER_DPI_FALLBACK}"
|
| 1053 |
)
|
| 1054 |
)
|
| 1055 |
|
|
@@ -1282,7 +1291,7 @@ def run_ocr(progress=gr.Progress(track_tqdm=False)) -> tuple:
|
|
| 1282 |
conf = 0.0
|
| 1283 |
method = "skipped-no-surya"
|
| 1284 |
|
| 1285 |
-
if method
|
| 1286 |
conf_class = "auto-accept"
|
| 1287 |
elif conf >= default_cal["auto_accept"]:
|
| 1288 |
conf_class = "auto-accept"
|
|
|
|
| 767 |
SS_TESSERACT_PSM = max(1, int(os.environ.get("SS_TESSERACT_PSM", "11")))
|
| 768 |
except Exception:
|
| 769 |
SS_TESSERACT_PSM = 11
|
| 770 |
+
try:
|
| 771 |
+
SS_TESSERACT_MIN_CONF_KEEP = max(0.0, min(1.0, float(os.environ.get("SS_TESSERACT_MIN_CONF_KEEP", "0.58"))))
|
| 772 |
+
except Exception:
|
| 773 |
+
SS_TESSERACT_MIN_CONF_KEEP = 0.58
|
| 774 |
|
| 775 |
|
| 776 |
def _load_surya_runtime():
|
|
|
|
| 975 |
word_count += wc
|
| 976 |
|
| 977 |
avg_conf = round(conf_weighted / max(word_count, 1), 4) if regions else 0.0
|
| 978 |
+
|
| 979 |
+
# Hard gate for fallback quality: do not keep OCR text below minimum page confidence.
|
| 980 |
+
if regions and avg_conf < SS_TESSERACT_MIN_CONF_KEEP:
|
| 981 |
+
return {"regions": [], "confidence": 0.0, "method": "tesseract-lowconf-filtered"}
|
| 982 |
+
|
| 983 |
# Filter obvious OCR noise from illustration texture (common in no-text pages).
|
| 984 |
full_text = " ".join(r["text"] for r in regions).strip()
|
| 985 |
letters = sum(1 for c in full_text if c.isalpha())
|
|
|
|
| 1058 |
log.append(
|
| 1059 |
log_line(
|
| 1060 |
f"ℹ Tesseract fallback config: workers={SS_TESSERACT_WORKERS} timeout={SS_TESSERACT_TIMEOUT_SEC}s "
|
| 1061 |
+
f"psm={SS_TESSERACT_PSM} dpi={SS_RENDER_DPI_FALLBACK} min_conf_keep={SS_TESSERACT_MIN_CONF_KEEP:.2f}"
|
| 1062 |
)
|
| 1063 |
)
|
| 1064 |
|
|
|
|
| 1291 |
conf = 0.0
|
| 1292 |
method = "skipped-no-surya"
|
| 1293 |
|
| 1294 |
+
if method in ("tesseract-noise-filtered", "tesseract-lowconf-filtered") and not regions:
|
| 1295 |
conf_class = "auto-accept"
|
| 1296 |
elif conf >= default_cal["auto_accept"]:
|
| 1297 |
conf_class = "auto-accept"
|