Skip to main content

ArtificeOCR

Local-First Archival OCR, Preservation Cleanup & Translation for Historical Research

Part of the Artifice Suite โ€” Local-First, Model-Agnostic Software Harnesses for Humanities Research.


๐Ÿ›๏ธ Philosophy: The Software Harness vs. The Chatbot

ArtificeOCR is a local-first pipeline built specifically for processing, cleaning, structuring, translating, and publishing historical documentsโ€”engineered for archival research, not demos. It operates around Joseph Weizenbaumโ€™s anti-ELIZA principle: software should perform deterministic computing tasks, and AI models should be invoked strictly as guarded text transformation engines.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ArtificeOCR Harness โ”‚ โ”‚ โ”‚ โ”‚ 1. Vision OCR Extraction (olmocr-2-7b via LM Studio) โ”‚ โ”‚ 2. Guarded Text Cleanup (Gemma 4 via Ollama - Capitalisation/Umlaut Guard)โ”‚ โ”‚ 3. Guarded Text Structuring (Gemma 4 via Ollama - Word-for-Word Guard) โ”‚ โ”‚ 4. Historical Translation (TranslateGemma via Ollama - German to English)โ”‚ โ”‚ 5. Multi-Format Export (PDF / LudwigLang Markdown / Tropy Writeback) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

  1. Deterministic Execution, No Conversational Noise: ArtificeOCR never "chats" about documents. It processes images or archival manifests through a strict multi-stage pipeline and outputs structured JSON, Markdown, or PDF assets.
  2. Preservation Over Prettiness (The Guard System): Historical textsโ€”especially fragmentary 1920sโ€“1940s German archival recordsโ€”contain fragile spellings, capitalized nouns, and OCR artifacts. The cleanup and structuring stages are strictly guarded. If a model attempts to alter valid words, capitalized German nouns, or delete text beyond tight thresholds, the modification is rejected and saved as rejected_* for reviewโ€”nothing is silently lost or rewritten.
  3. Local-First & Archival Privacy: All vision and language models run locally on your GPU via LM Studio and Ollama. Confidential archival findings and copyright-restricted manuscript photos never leave your hardware.
  4. Editorial Visual Identity: Built using The New Masses Design System (packages/shared-ui)โ€”a warm, paper-and-ink interface inspired by 1930s radical editorial design and Soviet Constructivism.

โœจ Core Capabilities

1. Guarded 4-Stage Processing Pipeline

Runs entirely on local GPU hardware with complete JSON metadata outputs (prompts, confidence, guard results, timings) at every stage:

  • Stage 1 โ€” Vision OCR: Converts document scans and photos into raw text using allenai/olmocr-2-7b via LM Studio.
  • Stage 2 โ€” Guarded Cleanup: Repairs OCR artifacts using gemma4:12b via Ollama. Guarded against word deletions, umlaut transliteration corruptions (ueber $\rightarrow$ รผber), and loss of capitalized German nouns.
  • Stage 3 โ€” Guarded Structuring: Adds paragraph breaks for human readability using gemma4:12b via Ollama. Guarded by word-for-word equalityโ€”only newline insertions are allowed.
  • Stage 4 โ€” Historical Translation: Optional translation (e.g., German to English) using specialized models (translategemma:4b) via Ollama.

2. Deep Tropy Archive Integration

Directly connects to Tropy historical research archives:

  • Read-Only Browsing: Inspect Tropy projects, lists, tags, items, and photos directly from the CLI or UI without modifying database state.
  • Manifest Processing: Ingest items by list ID, tag, or item ID, mirroring Tropy's item/page structure on disk.
  • Safe Writeback: Writes cleaned, structured, or translated texts back into Tropy as notes or native transcriptions with preview verification and automatic timestamped project backups.

3. Multi-Format Publishing Exports

  • Typeset PDF Compilation: Generates continuous reading PDFs with section headings per item, provenance page markers ([page1]), and Playfair/Libre Baskerville typography.
  • LudwigLang Markdown Export: Exports cleaned and structured text as .md files pre-configured with front-matter metadata for the LudwigLang editorial web publisher.
  • Structured JSON Data: Full audit logs for every page, preserving raw OCR text, accepted cleanup, rejected model attempts, and guard status logs.

๐Ÿ›ก๏ธ The Guard System (Preservation Details)

