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) โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- 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.
- 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. - 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.
- 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-7bvia LM Studio. - Stage 2 โ Guarded Cleanup: Repairs OCR artifacts using
gemma4:12bvia 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:12bvia 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
.mdfiles 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
1234and loadallenai/olmocr-2-7b. - Ollama: Launch Ollama locally on port
11434and 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/v1andhttp://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!
- 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). - Archival Exporters (
apps/artifice-ocr/src/): Add writeback connectors for other archival software (e.g., Omeka, Arches, or custom IIIF manifests). - 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04fcd45398a0043420493aab71c4c9e6aa10266852bed4fec451f718e8e411f0
|
|
| MD5 |
3810ae6cb8bd733763b6d5d9479319fc
|
|
| BLAKE2b-256 |
2464ae619ea5bbd2a0b04be4b3a25a82ec0a3b8768a5ccfc34435e2a225c15fd
|
Provenance
The following attestation bundles were made for artifice_ocr-0.1.0.tar.gz:
Publisher:
publish.yml on Muggwoffin/artifice-suite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
artifice_ocr-0.1.0.tar.gz -
Subject digest:
04fcd45398a0043420493aab71c4c9e6aa10266852bed4fec451f718e8e411f0 - Sigstore transparency entry: 2357324409
- Sigstore integration time:
-
Permalink:
Muggwoffin/artifice-suite@332bea1bbfdd1325c34e542c0a5f2c1e55db6032 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Muggwoffin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@332bea1bbfdd1325c34e542c0a5f2c1e55db6032 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbdc3716cca227058017a62976194bf5ceed2b1886b077a2a77365b48f05380b
|
|
| MD5 |
f0103e51eeb12f879530f87332ad6150
|
|
| BLAKE2b-256 |
efbafcc04ea31292397d0ff88181ffd4522aa18832c593e39c8b3af741eb61cc
|
Provenance
The following attestation bundles were made for artifice_ocr-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Muggwoffin/artifice-suite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
artifice_ocr-0.1.0-py3-none-any.whl -
Subject digest:
fbdc3716cca227058017a62976194bf5ceed2b1886b077a2a77365b48f05380b - Sigstore transparency entry: 2357324507
- Sigstore integration time:
-
Permalink:
Muggwoffin/artifice-suite@332bea1bbfdd1325c34e542c0a5f2c1e55db6032 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Muggwoffin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@332bea1bbfdd1325c34e542c0a5f2c1e55db6032 -
Trigger Event:
workflow_dispatch
-
Statement type: