How t0mer/ocr-docker works
Main Components
• User / Browser
The user interacts via a web browser, uploads images/PDFs, and views extracted text.
• Frontend (Flask-served Static UI)
ocr/templates/index.html + ocr/css/*.css + ocr/js/*.js + ocr/fonts/*
– Delivers the upload form and displays results.
• Backend (Flask Application)
ocr/ocr.py
– Defines routes (e.g. POST /upload), orchestrates preprocessing, calls OCR, returns JSON or renders HTML.
– Uses Python libraries: Flask, Loguru (logging), PyYAML (config), Pillow & image (image I/O), pytesseract (binding).
• Image / PDF Preprocessing
– Ghostscript for PDF→image conversion.
– ImageMagick for image cleanup, format conversion, resizing.
• OCR Engine
– Tesseract-OCR binary, invoked via pytesseract or subprocess.
– Tessdata language models (traineddata/*).
• Containerization & Deployment
– Dockerfile builds image with all dependencies.
– docker-compose.yaml defines service, port mapping (8080).
• CI / QA
– .github/workflows/docker-image.yml (build & push)
– .github/workflows/sonarcloud.yml (static analysis)
Relationships & Data Flow
User → HTTP Request → Flask App →
• If PDF: Ghostscript → images → ImageMagick → cleaned images →
• If image: optional ImageMagick →
→ Tesseract (with selected traineddata) → extracted text → Flask App → HTTP Response → User.
Architectural Patterns & Principles
• Separation of Concerns:
• Static UI assets served separately from core logic in ocr.py.
• Preprocessing, OCR, and I/O each encapsulated in distinct modules or subprocess calls.
• 12-Factor / Twelve-Factor-App (in container):
• Config via environment variables (in Docker).
• Dependencies declared in requirements, image deterministic.
• Stateless Processing:
• No persistent DB; ephemeral files only.
• Logs via Loguru.
Technologies & Frameworks
• Flask (web server / routing)
• Python libs: Pillow, pytesseract, Loguru, PyYAML
• CLI tools: Tesseract-OCR, Ghostscript, ImageMagick
• Container: Docker, Docker-Compose
• CI: GitHub Actions, SonarCloud