Stage Guard Implementation Protection Objective
Cleanup _guard.check_cleanup Protects German capitalized nouns, forbids umlaut transliteration (ueber $\rightarrow$ รผber), enforces word deletion thresholds (default $\le$ 2 words), and maintains length ratios ($\ge$ 97% letters retained).
Structure _guard.check_structure_only Enforces word-for-word equalityโ€”only newlines may be added. Any word alteration triggers a rejection, retaining raw text and saving the attempt as rejected_structured_text.

๐ŸŽจ Design System (packages/shared-ui)

All visual interfaces in ArtificeOCR adhere to The New Masses Design System:

  • Palette: Warm cream paper (#f6f3ea), deep warm black ink (#1b1813), Esperanto green accents (#2f7d45), and antique gold highlights (#bf9b30).
  • Typography: Playfair Display (Display/Headings), Libre Baskerville (Body/Manuscripts), and Archivo (UI Labels/Buttons).
  • Surface Depth & Motion: Paper-like diffused shadows (shadow-paper), card lifts (4px), rule draw-in animations, and tactile button presses.

๐Ÿ“‚ Monorepo Architecture

ArtificeOCR is located at apps/artifice-ocr within the Artifice Suite monorepo and shares core dependencies with partner applications:

artifice-suite/
โ”œโ”€โ”€ apps/
โ”‚   โ””โ”€โ”€ artifice-ocr/
โ”‚       โ”œโ”€โ”€ src/
โ”‚       โ”‚   โ”œโ”€โ”€ cli.py                 # Typer CLI entry point
โ”‚       โ”‚   โ”œโ”€โ”€ pipeline.py            # Stage orchestration (shared by CLI/GUI/Web)
โ”‚       โ”‚   โ”œโ”€โ”€ jobs.py                # Threaded JobRunner with pause/cancel
โ”‚       โ”‚   โ”œโ”€โ”€ history.py             # SQLite run history
โ”‚       โ”‚   โ”œโ”€โ”€ tropy.py               # Read-only Tropy archive parser
โ”‚       โ”‚   โ”œโ”€โ”€ tropy_write.py         # Tropy notes/transcriptions writeback
โ”‚       โ”‚   โ”œโ”€โ”€ pdf_export.py          # PDF compilation with structuring
โ”‚       โ”‚   โ”œโ”€โ”€ export_ludwiglang.py   # LudwigLang Markdown export
โ”‚       โ”‚   โ”œโ”€โ”€ _guard.py              # Content preservation guards
โ”‚       โ”‚   โ”œโ”€โ”€ _diff.py               # Diff & marker highlighting
โ”‚       โ”‚   โ”œโ”€โ”€ stages/                # OCR, Cleanup, Structure, Translate modules
โ”‚       โ”‚   โ””โ”€โ”€ web/                   # FastAPI server & vanilla JS SPA
โ”‚       โ”œโ”€โ”€ tests/                     # Pytest suite
โ”‚       โ””โ”€โ”€ README.md
โ””โ”€โ”€ packages/
    โ”œโ”€โ”€ shared-ui/                     # The New Masses CSS tokens & web components
    โ”œโ”€โ”€ model-harness/                 # BYOM connectors (Ollama/LM Studio)
    โ””โ”€โ”€ core-types/                    # Shared TypeScript & Python data interfaces

๐Ÿš€ Setup & Hardware Requirements

Prerequisites & Dependencies

Ensure Python 3.11+ is installed. From the monorepo root:

# Install shared packages and app in editable mode
pip install -e packages/core-types -e packages/model-harness -e packages/shared-ui -e apps/artifice-ocr[web]

Engine Setup & Model Provisioning

  • LM Studio: Launch LM Studio locally on port 1234 and load allenai/olmocr-2-7b.
  • Ollama: Launch Ollama locally on port 11434 and pull required models:
    ollama pull gemma4:12b
    ollama pull translategemma:4b
    

Cross-Platform & macOS Apple Silicon Notes

  • Linux / Windows (CUDA): Native GPU acceleration via CUDA drivers.
  • macOS (Apple Silicon Metal): Run LM Studio and Ollama natively on the host to leverage Apple Metal Performance Shaders (MPS) and Unified Memory. If running containers via Docker, connect to host models using http://host.docker.internal:1234/v1 and http://host.docker.internal:11434.

Hardware Recommendations

Tier GPU VRAM System RAM Notes
Recommended 16 GB (RTX 4060 Ti 16G / 4070+) 32 GB All models resident simultaneously.
Minimum (GPU) 12 GB (RTX 3060 / 4070) 16 GB Requires sequential model offloading between stages.
Apple Silicon 24 GB Unified (M3/M4 Pro) โ€” Unified memory handles vision and LLM weights comfortably.

๐Ÿ–ฅ๏ธ Usage & Interfaces

1. CLI Commands

# Process single image through full pipeline:
artifice-ocr pipeline path/to/document.png --skip-translate

# Execute individual processing stages:
artifice-ocr ocr path/to/image.png
artifice-ocr cleanup output/raw_ocr/text/file.txt
artifice-ocr structure output/structured/text/file.txt
artifice-ocr translate output/structured/text/file.txt

# Tropy Archive Workflows:
artifice-ocr tropy-browse "path/To/Archive.tropy"
artifice-ocr tropy "path/To/Archive.tropy" --list-id 3 --tag resistance

# Export Compilation:
artifice-ocr compile-pdf output/cleaned/text/Collection --stage cleaned
artifice-ocr export-md output/cleaned/text/Collection --author "Fritz Eberhard" --date "1936-1939"

2. Web UI (Recommended)

Launches the FastAPI server with The New Masses editorial layout, real Google Fonts, and Server-Sent Events (SSE) live progress tracking:

python -m artifice_ocr.web
# โ†’ Access at http://127.0.0.1:8765

โš™๏ธ Configuration

Set defaults via configs/default.yaml or environment variables:

Variable / Key Default Description
lmstudio_base_url http://localhost:1234/v1 LM Studio vision OCR endpoint
ollama_host http://localhost:11434 Ollama LLM endpoint
ocr_model allenai/olmocr-2-7b Vision model used for OCR stage
cleanup_model gemma4:12b Model used for guarded cleanup
translate_model translategemma:4b Model used for translation
cleanup_guard true Enable German noun / umlaut protection guard
structure_guard true Enable word-for-word equality guard
ollama_think false Disable reasoning tokens (13ร— speedup during cleanup)

๐Ÿ› ๏ธ Open-Source Extension Points

We welcome contributions from historians, archivists, and software engineers!

  1. Custom Stage Guards (apps/artifice-ocr/src/_guard.py): Implement specialized content-preservation rules for specific languages or historical writing styles (e.g., Fraktur font artifacts, early modern orthography).
  2. Archival Exporters (apps/artifice-ocr/src/): Add writeback connectors for other archival software (e.g., Omeka, Arches, or custom IIIF manifests).
  3. Vision OCR Connectors (apps/artifice-ocr/src/stages/ocr.py): Extend vision stage adapters to support additional local vision-language models.

๐Ÿงช Testing

Run the full pytest suite covering CLI commands, guard validation logic, Tropy read/write, and export compilers:

pytest apps/artifice-ocr/tests/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

artifice_ocr-0.1.0.tar.gz (663.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

artifice_ocr-0.1.0-py3-none-any.whl (629.5 kB view details)

Uploaded Python 3

File details

Details for the file artifice_ocr-0.1.0.tar.gz.

File metadata

  • Download URL: artifice_ocr-0.1.0.tar.gz
  • Upload date:
  • Size: 663.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for artifice_ocr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 04fcd45398a0043420493aab71c4c9e6aa10266852bed4fec451f718e8e411f0
MD5 3810ae6cb8bd733763b6d5d9479319fc
BLAKE2b-256 2464ae619ea5bbd2a0b04be4b3a25a82ec0a3b8768a5ccfc34435e2a225c15fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for artifice_ocr-0.1.0.tar.gz:

Publisher: publish.yml on Muggwoffin/artifice-suite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file artifice_ocr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: artifice_ocr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 629.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for artifice_ocr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fbdc3716cca227058017a62976194bf5ceed2b1886b077a2a77365b48f05380b
MD5 f0103e51eeb12f879530f87332ad6150
BLAKE2b-256 efbafcc04ea31292397d0ff88181ffd4522aa18832c593e39c8b3af741eb61cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for artifice_ocr-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Muggwoffin/artifice-suite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page