Skip to content

pipeline: support direct OCR for known table crops - #246

Open
agourakis82 wants to merge 2 commits into
zai-org:mainfrom
agourakis82:fix/table-numeric-punctuation-prompt
Open

agourakis82 wants to merge 2 commits into
zai-org:mainfrom
agourakis82:fix/table-numeric-punctuation-prompt

Conversation

@agourakis82

@agourakis82 agourakis82 commented Sep 29, 2026 •

Copy link
Copy Markdown

Summary

  • add self-hosted direct OCR mode for pre-cropped inputs via pipeline.enable_layout=false
  • add direct_task_type so callers can mark a crop as text, table, or formula without re-running layout detection
  • expose the mode through GlmOcr(...), glmocr.parse(...), and CLI --disable-layout --direct-task-type table
  • keep a table prompt guardrail to preserve decimal/thousands separators

Why

Issue #241 reports that an isolated table crop can lose decimal commas when it is processed as a fresh document. The issue asks for a way to submit a known region as a table without re-running layout detection on the crop.

This PR adds that explicit path: callers can send the crop directly to OCR as a full-page table region.

CLI:

glmocr parse table_crop.png --mode selfhosted --disable-layout --direct-task-type table

Python:

parser = GlmOcr(mode="selfhosted", enable_layout=False, direct_task_type="table")
result = parser.parse("table_crop.png")

Tests

  • /Users/demetriosagourakis/dev/GLM-OCR/.venv/bin/python -m pre_commit run --files glmocr/config.py glmocr/config.yaml glmocr/pipeline/_workers.py glmocr/pipeline/pipeline.py glmocr/api.py glmocr/cli.py glmocr/tests/test_unit.py
  • uv run --with pytest -m pytest glmocr/tests/test_unit.py::TestConfig glmocr/tests/test_unit.py::TestPipelineDirectOcr glmocr/tests/test_unit.py::TestGlmOcrParseStream glmocr/tests/test_unit.py::TestGlmOcrConstructor glmocr/tests/test_unit.py::TestPageLoader -q
  • uv run --with pytest -m pytest glmocr/tests/test_unit.py -q

Copilot AI balanced review requested due to automatic review settings September 29, 2026 21:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The change is narrowly scoped, and the test verifies the prompt reaches the request payload.

Review effort: Balanced
Findings: None

What changed in this PR

This PR adds a numeric-fidelity instruction to the packaged self-hosted table-recognition prompt and checks that it reaches outgoing requests.

Changes:

  • Ask table recognition to preserve decimal and thousands separators.
  • Test that the packaged prompt appears in a table OCR request.
File Description
glmocr/​tests/​test_unit.py Tests prompt delivery in the request payload.
glmocr/​config.yaml Updates the default table prompt.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@agourakis82 agourakis82 changed the title config: preserve numeric punctuation in table prompt pipeline: support direct OCR for known table crops Sep 29, 2026
@agourakis82

agourakis82 commented Sep 29, 2026 •

Copy link
Copy Markdown
Author

Updated this PR from a prompt-only guardrail into a direct known-crop OCR path.

New behavior:

  • pipeline.enable_layout=false skips layout detection in self-hosted mode.
  • pipeline.direct_task_type=table sends a pre-cropped table directly to OCR as one full-page table region.
  • CLI and Python APIs expose the mode via --disable-layout --direct-task-type table and GlmOcr(..., enable_layout=False, direct_task_type="table").

This now matches the use case from #241: submit an already-known table crop without re-running layout detection on it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants