- Jupyter Notebook 99.4%
- Python 0.5%
| .vscode | ||
| test | ||
| .editorconfig | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| CHANGELOG.md | ||
| CODEOWNERS | ||
| conftest.py | ||
| content_extraction.py | ||
| detect_language.py | ||
| docker-compose.yaml | ||
| Dockerfile | ||
| language_map.py | ||
| LICENSE | ||
| main.py | ||
| parse.py | ||
| poetry.lock | ||
| pyproject.toml | ||
| README.md | ||
| renovate.json | ||
| test.ipynb | ||
| test_detect_language.py | ||
| test_main.py | ||
| test_parse.py | ||
Extract Page Interpreted Content OCR
A Python worker that extracts text content from page images using Tesseract OCR via the tesserocr Python wrapper. This worker processes document page images to extract text with confidence scores, language detection, and detailed text structure analysis.
Features
- High-quality text extraction using Tesseract OCR engine
- Automatic language detection for extracted text
- Text structure analysis (text lines, words, block types)
- Confidence scoring for extracted content
- Integration with RabbitMQ for message queuing
- MinIO support for object storage
- Docker deployment ready
Getting Started
Local Installation
-
Clone the repository:
git clone https://gitlab.com/logius/nldoc/worker/page-interpreted-content-ocr.git cd page-interpreted-content-ocr -
Install system dependencies:
macOS:
brew install conda tesseract export PATH="/opt/homebrew/anaconda3/bin:$PATH" conda install -c conda-forge tesserocrLinux:
apt-get update && apt-get install -y tesseract-ocr libtesseract-dev libleptonica-dev -
Install Poetry (dependency management):
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install -
Install shell plugin:
poetry self add poetry-plugin-shell -
Activate virtual environment:
poetry shell
Running the Worker
Using Docker Compose (Recommended)
-
Ensure Docker and Docker Compose are installed (Installation Guide)
-
Start the services:
docker compose up -
Access the management interfaces:
- RabbitMQ Console:
http://localhost:15672/ - MinIO Console:
http://localhost:9001/
- RabbitMQ Console:
-
Once the
docker compose upcommand has been exited using Ctrl+C, all containers relative to this instance will have shut down automatically.
Running Directly
To run the worker without Docker:
python3 main.py
Required environment variables:
AMQP_HOST: RabbitMQ host (default: 127.0.0.1)AMQP_PORT: RabbitMQ port (default: 5672)AMQP_USER: RabbitMQ usernameAMQP_PASS: RabbitMQ passwordEXCHANGE: RabbitMQ exchange name (default: page-interpretedcontent)MINIO_HOST: MinIO host (default: 127.0.0.1)MINIO_PORT: MinIO port (default: 9000)MINIO_ACCESS_KEY: MinIO access keyMINIO_SECRET_KEY: MinIO secret keyMINIO_USE_SSL: Use SSL for MinIO connection (default: False)
For additional configuration options, refer to the Python base worker config.
Testing and Development
Run the test suite:
pytest
The worker includes:
- Unit tests for language detection (
test_detect_language.py) - Unit tests for main worker functionality (
test_main.py) - Unit tests for OCR parsing (
test_parse.py)
How It Works
The worker processes page images through the following pipeline:
- Image Processing: Opens the provided page image using PIL
- OCR Analysis: Uses Tesseract OCR to analyze the image layout and extract text
- Language Detection: Automatically detects the language of extracted text
- Text Structure Analysis: Extracts detailed information about:
- Text lines with bounding boxes and confidence scores
- Individual words within each line
- Block types (flowing text, headings, captions, etc.)
- Text attributes and positioning
- Result Publishing: Returns structured content with confidence metrics
Deployment
Docker Images
Pre-built Docker images are available in our container registry.
Run the latest version:
docker run --rm registry.gitlab.com/logius/nldoc/worker/page-interpreted-content-ocr:latest
Documentation
License
This project is licensed under the European Union Public License 1.2 - see LICENSE for details.
Acknowledgements
- Tesseract OCR for the powerful OCR engine
- tesserocr for the Python wrapper