Skip to content

fix(layout): add id2label to LayoutConfig and guard missing label_task_mapping#104

Open
Manitchahar wants to merge 2 commits intozai-org:mainfrom
Manitchahar:fix/layout-config-defaults
Open

fix(layout): add id2label to LayoutConfig and guard missing label_task_mapping#104
Manitchahar wants to merge 2 commits intozai-org:mainfrom
Manitchahar:fix/layout-config-defaults

Conversation

@Manitchahar
Copy link

What this PR does

Fixes two layout-mode crashes when using custom config files:

  1. LayoutConfig did not declare id2label, but glmocr/layout/layout_detector.py
    reads config.id2label.

    • Added: id2label: Optional[Dict[Union[int, str], str]] = None in glmocr/config.py.
  2. layout_detector.py assumed label_task_mapping is always present and called
    .items() on it.

    • Added guard in start() to fallback when missing:
      • logs a warning
      • sets label_task_mapping = {"text": list(self.id2label.values())}

Reproduction

  1. Create custom config with layout enabled but without id2label and label_task_mapping.
  2. Run: glmocr parse "image.png" --config custom.yaml
  3. Before: AttributeError crash. After: pipeline continues safely.

Files changed

  • glmocr/config.py (+1 line)
  • glmocr/layout/layout_detector.py (+5 lines)

Notes

Scope is intentionally minimal (2 files only), with no behavior change unless those config fields are missing.

Copilot AI review requested due to automatic review settings February 21, 2026 21:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes two layout-mode crashes when using custom config files by adding the missing id2label field to LayoutConfig and adding a guard for missing label_task_mapping in the layout detector initialization.

Changes:

  • Added id2label field to LayoutConfig to prevent AttributeError when reading config.id2label
  • Added guard in layout_detector.py to handle missing label_task_mapping with a sensible default fallback

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
glmocr/config.py Adds id2label field to LayoutConfig class definition
glmocr/layout/layout_detector.py Adds guard to handle missing label_task_mapping with default fallback to text task type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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