Spaces:
Sleeping
Sleeping
Claude commited on
Commit ·
5026b24
1
Parent(s): c1acc29
fix: tighten illustration noise filter — alpha ratio, per-region cleanup
Browse files- smoke_signal_tab.py +29 -1
smoke_signal_tab.py
CHANGED
|
@@ -1721,13 +1721,41 @@ def _run_tesseract_batch(
|
|
| 1721 |
alpha_ratio = (letters / printable) if printable else 0.0
|
| 1722 |
tokens = [t for t in full_text.split() if t]
|
| 1723 |
avg_token_len = (sum(len(t) for t in tokens) / len(tokens)) if tokens else 0.0
|
| 1724 |
-
|
|
|
|
|
|
|
| 1725 |
return {
|
| 1726 |
"regions": [],
|
| 1727 |
"confidence": 0.0,
|
| 1728 |
"method": "tesseract-noise-filtered",
|
| 1729 |
"tesseract_lang": lang_hint or "eng",
|
| 1730 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1731 |
|
| 1732 |
return {
|
| 1733 |
"regions": regions,
|
|
|
|
| 1721 |
alpha_ratio = (letters / printable) if printable else 0.0
|
| 1722 |
tokens = [t for t in full_text.split() if t]
|
| 1723 |
avg_token_len = (sum(len(t) for t in tokens) / len(tokens)) if tokens else 0.0
|
| 1724 |
+
# Filter illustration noise — two thresholds:
|
| 1725 |
+
# 1. Strict: low conf + low alpha + short tokens (original heuristic, loosened)
|
| 1726 |
+
if regions and avg_conf <= 0.55 and alpha_ratio < 0.72 and avg_token_len < 3.5:
|
| 1727 |
return {
|
| 1728 |
"regions": [],
|
| 1729 |
"confidence": 0.0,
|
| 1730 |
"method": "tesseract-noise-filtered",
|
| 1731 |
"tesseract_lang": lang_hint or "eng",
|
| 1732 |
}
|
| 1733 |
+
# 2. Pure gibberish: very low alpha ratio regardless of confidence
|
| 1734 |
+
if regions and alpha_ratio < 0.50:
|
| 1735 |
+
return {
|
| 1736 |
+
"regions": [],
|
| 1737 |
+
"confidence": 0.0,
|
| 1738 |
+
"method": "tesseract-noise-filtered",
|
| 1739 |
+
"tesseract_lang": lang_hint or "eng",
|
| 1740 |
+
}
|
| 1741 |
+
# 3. Filter individual regions that look like illustration noise
|
| 1742 |
+
# Keep only regions where alpha ratio >= 0.60 and token length >= 2
|
| 1743 |
+
clean_regions = []
|
| 1744 |
+
for r in regions:
|
| 1745 |
+
txt = r["text"]
|
| 1746 |
+
letters = sum(1 for c in txt if c.isalpha())
|
| 1747 |
+
printable = sum(1 for c in txt if c.isprintable() and not c.isspace())
|
| 1748 |
+
r_alpha = (letters / printable) if printable else 0.0
|
| 1749 |
+
tokens = [t for t in txt.split() if t]
|
| 1750 |
+
r_avg_tok = (sum(len(t) for t in tokens) / len(tokens)) if tokens else 0.0
|
| 1751 |
+
if r_alpha >= 0.55 or r["confidence"] >= 0.75:
|
| 1752 |
+
clean_regions.append(r)
|
| 1753 |
+
if clean_regions and len(clean_regions) < len(regions):
|
| 1754 |
+
# Recalculate confidence without noise regions
|
| 1755 |
+
cw = sum(r["confidence"] * r["word_count"] for r in clean_regions)
|
| 1756 |
+
wc = sum(r["word_count"] for r in clean_regions)
|
| 1757 |
+
avg_conf = round(cw / max(wc, 1), 4)
|
| 1758 |
+
regions = clean_regions
|
| 1759 |
|
| 1760 |
return {
|
| 1761 |
"regions": regions,
|