From 77be889c58e34653f732ac328d2d099f774da391 Mon Sep 17 00:00:00 2001 From: John Wooten <60260750+JFWooten4@users.noreply.github.com> Date: Sat, 28 Nov 2026 06:34:32 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A7=20Forward=20selected=20Ollama?= =?UTF-8?q?=20models=20through=20OCR=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Accept explicit extraction and review model arguments and preserve them when resuming review. Cover forwarding in the existing shell checkpoint regression. Co-authored-by: ChatGPT 6.2 --- ocr-scanned-pdf.sh | 16 +++++++++++++--- tests/test_ocr_shell_startup.py | 5 +++-- 2 files changed, 16 insertions(+), 5 deletions(-) mode change 100644 => 100755 ocr-scanned-pdf.sh diff --git a/ocr-scanned-pdf.sh b/ocr-scanned-pdf.sh old mode 100644 new mode 100755 index 14b45e0..8d31c59 --- a/ocr-scanned-pdf.sh +++ b/ocr-scanned-pdf.sh @@ -4,7 +4,7 @@ set -euo pipefail usage() { cat <<'EOF' -Usage: ./ocr-scanned-pdf.sh INPUT.pdf [OUTPUT.pdf] [--skip-text|--force-ocr] [--ai-review] [metadata options] +Usage: ./ocr-scanned-pdf.sh INPUT.pdf [OUTPUT.pdf] [--skip-text|--force-ocr] [--ai-review] [--extract-model MODEL] [--review-model MODEL] [metadata options] Create a searchable, tagged PDF from an English-language scanned PDF. If OUTPUT.pdf is omitted, the output is written beside the input as @@ -13,7 +13,8 @@ written beside the output for searching and review. OCR lines are grouped into logical paragraphs, and likely section headings are tagged as H1 or H2. Use --skip-text for mixed documents to preserve pages that already have text. Use --force-ocr to replace the text layer on every page, including existing OCR. -Use --ai-review to apply the local DeepSeek and SEC OCR review models afterward. +Use --ai-review to apply local Ollama OCR extraction and review afterward. +Use --extract-model and --review-model to override the default Ollama models. Use --source-url URL to preserve the original document link in PDF metadata. Add optional --title, --author, --description, --tags (or --keywords), --publisher, --rights, --language, and --identifier values during enhancement. @@ -37,6 +38,7 @@ if [[ $# -gt 0 && "$1" != --* ]]; then fi ocr_options=() metadata_options=() +review_options=() ocr_mode="" ai_review=false while [[ $# -gt 0 ]]; do @@ -50,6 +52,14 @@ while [[ $# -gt 0 ]]; do ocr_options+=("$1") ;; --ai-review) ai_review=true ;; + --extract-model|--review-model) + if [[ $# -lt 2 || -z "$2" || "$2" == --* ]]; then + printf "Provide a model after %s.\n" "$1" >&2 + exit 2 + fi + review_options+=("$1" "$2") + shift + ;; --source-url) if [[ $# -lt 2 || -z "$2" || "$2" == --* ]]; then printf 'Provide a URL after --source-url.\n' >&2 @@ -209,7 +219,7 @@ fi if "$ai_review"; then printf 'PDF_MAGIC_PROGRESS review %s\n' "$input_pages" "${tagger_python[@]}" "$script_dir/ollama-review-ocr.py" \ - "$tagged_output" "$initial_report" "$review_report" ${resume_review[@]+"${resume_review[@]}"} + "$tagged_output" "$initial_report" "$review_report" ${resume_review[@]+"${resume_review[@]}"} ${review_options[@]+"${review_options[@]}"} reviewed_output="$tagging_dir/reviewed.pdf" printf 'PDF_MAGIC_PROGRESS finalizing\n' "${tagger_python[@]}" "$tagger" \ diff --git a/tests/test_ocr_shell_startup.py b/tests/test_ocr_shell_startup.py index 25e5ddb..9265485 100644 --- a/tests/test_ocr_shell_startup.py +++ b/tests/test_ocr_shell_startup.py @@ -45,7 +45,7 @@ def test_interrupted_review_reuses_ocr_and_saved_pages(self): (directory / "ollama-review-ocr.py").write_text( "from pathlib import Path\n" "import sys\n" - "assert sys.argv[4:] == ['--resume']\n" + "assert sys.argv[4:] == ['--resume', '--extract-model', 'custom-ocr:latest', '--review-model', 'custom-review:latest']\n" "checkpoint = Path(sys.argv[3])\n" "if not checkpoint.exists():\n" " checkpoint.write_text('{\"page\":1}\\n')\n" @@ -56,7 +56,8 @@ def test_interrupted_review_reuses_ocr_and_saved_pages(self): ) env = {**os.environ, "PATH": str(commands) + os.pathsep + os.environ["PATH"], "PDF_MAGIC_REVIEW_CHECKPOINT": str(checkpoint)} - command = ["/bin/bash", str(script), str(source), str(output), "--force-ocr", "--ai-review"] + command = ["/bin/bash", str(script), str(source), str(output), "--force-ocr", "--ai-review", + "--extract-model", "custom-ocr:latest", "--review-model", "custom-review:latest"] first = subprocess.run(command, env=env, capture_output=True, text=True) self.assertEqual(first.returncode, 47, first.stderr) self.assertFalse(output.exists()) From 6edd13039e711d2adca1416594d960a8041369d5 Mon Sep 17 00:00:00 2001 From: John Wooten <60260750+JFWooten4@users.noreply.github.com> Date: Sat, 28 Nov 2026 06:36:14 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=96=8B=EF=B8=8F=20Document=20OCR=20mo?= =?UTF-8?q?del=20overrides?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Explain the new extraction and review flags and keep the original shell script file mode. Co-authored-by: ChatGPT 6.2 --- OCR.md | 5 +++++ ocr-scanned-pdf.sh | 0 2 files changed, 5 insertions(+) mode change 100755 => 100644 ocr-scanned-pdf.sh diff --git a/OCR.md b/OCR.md index 4cd75d9..99163a6 100644 --- a/OCR.md +++ b/OCR.md @@ -38,6 +38,11 @@ and apply the local AI review in one run: ./ocr-scanned-pdf.sh SOURCE.pdf NEW-AI-OCR.pdf --force-ocr --ai-review ``` +To use different locally installed Ollama models for the two stages, add +`--extract-model MODEL` and `--review-model MODEL` to the same command. Both +models must support the image input and output format expected by their stage. +The default models are unchanged when the options are omitted. + This is the workflow used by the viewer's Enhance button. Force OCR rasterizes pages and replaces existing text in the new copy; the source remains unchanged. The AI pass reviews all pages with recognized blocks, applies reviewed text and diff --git a/ocr-scanned-pdf.sh b/ocr-scanned-pdf.sh old mode 100755 new mode 100644