Skip to content

Fast, accurate OCR with correctness assessment.

test: align header/footer OCR coverage with upstream image rendering

caowanxia123a1b439f87aa3
diff --git a/sdk/minicpmvocr/postprocess/markdown.py b/sdk/minicpmvocr/postprocess/markdown.py
index 838974f..2223920 100644
--- a/sdk/minicpmvocr/postprocess/markdown.py
+++ b/sdk/minicpmvocr/postprocess/markdown.py
@@ -316,8 +316,6 @@ def assemble_markdown(blocks: list, prompt_cfg: dict) -> str:
parts.append(formula_fmt[label].format(content=content))
elif label == "table":
parts.append(table_fmt.format(content=content))
- elif label in ("header_image", "footer_image") and content:
- parts.append(content)
elif label in ("image", "header_image", "footer_image"):
parts.append(render_image_block(block, content))
elif label == "chart":
diff --git a/sdk/tests/test_skip_vlm_labels.py b/sdk/tests/test_skip_vlm_labels.py
index c876e91..3366911 100644
--- a/sdk/tests/test_skip_vlm_labels.py
+++ b/sdk/tests/test_skip_vlm_labels.py
@@ -167,24 +167,30 @@ def test_chart_otsl_is_converted_to_html():
@pytest.mark.parametrize("label", ["header_image", "footer_image"])
-def test_recognized_header_footer_images_are_kept_in_markdown(label):
[email protected]("image_path", ["", "imgs/page/header-footer.png"])
+def test_recognized_header_footer_images_are_kept_in_markdown(label, image_path):
from minicpmvocr.postprocess.markdown import assemble_markdown
prompt_map = _prompt_map({"skip_vlm_labels": ["image"]})
+ prompt_map["markdown_assembly"]["ignore_labels"] = []
assert prompts.get_element_cfg(prompt_map, label) is not None
blocks = [
- {"order": 0, "label": label, "content": "COURT OFFICE / Page 12"},
+ {"order": 0, "label": label, "content": "COURT OFFICE / Page 12", "image_path": image_path},
{"order": 1, "label": "text", "content": "Body text"},
]
- assert assemble_markdown(blocks, prompt_map) == "COURT OFFICE / Page 12\n\nBody text"
+ assert assemble_markdown(blocks, prompt_map) == (
+ f"![image]({image_path})\n\nCOURT OFFICE / Page 12\n\nBody text"
+ )
@pytest.mark.parametrize("label", ["header_image", "footer_image"])
def test_header_footer_images_without_text_keep_the_placeholder(label):
from minicpmvocr.postprocess.markdown import assemble_markdown
+ prompt_map = _prompt_map({})
+ prompt_map["markdown_assembly"]["ignore_labels"] = []
assert assemble_markdown(
- [{"label": label, "content": ""}], _prompt_map({})
+ [{"label": label, "content": ""}], prompt_map
) == "![image]()"