A small, runnable OCR and speech-to-text cleanup pipeline. The deterministic core has no OCR, ASR, or LLM dependency, so it installs quickly and is tested in CI. Tesseract, Whisper, and Ollama are optional backends.
This repository previously advertised OCR engines, text detectors, and ASR models that were placeholders. Those paths have been removed. Everything listed below is implemented in this repository.
| Path | Requirements | CI coverage |
|---|---|---|
| Text normalization, chunking, correction fallback | Core install | Yes, Python 3.11–3.13 |
| Image OCR | Core install + Tesseract binary | Runs when Tesseract is present; skips automatically when absent |
| PDF OCR | .[ocr] + Tesseract + Poppler |
Not run in CI |
| Speech-to-text | .[asr] + first-run model download |
Not run in CI |
| LLM correction | .[llm] + local Ollama server |
Not run in CI |
| Demo CLI | Core install; OCR used when Tesseract is present | Yes |
The workflow does not install Tesseract, Whisper, Ollama, or GPU libraries. There are no benchmark claims, hosted service, or fake build badges.
Requires Python 3.11 or newer.
git clone https://github.com/PStarH/LLM-boost-recognition.git
cd LLM-boost-recognition
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -e .This installs Pillow, the llm_boost package, and the llm-boost console
script. The core provides text cleanup, chunking, sample-image generation, and
the demo command without requiring OCR or ASR tools.
Image OCR calls the Tesseract command-line binary directly; no Python OCR
package is needed. The ocr extra adds PDF input through pdf2image.
python -m pip install -e ".[ocr]"Install Tesseract and the English language pack:
# macOS
brew install tesseract
# Debian / Ubuntu
sudo apt-get update
sudo apt-get install tesseract-ocr
# Windows: use the UB Mannheim installer and add Tesseract to PATH
# https://github.com/UB-Mannheim/tesseract/wikiIf Tesseract is installed outside PATH, point TESSERACT_CMD at the
executable. Additional languages require the corresponding Tesseract language
pack, for example brew install tesseract-lang or
sudo apt-get install tesseract-ocr-deu, then pass --language deu. Combine
installed packs with --language eng+deu.
PDF input also requires Poppler, for example brew install poppler or
sudo apt-get install poppler-utils.
python -m pip install -e ".[asr]"
python -m llm_boost voice path/to/audio.wav --model baseThis installs faster-whisper. The first transcription downloads the selected
model (the base model is roughly 150 MB) from Hugging Face and caches it. CPU
works; CUDA requires a compatible CTranslate2/CUDA installation. ffmpeg is not
needed for formats PyAV can decode, but installing it avoids decoder surprises
for uncommon formats.
python -m pip install -e ".[llm]"
ollama serve
ollama pull llama3.2
python -m llm_boost ocr image.png --llmThe LLM receives text over localhost and returns a corrected candidate. If the server, model, or response is unavailable, the CLI prints a warning and falls back to deterministic cleanup.
python -m pip install -e ".[dev]"
pytest
ruff check .
ruff format --check .The requirements*.txt files contain the same dependency sets for environments
that install dependencies separately. Use pip install -e . first if you want
the package and the llm-boost command.
The demo generates a sample image with Pillow, runs OCR when Tesseract is available, and prints both the raw and cleaned text. It does not need a sample PDF or any model download.
llm-boost demo
# equivalent module and compatibility launchers
python -m llm_boost demo
python -m llm_boost --demo
python OCR.pyExample output on macOS with Tesseract 5.5 (temporary path replaced):
Sample image: <temporary directory>/sample.png
--- raw text ---
The quick brown fox jumps over the lazy dog.
OCR turns pictures of text into editable text.
Generated with Pillow - no PDF required.
--- cleaned text ---
The quick brown fox jumps over the lazy dog.
OCR turns pictures of text into editable text.
Generated with Pillow - no PDF required.
Without Tesseract, the demo still generates the image and cleans the known sample text, but clearly reports that OCR was not run.
# Image
python -m llm_boost ocr scanned-page.png
# PDF (needs the ocr extra and Poppler)
python -m llm_boost ocr document.pdf --language eng --psm 6
# Include optional Ollama correction
python -m llm_boost ocr scanned-page.png --llm --llm-model llama3.2
# Speech (needs the asr extra and a model download)
python -m llm_boost voice recording.wav --model small --language en
# Compatibility launchers
python OCR.py path/to/image.png
python Voice-Recognition.py path/to/audio.wavpython OCR.py with no arguments runs the demo. python Voice-Recognition.py
without an audio path prints the normal usage error. The console script accepts
the same subcommands as python -m llm_boost.
llm_boost/
text.py normalization, allowlist OCR fixes, chunking, correction fallback
ocr.py Tesseract CLI wrapper, sample-image rendering, optional PDF input
voice.py optional faster-whisper wrapper with actionable errors
llm.py optional Ollama HTTP client
cli.py argparse commands: demo, ocr, voice
OCR.py compatibility launcher
Voice-Recognition.py compatibility launcher
tests/ pytest suite
Data flow:
image/PDF --(Tesseract)------> raw text -----+
|
audio --(faster-whisper)-----> transcript ---+
|
v
normalize -> allowlist fixes
|
+--------------+--------------+
| |
v v
optional Ollama correction deterministic fallback
| |
+--------------+--------------+
|
v
cleaned stdout
Design rules:
- Optional dependencies are imported lazily. Importing the package never requires Tesseract, Whisper, Ollama, or network access.
- Missing system tools produce an error that names the install command.
- An optional LLM response is accepted only if it is a non-empty string that is not suspiciously shorter than the input. Any failure returns the deterministic result instead of breaking the command.
- Chunking is character-based and covers every input word. It does not pretend to be model-token-aware.
python -m pip install -e ".[dev]"
pytestThe suite covers normalization, line-broken hyphenation, common OCR word fixes, chunk boundaries and overlap, correction fallback behavior, sample-image generation, the demo CLI, missing-file errors, and optional-backend error messages. The Tesseract end-to-end test skips automatically when the binary or language pack is absent.
GitHub Actions runs lint plus the core and demo on Python 3.11, 3.12, and 3.13 without installing Tesseract, Whisper, Ollama, or GPU libraries. The OCR test is skipped when the runner does not provide Tesseract.
- OCR quality is Tesseract's quality. Clean, high-contrast, horizontal text works best. Handwriting, complex tables, formulas, and layout reconstruction are not implemented.
engis the default and the only language pack exercised in this repository. Other languages need their pack installed; the CLI reports available languages when one is missing.- PDF OCR requires Poppler and the
ocrextra. Only rasterization is handled; embedded PDF text layers are ignored. - Speech-to-text is optional and not exercised in CI. It downloads a Whisper
model on first use, is CPU-intensive without a GPU, and is limited to what
faster-whispersupports. GPU execution requires the correct CUDA/CTranslate2 setup and is not tested here. - LLM correction is not benchmarked and is not a grammar or fact checker. It sends the whole input to a local Ollama model and may hit context limits; the command falls back to deterministic cleanup rather than truncating silently.
- Chunking uses characters, not model tokens. Large inputs may need smaller chunk sizes when used with a specific model.
- There is no explicit CI job that installs Tesseract or Poppler on Windows or Linux; the OCR test only runs if the runner image happens to provide Tesseract. There is no performance benchmark and no support for the removed EAST/CRAFT/DeepSpeech placeholders.
GPL-3.0-only. See LICENSE.
Pillow, Tesseract OCR, Poppler/pdf2image, faster-whisper, CTranslate2, Ollama, and pytest.