Spaces:
Sleeping
Sleeping
Update app.py
Browse filesChun updated to include header and footer in mapping list
app.py
CHANGED
|
@@ -17,7 +17,7 @@ FORMATTER_PATH = os.path.join(GLMOCR_BASE, "postprocess", "result_formatter.py")
|
|
| 17 |
DEFAULT_ZONE_FRAC = float(os.environ.get("GLMOCR_DEFAULT_ZONE_FRAC", "0.08"))
|
| 18 |
|
| 19 |
# ---------------------------------------------------------------------------
|
| 20 |
-
# 1. Config: include headers/footers (remove from abandon
|
| 21 |
# ---------------------------------------------------------------------------
|
| 22 |
with open(CONFIG_PATH, "r") as f:
|
| 23 |
config = yaml.safe_load(f)
|
|
@@ -25,19 +25,33 @@ with open(CONFIG_PATH, "r") as f:
|
|
| 25 |
config["pipeline"]["maas"]["enabled"] = True
|
| 26 |
config["pipeline"]["maas"]["api_key"] = "4570c28bdea5493c9efae9dae68edc66.sGbA9DLlcX1GlvqV"
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
with open(CONFIG_PATH, "w") as f:
|
| 43 |
yaml.dump(config, f, default_flow_style=False, sort_keys=False)
|
|
|
|
| 17 |
DEFAULT_ZONE_FRAC = float(os.environ.get("GLMOCR_DEFAULT_ZONE_FRAC", "0.08"))
|
| 18 |
|
| 19 |
# ---------------------------------------------------------------------------
|
| 20 |
+
# 1. Config: include headers/footers (remove from abandon, add to text mapping)
|
| 21 |
# ---------------------------------------------------------------------------
|
| 22 |
with open(CONFIG_PATH, "r") as f:
|
| 23 |
config = yaml.safe_load(f)
|
|
|
|
| 25 |
config["pipeline"]["maas"]["enabled"] = True
|
| 26 |
config["pipeline"]["maas"]["api_key"] = "4570c28bdea5493c9efae9dae68edc66.sGbA9DLlcX1GlvqV"
|
| 27 |
|
| 28 |
+
to_include_as_text = {"header", "footer"}
|
| 29 |
+
layout_section = config.get("pipeline", {}).get("layout", {})
|
| 30 |
+
if "label_task_mapping" in layout_section:
|
| 31 |
+
mapping = layout_section["label_task_mapping"]
|
| 32 |
+
# Remove header/footer from abandon so they are not discarded
|
| 33 |
+
abandon = mapping.get("abandon")
|
| 34 |
+
if isinstance(abandon, list):
|
| 35 |
+
mapping["abandon"] = [x for x in abandon if x not in to_include_as_text]
|
| 36 |
+
# Add header/footer to text so they are OCR'd and output as text
|
| 37 |
+
text_labels = mapping.get("text")
|
| 38 |
+
if isinstance(text_labels, list):
|
| 39 |
+
for label in to_include_as_text:
|
| 40 |
+
if label not in text_labels:
|
| 41 |
+
text_labels.append(label)
|
| 42 |
+
|
| 43 |
+
formatter_section = config.get("pipeline", {}).get("result_formatter", {})
|
| 44 |
+
if "abandon" in formatter_section:
|
| 45 |
+
abandon = formatter_section["abandon"]
|
| 46 |
+
if isinstance(abandon, list):
|
| 47 |
+
formatter_section["abandon"] = [x for x in abandon if x not in to_include_as_text]
|
| 48 |
+
# Include header/footer in visualization/output text category
|
| 49 |
+
if "label_visualization_mapping" in formatter_section:
|
| 50 |
+
text_vis = formatter_section["label_visualization_mapping"].get("text")
|
| 51 |
+
if isinstance(text_vis, list):
|
| 52 |
+
for label in to_include_as_text:
|
| 53 |
+
if label not in text_vis:
|
| 54 |
+
text_vis.append(label)
|
| 55 |
|
| 56 |
with open(CONFIG_PATH, "w") as f:
|
| 57 |
yaml.dump(config, f, default_flow_style=False, sort_keys=False)
|