How text2knowledge/doctr-labeler works
Project type and purpose
• This is an open-source, Python-based desktop annotation tool (“docTR Labeler”) for OCR data.
Main components and directories
• CLI launcher (labeler/cli/main.py)
• GUI layer (labeler/views/gui.py)
• Canvas view (labeler/views/canvas.py)
• Drawing primitives & domain model (labeler/components/*.py: polygon, draw_poly)
• Automation & auto-annotation (labeler/automation/auto_labeler.py, tight_box.py)
• Utilities (labeler/utils/data_utils.py for preparing folders, hub_factory.py for HF uploads)
• Logger (labeler/logger.py)
• Data store (on-disk image folder + labels.json)
• External services:
• OnnxTR/DocTR inference (via automation modules)
• Hugging Face dataset hub (via hub_factory)
Relationships and data flows
• User invokes either
• CLI → labeler.cli.main → GUI or
• Programmatic API → GUI
• GUI instantiates Canvas, loads images from the data folder
• Auto-annotation: user triggers “auto adjust” → automation.auto_labeler calls OnnxTR detector & recognizer → returns polygons → Canvas updates view/model
• Save: GUI/Canvas serializes annotations to labels.json on disk
• (Optional) HF upload: utils.hf_upload_dataset reads images+labels.json → hub_factory pushes to remote
Architectural patterns and design principles
• MVC-ish separation:
• Views: GUI + Canvas
• Model: Polygon objects, internal state
• Controller: CLI entrypoint & automation logic
• Factory pattern: hub_factory creates HF dataset clients
• Plugin-style extensibility: detection/recognition architectures picked via environment variables