Spaces:
Sleeping
Sleeping
Pointf5ive commited on
Commit ·
bb53942
1
Parent(s): 7ad227d
Tune fallback for speed and filter low-confidence OCR noise
Browse files- smoke_signal_tab.py +18 -8
smoke_signal_tab.py
CHANGED
|
@@ -727,21 +727,21 @@ try:
|
|
| 727 |
except Exception:
|
| 728 |
SS_RENDER_DPI_SURYA = 300
|
| 729 |
try:
|
| 730 |
-
SS_RENDER_DPI_FALLBACK = max(72, int(os.environ.get("SS_RENDER_DPI_FALLBACK", "
|
| 731 |
except Exception:
|
| 732 |
-
SS_RENDER_DPI_FALLBACK =
|
| 733 |
try:
|
| 734 |
-
SS_TESSERACT_WORKERS = max(1, int(os.environ.get("SS_TESSERACT_WORKERS", "
|
| 735 |
except Exception:
|
| 736 |
-
SS_TESSERACT_WORKERS =
|
| 737 |
try:
|
| 738 |
-
SS_TESSERACT_TIMEOUT_SEC = max(1, int(os.environ.get("SS_TESSERACT_TIMEOUT_SEC", "
|
| 739 |
except Exception:
|
| 740 |
-
SS_TESSERACT_TIMEOUT_SEC =
|
| 741 |
try:
|
| 742 |
-
SS_TESSERACT_PSM = max(1, int(os.environ.get("SS_TESSERACT_PSM", "
|
| 743 |
except Exception:
|
| 744 |
-
SS_TESSERACT_PSM =
|
| 745 |
|
| 746 |
|
| 747 |
def _load_surya_runtime():
|
|
@@ -946,6 +946,16 @@ def _run_tesseract_batch(images):
|
|
| 946 |
word_count += wc
|
| 947 |
|
| 948 |
avg_conf = round(conf_weighted / max(word_count, 1), 4) if regions else 0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 949 |
return {"regions": regions, "confidence": avg_conf, "method": "tesseract"}
|
| 950 |
except RuntimeError as e:
|
| 951 |
return {"regions": [], "confidence": 0.0, "method": f"error-tesseract-timeout ({e})"}
|
|
|
|
| 727 |
except Exception:
|
| 728 |
SS_RENDER_DPI_SURYA = 300
|
| 729 |
try:
|
| 730 |
+
SS_RENDER_DPI_FALLBACK = max(72, int(os.environ.get("SS_RENDER_DPI_FALLBACK", "180")))
|
| 731 |
except Exception:
|
| 732 |
+
SS_RENDER_DPI_FALLBACK = 180
|
| 733 |
try:
|
| 734 |
+
SS_TESSERACT_WORKERS = max(1, int(os.environ.get("SS_TESSERACT_WORKERS", "3")))
|
| 735 |
except Exception:
|
| 736 |
+
SS_TESSERACT_WORKERS = 3
|
| 737 |
try:
|
| 738 |
+
SS_TESSERACT_TIMEOUT_SEC = max(1, int(os.environ.get("SS_TESSERACT_TIMEOUT_SEC", "10")))
|
| 739 |
except Exception:
|
| 740 |
+
SS_TESSERACT_TIMEOUT_SEC = 10
|
| 741 |
try:
|
| 742 |
+
SS_TESSERACT_PSM = max(1, int(os.environ.get("SS_TESSERACT_PSM", "11")))
|
| 743 |
except Exception:
|
| 744 |
+
SS_TESSERACT_PSM = 11
|
| 745 |
|
| 746 |
|
| 747 |
def _load_surya_runtime():
|
|
|
|
| 946 |
word_count += wc
|
| 947 |
|
| 948 |
avg_conf = round(conf_weighted / max(word_count, 1), 4) if regions else 0.0
|
| 949 |
+
# Filter obvious OCR noise from illustration texture (common in no-text pages).
|
| 950 |
+
full_text = " ".join(r["text"] for r in regions).strip()
|
| 951 |
+
letters = sum(1 for c in full_text if c.isalpha())
|
| 952 |
+
printable = sum(1 for c in full_text if c.isprintable() and not c.isspace())
|
| 953 |
+
alpha_ratio = (letters / printable) if printable else 0.0
|
| 954 |
+
tokens = [t for t in full_text.split() if t]
|
| 955 |
+
avg_token_len = (sum(len(t) for t in tokens) / len(tokens)) if tokens else 0.0
|
| 956 |
+
if regions and avg_conf <= 0.42 and alpha_ratio < 0.62 and avg_token_len < 3.2:
|
| 957 |
+
return {"regions": [], "confidence": 0.0, "method": "tesseract-noise-filtered"}
|
| 958 |
+
|
| 959 |
return {"regions": regions, "confidence": avg_conf, "method": "tesseract"}
|
| 960 |
except RuntimeError as e:
|
| 961 |
return {"regions": [], "confidence": 0.0, "method": f"error-tesseract-timeout ({e})"}
|