hoytshao commited on
Commit
5a4a8c4
·
verified ·
1 Parent(s): bcc62dd

Update app.py

Browse files

Chun updated to include header and footer in mapping list

Files changed (1) hide show
  1. app.py +28 -14
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 lists)
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
- to_remove = {"header", "footer"}
29
- for key in ("layout", "result_formatter"):
30
- if key not in config.get("pipeline", {}):
31
- continue
32
- section = config["pipeline"][key]
33
- if key == "layout" and "label_task_mapping" in section:
34
- abandon = section["label_task_mapping"].get("abandon")
35
- if isinstance(abandon, list):
36
- section["label_task_mapping"]["abandon"] = [x for x in abandon if x not in to_remove]
37
- elif key == "result_formatter" and "abandon" in section:
38
- abandon = section["abandon"]
39
- if isinstance(abandon, list):
40
- section["abandon"] = [x for x in abandon if x not in to_remove]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)