pyocr-toolkit 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. pyocr_toolkit/__init__.py +3 -0
  2. pyocr_toolkit/__main__.py +3 -0
  3. pyocr_toolkit/api.py +603 -0
  4. pyocr_toolkit/cli.py +315 -0
  5. pyocr_toolkit/compare.py +142 -0
  6. pyocr_toolkit/config.py +86 -0
  7. pyocr_toolkit/credentials.py +108 -0
  8. pyocr_toolkit/documents.py +326 -0
  9. pyocr_toolkit/env.example +48 -0
  10. pyocr_toolkit/jobs.py +205 -0
  11. pyocr_toolkit/llm/__init__.py +44 -0
  12. pyocr_toolkit/llm/anthropic_provider.py +188 -0
  13. pyocr_toolkit/llm/base.py +126 -0
  14. pyocr_toolkit/llm/catalog.py +337 -0
  15. pyocr_toolkit/llm/gemini_provider.py +98 -0
  16. pyocr_toolkit/llm/openai_provider.py +183 -0
  17. pyocr_toolkit/llm/prompts.py +61 -0
  18. pyocr_toolkit/search.py +88 -0
  19. pyocr_toolkit/service.py +269 -0
  20. pyocr_toolkit/static/common.js +538 -0
  21. pyocr_toolkit/static/compare.js +157 -0
  22. pyocr_toolkit/static/document.js +89 -0
  23. pyocr_toolkit/static/jobs.js +13 -0
  24. pyocr_toolkit/static/library.js +28 -0
  25. pyocr_toolkit/static/models.js +98 -0
  26. pyocr_toolkit/static/providers.js +44 -0
  27. pyocr_toolkit/static/reader.js +78 -0
  28. pyocr_toolkit/static/search.js +34 -0
  29. pyocr_toolkit/static/styles.css +819 -0
  30. pyocr_toolkit/static/workspace.js +420 -0
  31. pyocr_toolkit/static/workspaces.js +81 -0
  32. pyocr_toolkit/templates/_doc_card.html +30 -0
  33. pyocr_toolkit/templates/_doctabs.html +14 -0
  34. pyocr_toolkit/templates/_icons.html +55 -0
  35. pyocr_toolkit/templates/_llm_picker.html +12 -0
  36. pyocr_toolkit/templates/base.html +97 -0
  37. pyocr_toolkit/templates/compare.html +84 -0
  38. pyocr_toolkit/templates/document.html +80 -0
  39. pyocr_toolkit/templates/error.html +11 -0
  40. pyocr_toolkit/templates/help.html +244 -0
  41. pyocr_toolkit/templates/home.html +90 -0
  42. pyocr_toolkit/templates/jobs.html +15 -0
  43. pyocr_toolkit/templates/library.html +44 -0
  44. pyocr_toolkit/templates/models.html +67 -0
  45. pyocr_toolkit/templates/providers.html +104 -0
  46. pyocr_toolkit/templates/reader.html +28 -0
  47. pyocr_toolkit/templates/search.html +22 -0
  48. pyocr_toolkit/templates/workspace.html +109 -0
  49. pyocr_toolkit/templates/workspace_detail.html +42 -0
  50. pyocr_toolkit/templates/workspaces.html +42 -0
  51. pyocr_toolkit/web.py +186 -0
  52. pyocr_toolkit/workspaces.py +330 -0
  53. pyocr_toolkit-0.3.0.dist-info/METADATA +483 -0
  54. pyocr_toolkit-0.3.0.dist-info/RECORD +57 -0
  55. pyocr_toolkit-0.3.0.dist-info/WHEEL +4 -0
  56. pyocr_toolkit-0.3.0.dist-info/entry_points.txt +3 -0
  57. pyocr_toolkit-0.3.0.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,97 @@
1
+ {% from "_icons.html" import icon with context %}<!DOCTYPE html>
2
+ <html lang="en" data-theme="light" data-theme-pref="system">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>{% block title %}pyocr toolkit{% endblock %} · pyocr</title>
7
+ <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🔎</text></svg>">
8
+ <script>
9
+ /* Runs before first paint so the page never flashes the wrong theme.
10
+ pref = what the user picked (system | light | dark); theme = what is shown. */
11
+ (function () {
12
+ var pref = "system";
13
+ try { pref = localStorage.getItem("pyocr.theme") || "system"; } catch (_) {}
14
+ var dark = pref === "dark" || (pref === "system" && window.matchMedia("(prefers-color-scheme: dark)").matches);
15
+ document.documentElement.dataset.themePref = pref;
16
+ document.documentElement.dataset.theme = dark ? "dark" : "light";
17
+ })();
18
+ </script>
19
+ <link rel="stylesheet" href="/static/styles.css?v={{ version }}">
20
+ </head>
21
+ <body class="{% block body_class %}site{% endblock %}">
22
+ <header class="topbar">
23
+ <a class="brand" href="/"><span class="logo">{{ icon('scan') }}</span>pyocr <span>toolkit</span></a>
24
+ <nav class="mainnav">
25
+ <a href="/" class="{{ 'active' if nav == 'home' }}" title="Home">{{ icon('home') }}<span>Home</span></a>
26
+ <a href="/documents" class="{{ 'active' if nav == 'library' }}" title="Library">{{ icon('folder') }}<span>Library</span></a>
27
+ <a href="/workspaces" class="{{ 'active' if nav == 'workspaces' }}" title="Workspaces">{{ icon('folders') }}<span>Workspaces</span></a>
28
+ <a href="/search" class="{{ 'active' if nav == 'search' }}" title="Search">{{ icon('search') }}<span>Search</span></a>
29
+ <a href="/jobs" class="{{ 'active' if nav == 'jobs' }}" title="Jobs">{{ icon('layers') }}<span>Jobs</span></a>
30
+ <a href="/providers" class="{{ 'active' if nav == 'providers' }}" title="Providers">{{ icon('key') }}<span>Providers</span></a>
31
+ <a href="/models" class="{{ 'active' if nav == 'models' }}" title="Models">{{ icon('grid') }}<span>Models</span></a>
32
+ <a href="/help" class="{{ 'active' if nav == 'help' }}" title="Help">{{ icon('help') }}<span>Help</span></a>
33
+ </nav>
34
+ <div class="spacer"></div>
35
+ <form class="quicksearch" action="/search" method="get" role="search">
36
+ {{ icon('search') }}
37
+ <input type="search" name="q" placeholder="Search all documents…" aria-label="Search all documents">
38
+ </form>
39
+ <button type="button" class="btn ghost icon-only theme-toggle" id="theme-toggle" title="Theme" aria-label="Toggle colour theme">
40
+ <span data-icon="system">{{ icon('monitor') }}</span>
41
+ <span data-icon="light">{{ icon('sun') }}</span>
42
+ <span data-icon="dark">{{ icon('moon') }}</span>
43
+ </button>
44
+ <label class="btn primary" title="PDF, XPS, EPUB, PNG, JPEG, TIFF, ... (anything PyMuPDF opens)">
45
+ {{ icon('upload') }}<span class="upload-label">Upload</span>
46
+ <input class="upload-input" type="file" hidden multiple
47
+ accept=".zip,.pdf,.xps,.oxps,.epub,.cbz,.fb2,.mobi,.svg,.png,.jpg,.jpeg,.jp2,.jpx,.bmp,.gif,.tif,.tiff,.pnm,.pgm,.pbm,.ppm,.psd,.webp">
48
+ </label>
49
+ </header>
50
+
51
+ {% block subnav %}{% endblock %}
52
+
53
+ {% block main %}
54
+ <main class="container">
55
+ {% block content %}{% endblock %}
56
+ </main>
57
+ <footer class="footer">
58
+ pyocr-toolkit {{ version }} · <a href="/help">{{ icon('help') }}Help</a> · <a href="/docs">{{ icon('code') }}API docs</a> ·
59
+ <a href="https://github.com/utkarsh5026/pyocr">{{ icon('github') }}GitHub</a>
60
+ </footer>
61
+ {% endblock %}
62
+
63
+ <div id="drop-overlay" hidden><div><span class="emoji" aria-hidden="true">📥</span>Drop PDFs, images or a .zip to upload</div></div>
64
+ {# Shown by common.js when several files or a zip are uploaded: pick a workspace name first. #}
65
+ <dialog id="upload-dialog" class="dialog" aria-labelledby="upload-dialog-title">
66
+ <form method="dialog" id="upload-form">
67
+ <h2 id="upload-dialog-title">{{ icon('folders') }}Put these files in a workspace</h2>
68
+ <p class="small muted" id="upload-summary"></p>
69
+ <div class="seg" role="radiogroup" aria-label="Workspace">
70
+ <label><input type="radio" name="ws-mode" value="new" checked> New workspace</label>
71
+ <label><input type="radio" name="ws-mode" value="existing"> Existing</label>
72
+ <label><input type="radio" name="ws-mode" value="none"> No workspace</label>
73
+ </div>
74
+ <div data-ws-mode="new">
75
+ <label class="field"><span>Name</span>
76
+ <input id="upload-ws-name" maxlength="80" autocomplete="off" placeholder="e.g. festive-albattani"></label>
77
+ <div class="ws-suggest-row">
78
+ <div class="chips ws-suggest" id="upload-ws-suggest" aria-label="Suggested names"></div>
79
+ <button type="button" class="btn small ghost icon-only" id="upload-ws-shuffle" title="More suggestions" aria-label="More name suggestions">{{ icon('shuffle') }}</button>
80
+ </div>
81
+ </div>
82
+ <div data-ws-mode="existing" hidden>
83
+ <label class="field"><span>Workspace</span><select id="upload-ws-existing"></select></label>
84
+ </div>
85
+ <p data-ws-mode="none" class="small muted" hidden>The files go into the Library on their own. You can still group them later.</p>
86
+ <ul class="upload-files small" id="upload-files"></ul>
87
+ <div class="dialog-actions">
88
+ <button type="button" class="btn ghost" value="cancel" id="upload-cancel">Cancel</button>
89
+ <button class="btn primary" value="ok" id="upload-ok">{{ icon('upload') }}Upload</button>
90
+ </div>
91
+ </form>
92
+ </dialog>
93
+ <div id="toast" hidden role="status"></div>
94
+ <script src="/static/common.js?v={{ version }}"></script>
95
+ {% block scripts %}{% endblock %}
96
+ </body>
97
+ </html>
@@ -0,0 +1,84 @@
1
+ {% extends "base.html" %}
2
+ {% from "_icons.html" import icon %}
3
+ {% block title %}Compare · {{ doc.filename }}{% endblock %}
4
+ {% block subnav %}{% include "_doctabs.html" %}{% endblock %}
5
+ {% block content %}
6
+ <div id="compare-root" data-doc-id="{{ doc.id }}" data-page-count="{{ doc.page_count }}">
7
+ <div class="page-head">
8
+ <div>
9
+ <h1>Compare two sources across the whole document</h1>
10
+ <p>The <b>reference</b> is the text you trust more; the <b>candidate</b> is the one being judged.</p>
11
+ </div>
12
+ <div class="row" style="margin:0">
13
+ <label class="check"><input type="checkbox" id="opt-case" checked> Ignore case</label>
14
+ <label class="check"><input type="checkbox" id="opt-punct"> Ignore punctuation</label>
15
+ </div>
16
+ </div>
17
+
18
+ <div class="src-pick">
19
+ <label class="src-card">
20
+ <span class="src-letter a">A</span>
21
+ <span class="src-body"><span class="src-k">Reference</span>
22
+ <select id="src-a">
23
+ {% for s in sources %}<option value="{{ s.id }}" {{ 'disabled' if not s.page_count }}>{{ s.label }} ({{ s.page_count }}/{{ doc.page_count }})</option>{% endfor %}
24
+ </select></span>
25
+ </label>
26
+ <button class="btn ghost icon-only swap-btn" id="swap" title="Swap reference and candidate" aria-label="Swap reference and candidate">{{ icon('swap') }}</button>
27
+ <label class="src-card">
28
+ <span class="src-letter b">B</span>
29
+ <span class="src-body"><span class="src-k">Candidate</span>
30
+ <select id="src-b">
31
+ {% for s in sources %}<option value="{{ s.id }}" {{ 'disabled' if not s.page_count }}>{{ s.label }} ({{ s.page_count }}/{{ doc.page_count }})</option>{% endfor %}
32
+ </select></span>
33
+ </label>
34
+ <button class="btn primary run-btn" id="run">{{ icon('diff') }}Compare</button>
35
+ </div>
36
+
37
+ <div id="cmp-overall" class="stat-grid"></div>
38
+
39
+ <section id="cmp-chart" class="card chart-card" hidden>
40
+ <div class="section-head">
41
+ <h3 class="h-icon">{{ icon('layers') }}Character error rate per page</h3>
42
+ <span class="small muted">click a bar to see that page's diff</span>
43
+ <div class="spacer"></div>
44
+ <div class="legend-inline">
45
+ <span><i class="swatch good"></i>≤ 2%</span>
46
+ <span><i class="swatch warn"></i>≤ 10%</span>
47
+ <span><i class="swatch bad"></i>&gt; 10%</span>
48
+ <span><i class="swatch missing"></i>not scored</span>
49
+ </div>
50
+ </div>
51
+ <div class="bars" id="cmp-bars"></div>
52
+ </section>
53
+
54
+ <section id="cmp-page" class="card diff-card" hidden>
55
+ <div class="diff-head">
56
+ <button class="btn small ghost icon-only" id="pg-prev" title="Previous scored page" aria-label="Previous scored page">{{ icon('chevron-left') }}</button>
57
+ <b id="pg-title">Page –</b>
58
+ <button class="btn small ghost icon-only" id="pg-next" title="Next scored page" aria-label="Next scored page">{{ icon('chevron-right') }}</button>
59
+ <span id="pg-pill" class="badge"></span>
60
+ <span id="pg-wer" class="small muted"></span>
61
+ <div class="spacer"></div>
62
+ <div class="legend-inline">
63
+ <span><span class="del-mark">text</span> only in A</span>
64
+ <span><span class="ins-mark">text</span> only in B</span>
65
+ </div>
66
+ <a id="pg-open" class="btn small ghost" href="#">{{ icon('eye') }}Open in inspector</a>
67
+ </div>
68
+ <div class="diff-cols">
69
+ <div><div class="src-k">A · <span id="pg-a-label"></span></div><pre class="text" id="pg-a"></pre></div>
70
+ <div><div class="src-k">B · <span id="pg-b-label"></span></div><pre class="text" id="pg-b"></pre></div>
71
+ </div>
72
+ </section>
73
+
74
+ <details class="card table-details" id="cmp-table-wrap" hidden>
75
+ <summary>{{ icon('text') }}All pages as a table</summary>
76
+ <table class="table hover" id="cmp-table">
77
+ <thead><tr><th>Page</th><th>CER</th><th>WER</th><th>Ref chars</th><th>Cand chars</th><th></th></tr></thead>
78
+ <tbody></tbody>
79
+ </table>
80
+ </details>
81
+ <p class="small muted" id="cmp-hint">Pages missing from either source are shown but not scored.</p>
82
+ </div>
83
+ {% endblock %}
84
+ {% block scripts %}<script src="/static/compare.js?v={{ version }}"></script>{% endblock %}
@@ -0,0 +1,80 @@
1
+ {% extends "base.html" %}
2
+ {% from "_icons.html" import icon %}
3
+ {% block title %}{{ doc.filename }}{% endblock %}
4
+ {% block subnav %}{% include "_doctabs.html" %}{% endblock %}
5
+ {% block content %}
6
+ <div class="grid-2" data-doc-id="{{ doc.id }}" data-page-count="{{ doc.page_count }}" id="doc-root">
7
+ <section class="card">
8
+ <h2 class="h-icon">{{ icon('sparkles') }}Extract text</h2>
9
+ <p class="hint">Runs in the background. Pages already extracted with the same engine, model and prompt are skipped.</p>
10
+ <form id="extract-form" class="form">
11
+ <div class="seg" role="radiogroup" aria-label="Engine">
12
+ <label><input type="radio" name="kind" value="llm" checked> {{ icon('sparkles') }}LLM transcription</label>
13
+ <label><input type="radio" name="kind" value="ocr"> {{ icon('cpu') }}Tesseract OCR</label>
14
+ </div>
15
+ <label>Pages <input name="pages" placeholder="All pages (or e.g. 1-5, 9)"></label>
16
+ <div id="llm-options">{% set picker_id = 'ex' %}{% include "_llm_picker.html" %}</div>
17
+ <label class="check"><input type="checkbox" name="force"> Re-run pages that are already extracted</label>
18
+ <div class="row" style="margin-top:4px">
19
+ <button class="btn primary" type="submit">{{ icon('play') }}Start extraction</button>
20
+ <span class="small muted" id="extract-hint"></span>
21
+ </div>
22
+ </form>
23
+ <h3 class="h-icon" style="margin-top:24px">{{ icon('clock') }}Jobs</h3>
24
+ <div id="job-list" class="job-list"><p class="small muted">No jobs started for this document yet.</p></div>
25
+ </section>
26
+
27
+ <section class="card">
28
+ <h2 class="h-icon">{{ icon('layers') }}Extracted text sources</h2>
29
+ <p class="hint">Each engine, model and prompt you run becomes a source you can read, export or compare.</p>
30
+ <table class="table compact">
31
+ <thead><tr><th>Source</th><th>Pages</th><th>Tokens in / out</th><th></th></tr></thead>
32
+ <tbody>
33
+ {% for s in sources %}
34
+ <tr>
35
+ <td><b title="{{ s.id }}" style="font-weight:600">{{ s.label }}</b></td>
36
+ <td><span class="badge {{ 'ok' if s.page_count == doc.page_count }}">{{ s.page_count }}/{{ doc.page_count }}</span></td>
37
+ <td class="small muted">{% if s.kind == 'llm' %}{{ "{:,}".format(s.input_tokens) }} / {{ "{:,}".format(s.output_tokens) }}{% else %}–{% endif %}</td>
38
+ <td class="actions">
39
+ {% if s.page_count %}
40
+ <a class="btn small ghost" href="/documents/{{ doc.id }}/text?source={{ s.id|urlencode }}">{{ icon('book') }}Read</a>
41
+ <details class="menu"><summary class="btn small ghost">{{ icon('download') }}Export {{ icon('chevron-down') }}</summary>
42
+ <div>
43
+ {% for fmt, name in [('txt','Plain text'),('md','Markdown'),('json','JSON'),('jsonl','JSONL (page per line)')] %}
44
+ <a href="/api/documents/{{ doc.id }}/export?source={{ s.id|urlencode }}&fmt={{ fmt }}">{{ name }}</a>
45
+ {% endfor %}
46
+ </div>
47
+ </details>
48
+ {% else %}<span class="small muted">not extracted</span>{% endif %}
49
+ </td>
50
+ </tr>
51
+ {% endfor %}
52
+ </tbody>
53
+ </table>
54
+ <div class="row" style="margin-top:18px">
55
+ <a class="btn" href="/documents/{{ doc.id }}/compare">Compare sources {{ icon('arrow-right') }}</a>
56
+ <a class="btn ghost" href="/api/documents/{{ doc.id }}/source">{{ icon('download') }}Original</a>
57
+ <div class="spacer"></div>
58
+ <button class="btn ghost danger" id="delete-doc" data-name="{{ doc.filename }}">{{ icon('trash') }}Delete</button>
59
+ </div>
60
+ {% if doc.metadata %}
61
+ <details class="meta"><summary>{{ icon('info') }}File metadata</summary>
62
+ <dl>{% for k, v in doc.metadata.items() %}<dt>{{ k }}</dt><dd>{{ v }}</dd>{% endfor %}</dl>
63
+ </details>
64
+ {% endif %}
65
+ </section>
66
+ </div>
67
+
68
+ <section>
69
+ <div class="section-head">
70
+ <h2 class="h-icon">{{ icon('file') }}Pages</h2>
71
+ <div class="legend-inline">
72
+ <span><span class="badge scan">scan</span> no text layer</span>
73
+ <span><span class="badge ok">OCR</span> Tesseract done</span>
74
+ <span><span class="badge ok">LLM</span> transcribed</span>
75
+ </div>
76
+ </div>
77
+ <div id="page-grid" class="page-grid"><p class="muted small">Loading pages…</p></div>
78
+ </section>
79
+ {% endblock %}
80
+ {% block scripts %}<script src="/static/document.js?v={{ version }}"></script>{% endblock %}
@@ -0,0 +1,11 @@
1
+ {% extends "base.html" %}
2
+ {% from "_icons.html" import icon %}
3
+ {% block title %}Error {{ status }}{% endblock %}
4
+ {% block content %}
5
+ <div class="empty">
6
+ <div class="empty-icon"><span class="emoji" aria-hidden="true">🧐</span></div>
7
+ <h1 style="font-size:48px;margin-bottom:4px">{{ status }}</h1>
8
+ <p>{{ message }}</p>
9
+ <p><a class="btn" href="/documents">{{ icon('chevron-left') }}Back to the library</a></p>
10
+ </div>
11
+ {% endblock %}
@@ -0,0 +1,244 @@
1
+ {% extends "base.html" %}
2
+ {% block title %}Help{% endblock %}
3
+ {% block content %}
4
+ <div class="help">
5
+ <nav class="toc">
6
+ <b>Contents</b>
7
+ <a href="#start">Quick start</a>
8
+ <a href="#tour">Tour of the pages</a>
9
+ <a href="#workspaces">Workspaces &amp; batch uploads</a>
10
+ <a href="#engines">The three text sources</a>
11
+ <a href="#prompts">LLM prompts</a>
12
+ <a href="#metrics">Comparing: CER &amp; WER</a>
13
+ <a href="#workflows">Typical workflows</a>
14
+ <a href="#export">Export &amp; GenAI pipelines</a>
15
+ <a href="#search">Search</a>
16
+ <a href="#providers">Setting up providers</a>
17
+ <a href="#cli">Command line</a>
18
+ <a href="#api">HTTP API</a>
19
+ <a href="#data">Data &amp; privacy</a>
20
+ <a href="#faq">Troubleshooting &amp; FAQ</a>
21
+ <a href="#keys">Keyboard shortcuts</a>
22
+ </nav>
23
+
24
+ <article>
25
+ <h1>pyocr toolkit guide</h1>
26
+ <p class="lead">pyocr shows you what text you actually get out of a PDF or image, using three different
27
+ methods, and how far apart they are. Use it to decide whether OCR is good enough for a document set, to pick an
28
+ LLM for extraction, or just to get clean text out of a difficult file.</p>
29
+
30
+ <h2 id="start">Quick start</h2>
31
+ <ol>
32
+ <li><b>Upload</b> a file with the <i>Upload</i> button (top right) or by dropping it anywhere on a page. You can upload several at once, or a <b>.zip</b>; those go into a <a href="#workspaces">workspace</a>.</li>
33
+ <li>The file opens on its <b>Overview</b> page. Each page gets a badge; <span class="badge scan">scan</span> means it has no embedded text, so it needs OCR or an LLM.</li>
34
+ <li>Start an <b>extraction</b>: choose Tesseract or an LLM, a page range (or leave it empty for every page), and click <i>Start extraction</i>. A progress bar follows the job.</li>
35
+ <li>Open the <b>Page inspector</b> to see one page next to all of its texts, or <b>Full text</b> to read the whole document from one source.</li>
36
+ <li>Use <b>Compare</b> to measure two sources against each other, then export the text you want.</li>
37
+ </ol>
38
+
39
+ <h2 id="tour">Tour of the pages</h2>
40
+ <dl class="defs">
41
+ <dt><a href="/">Home</a></dt><dd>Upload area, setup status and recent documents.</dd>
42
+ <dt><a href="/documents">Library</a></dt><dd>Every uploaded document as a card showing how many pages have native, OCR and LLM text, and how many still have no text at all. Filter by status (<i>Needs text</i>, <i>Scanned</i>, <i>All pages have text</i>), by workspace or by name.</dd>
43
+ <dt><a href="/workspaces">Workspaces</a></dt><dd>Named groups of documents, usually one batch upload each. Open one to rename it, add files, or take documents out of it.</dd>
44
+ <dt>Document → Overview</dt><dd>Start background extractions, list every <i>source</i> (each engine/model/prompt you've run), export a source, and see all pages as thumbnails.</dd>
45
+ <dt>Document → Page inspector</dt><dd>The page image on the left; tabs for native text, Tesseract, LLM and a per-page diff on the right. Search hits are drawn on the image. Run OCR or an LLM on just this page.</dd>
46
+ <dt>Document → Full text</dt><dd>The whole document from one source, page by page, optionally next to the page images. Find-in-text, copy and download.</dd>
47
+ <dt>Document → Compare</dt><dd>Pick a reference (A) and a candidate (B). You get the whole-document error rates, a per-page CER chart (click a bar to open that page) and the selected page's text side by side, with words only in A and only in B highlighted. It opens on the worst page.</dd>
48
+ <dt><a href="/search">Search</a></dt><dd>Search every document in the library at once.</dd>
49
+ <dt><a href="/jobs">Jobs</a></dt><dd>All background extractions with their progress, errors and token usage.</dd>
50
+ <dt><a href="/providers">Providers</a></dt><dd>Which LLMs are configured, which settings are missing, a form to set keys and endpoints in the browser, and a <i>Test connection</i> button.</dd>
51
+ <dt><a href="/models">Models</a></dt><dd>Search vision models and see whether each is good for transcription, its price and why; list the models your key can use.</dd>
52
+ </dl>
53
+
54
+ <h2 id="workspaces">Workspaces and batch uploads</h2>
55
+ <p>A <b>workspace</b> keeps documents that belong together (a folder of invoices, a zip of scans) under one name.</p>
56
+ <ul>
57
+ <li><b>Several files or a .zip.</b> Select or drop more than one file, or any <code>.zip</code>, and a dialog asks where
58
+ they go: a <i>new workspace</i>, an <i>existing</i> one, or <i>no workspace</i> (just the Library). A single PDF or
59
+ image skips the dialog and opens right away, as before.</li>
60
+ <li><b>Name suggestions.</b> When the files share a name, that comes first: <code>invoices-2024.zip</code> suggests
61
+ <code>invoices-2024</code>, and <code>report-q1.pdf</code> + <code>report-q2.pdf</code> suggest <code>report</code>.
62
+ The other ideas are short <code>adjective-scientist</code> names such as <code>festive-albattani</code>; the shuffle
63
+ button gives new ones. Type anything you like instead; names must be unique (ignoring case) and at most 80 characters.</li>
64
+ <li><b>Zips</b> are unpacked on upload. Every PDF or image inside becomes its own document. Unsupported files,
65
+ zips inside the zip, encrypted entries and files that won't open are skipped, and the dialog lists each one with the reason.
66
+ <code>__MACOSX</code> folders and hidden files are ignored. Limits: 500 files per zip, each file up to
67
+ <code>MAX_UPLOAD_MB</code>, and the zip's unpacked total up to 5 × <code>MAX_UPLOAD_MB</code>.</li>
68
+ <li><b>Renaming.</b> On the workspace page, click the pencil or double-click the name. Name ideas based on the files are offered there too.</li>
69
+ <li><b>Adding later.</b> On a workspace page, <i>Add files</i> or dropping files puts them straight into that workspace.</li>
70
+ <li><b>Removing vs deleting.</b> <b>×</b> on a card takes the document out of the workspace but keeps it in the Library;
71
+ the bin deletes it everywhere. Deleting a workspace asks whether to delete its documents as well.</li>
72
+ <li>A document can belong to more than one workspace. Its badges in the Library show which ones.</li>
73
+ </ul>
74
+
75
+ <h2 id="engines">The three text sources, from first principles</h2>
76
+ <h3>1. Native text: the text the file already contains</h3>
77
+ <p>A PDF page is a list of <b>drawing instructions</b>, for example <i>"use font F at 11 pt, draw glyph 37 at (72, 700)"</i>.
78
+ When a PDF is exported from Word, LaTeX or a browser, each glyph also carries a mapping back to a Unicode character.
79
+ PyMuPDF follows those instructions and rebuilds words and lines from where the glyphs sit. This is exact, because
80
+ nothing is guessed, but it only exists for <i>born-digital</i> files. A scanner only records a picture of the page,
81
+ so a scanned PDF has no glyphs and no native text. A few PDFs also have broken glyph mappings, so native text can
82
+ be gibberish even though the page looks fine.</p>
83
+ <h3>2. Tesseract OCR: turning pixels back into characters</h3>
84
+ <p>For a picture, all we have is pixels. pyocr renders the page at <code>OCR_DPI</code> (300 by default; small text
85
+ needs enough pixels per character) and gives it to <b>Tesseract</b>, an open-source OCR engine. Tesseract finds
86
+ lines of text, segments them, and recognises characters with a neural network (LSTM). It also reports a box for every
87
+ word, which is how search can highlight OCR hits on the page. It is fast, free and private, but it reads shapes rather
88
+ than meaning. Tables, multi-column layouts, stamps, low-contrast or skewed scans and handwriting are its weak spots.</p>
89
+ <h3>3. LLM transcription: a vision model reading the page</h3>
90
+ <p>The page is rendered to an image (<code>LLM_DPI</code>, with the longest side capped at <code>LLM_MAX_EDGE_PX</code>)
91
+ and sent to a multimodal LLM with instructions to act as a <i>transcription engine</i>, not an assistant. Because it
92
+ reads whole words and sentences in context, it is usually far more accurate than Tesseract on hard pages, and it
93
+ understands layout. It can also make mistakes OCR never makes: quietly fixing a typo, normalising a date, skipping a
94
+ repeated header, or occasionally inventing a plausible word for a smudge. Use the diff view to catch these. It also
95
+ costs money and sends the page image to the provider.</p>
96
+
97
+ <h2 id="prompts">LLM prompts</h2>
98
+ <ul>
99
+ <li><b>Verbatim</b> (default): plain text, line by line, nothing corrected, tables as <code>cell | cell</code>. Use this to judge OCR, because both outputs then have the same shape.</li>
100
+ <li><b>Markdown</b>: keeps structure (headings, lists, GFM tables). Closest to what you would feed a RAG or LLM pipeline.</li>
101
+ <li><b>Custom</b>: write your own instructions, for example "extract only the line items as CSV" or "transcribe the handwritten notes only".</li>
102
+ </ul>
103
+ <p>Every provider + model + prompt combination is stored separately, so you can run several and compare them.
104
+ Results are cached: repeating a request costs nothing unless you click <i>re-run</i>.</p>
105
+
106
+ <h2 id="metrics">Comparing: CER and WER</h2>
107
+ <p>To find out how wrong a text is, compare it with a text you trust more: the <b>reference</b>. The basic quantity is
108
+ <b>edit distance</b> (Levenshtein distance): the smallest number of single-item <i>insertions</i>, <i>deletions</i> and
109
+ <i>substitutions</i> needed to turn the candidate into the reference.</p>
110
+ <pre class="code">reference : the cat sat
111
+ candidate : the bat sat → 1 substitution (c → b)
112
+
113
+ CER = character edits / reference characters = 1 / 11 = 9.1 %
114
+ WER = word edits / reference words = 1 / 3 = 33 %</pre>
115
+ <ul>
116
+ <li><b>CER</b> (character error rate) is the usual OCR quality figure. As a rough guide, under 2 % is excellent
117
+ (<span class="good">green</span>), 2–10 % is usable with care (<span class="warn">amber</span>), and over 10 % will
118
+ hurt downstream extraction (<span class="bad">red</span>).</li>
119
+ <li><b>WER</b> (word error rate) is harsher, because one wrong letter makes the whole word wrong. It is closer to what
120
+ matters for search and for exact values such as invoice numbers or amounts.</li>
121
+ <li>Both can be <b>over 100 %</b> when the candidate contains a lot of extra text.</li>
122
+ <li>The whole-document CER on the Compare page is <b>micro-averaged</b>: total edits divided by total reference
123
+ characters. Long pages count more than short ones, which matches how much text is actually affected.</li>
124
+ </ul>
125
+ <p>Before scoring, whitespace is collapsed, because engines break lines differently and that is not a reading error.
126
+ Ligatures such as <code>fi</code> are normalised to <code>fi</code>, and words hyphenated across a line break are joined.
127
+ Case and punctuation can optionally be ignored as well.</p>
128
+ <p class="callout"><b>Disagreement is not the same as error.</b> "OCR vs LLM" tells you how much two engines disagree,
129
+ not which one is right. For real ground truth, use a born-digital PDF: its native text is exact, so comparing OCR and
130
+ each LLM against it shows how every engine performs on your kind of documents.</p>
131
+
132
+ <h2 id="workflows">Typical workflows</h2>
133
+ <h3>Is OCR good enough for this batch of scans?</h3>
134
+ <ol><li>Upload a representative document.</li><li>Extract with Tesseract <i>and</i> an LLM (verbatim) on all pages.</li>
135
+ <li>Compare: reference = LLM, candidate = Tesseract OCR. Check the overall CER and the worst pages.</li>
136
+ <li>Open the worst pages in the inspector and read the diff. Are the errors in places that matter, such as numbers and names?</li></ol>
137
+ <h3>Which LLM should our pipeline use?</h3>
138
+ <ol><li>Take a born-digital PDF, which has exact native text.</li><li>Run two or three models on the same pages.</li>
139
+ <li>Compare native text (reference) against each model (candidate). Lower CER means a more faithful model. Also look at
140
+ the cost on the Overview page: each job shows its spend at list price in US dollars and rupees
141
+ (set <code>USD_INR_RATE</code> to today's rate).</li>
142
+ <li>Compare model A against model B on your real scans to see where they disagree.</li></ol>
143
+ <h3>Just get clean text out of a hard PDF</h3>
144
+ <ol><li>Extract with an LLM using the Markdown prompt.</li><li>Open <i>Full text</i>, check it next to the page images, then download as Markdown or JSONL.</li></ol>
145
+
146
+ <h2 id="export">Export and GenAI pipelines</h2>
147
+ <p>Every source can be downloaded for the whole document (Overview → <i>Export</i>, or the <i>Download</i> menu in Full text):</p>
148
+ <ul>
149
+ <li><b>TXT</b>: pages separated by <code>===== Page N =====</code>.</li>
150
+ <li><b>Markdown</b>: a <code>## Page N</code> heading per page.</li>
151
+ <li><b>JSON</b>: <code>{document, source, pages: [{page, text, extracted}]}</code>.</li>
152
+ <li><b>JSONL</b>: one JSON object per page (<code>document_id, filename, page, source, text</code>), ready for chunking, embedding or loading into a vector store.</li>
153
+ </ul>
154
+ <p>Pages that have not been extracted for that source are left empty. An export never starts a paid LLM call.</p>
155
+
156
+ <h2 id="search">Search</h2>
157
+ <p>Search is case-insensitive, and a phrase matches even when it is split across lines. In the page inspector, hits
158
+ from the native text are drawn in <span class="hl-native">yellow</span> and Tesseract hits in
159
+ <span class="hl-ocr">blue</span>, using each word's coordinates. LLM output has no coordinates, so its hits appear as
160
+ text snippets. OCR and LLM text is only searchable on pages where it has been extracted.</p>
161
+
162
+ <h2 id="providers">Setting up providers</h2>
163
+ <p>Easiest: open <a href="/providers">Providers</a>, expand <i>Set up in the browser</i> on a provider card, paste your
164
+ key and click <i>Save</i>. It takes effect immediately, is stored only on this machine in
165
+ <code>DATA_DIR/credentials.json</code> (readable only by you), overrides environment variables, and is never sent
166
+ back to the browser. Tick <i>forget saved value</i> to fall back to the environment again.</p>
167
+ <p>Alternatively run <code>pyocr init</code> to create a <code>.env</code> file, fill in the keys you have, and restart
168
+ <code>pyocr serve</code>. Either way, click <i>Test connection</i> to check.</p>
169
+ <table class="table compact">
170
+ <tr><th>Provider</th><th>Minimum settings</th></tr>
171
+ <tr><td>Claude (Anthropic API)</td><td><code>ANTHROPIC_API_KEY</code></td></tr>
172
+ <tr><td>OpenAI</td><td><code>OPENAI_API_KEY</code></td></tr>
173
+ <tr><td>Azure OpenAI</td><td><code>AZURE_OPENAI_API_KEY</code>, <code>AZURE_OPENAI_ENDPOINT</code>, <code>AZURE_OPENAI_DEPLOYMENT</code></td></tr>
174
+ <tr><td>Claude on Azure (Foundry)</td><td><code>ANTHROPIC_FOUNDRY_API_KEY</code>, <code>ANTHROPIC_FOUNDRY_RESOURCE</code></td></tr>
175
+ <tr><td>Google Gemini</td><td><code>GEMINI_API_KEY</code></td></tr>
176
+ <tr><td>Ollama / vLLM / LM Studio / OpenRouter</td><td><code>OPENAI_COMPATIBLE_BASE_URL</code>, <code>OPENAI_COMPATIBLE_MODEL</code></td></tr>
177
+ </table>
178
+ <p>You can type any model or deployment name in the model box. The suggestions are only hints. The model must accept
179
+ images: for local models, use a vision model such as <code>qwen2.5vl</code> or <code>llama3.2-vision</code>.</p>
180
+ <p>The <a href="/models">Models</a> page is a searchable catalog of vision models rated for this job
181
+ (<i>Excellent</i>, <i>Good</i>, <i>Fair: clean print only</i>, <i>Not suitable</i>), with prices and the reason
182
+ for each rating, and links to the benchmarks used. <i>List models</i> asks a provider which models your key can
183
+ use and rates each one. The same rating appears under every model box as you type; names that aren't in the
184
+ catalog are marked <i>custom</i> and still work. Ratings are a starting point: measure on your own pages with
185
+ <i>Compare</i>.</p>
186
+
187
+ <h2 id="cli">Command line</h2>
188
+ <pre class="code">pyocr serve [--host 0.0.0.0] [--port 8000] [--open] # start this web app
189
+ pyocr init # write a .env template here
190
+ pyocr doctor # check Tesseract, providers, data dir
191
+ pyocr providers # list providers and their status
192
+ pyocr extract FILE --engine llm -p anthropic --pages 1-5 --format jsonl -o out.jsonl
193
+ pyocr extract FILE --engine ocr # Tesseract, all pages, text to stdout
194
+ pyocr extract FILE --engine native --format md # embedded text layer only
195
+ pyocr compare FILE -p openai -m gpt-6.2-sol # per-page OCR/native error rate vs an LLM
196
+ pyocr import a.pdf b.pdf scans.zip folder/ -w "Q3" # add many files as one workspace (zips unpacked)
197
+ pyocr import FILE... --no-workspace # add to the Library without grouping</pre>
198
+ <p>Documents processed from the command line also appear in the Library, so you can inspect them in the browser afterwards.</p>
199
+
200
+ <h2 id="api">HTTP API</h2>
201
+ <p>Everything this UI does goes through a JSON API. Interactive documentation is at <a href="/docs">/docs</a>.
202
+ The most useful endpoints:</p>
203
+ <pre class="code">POST /api/documents upload (multipart "file")
204
+ POST /api/uploads several files (multipart "files"), zips unpacked; optional workspace_id
205
+ GET /api/workspaces list; POST {"name"} creates, PATCH /api/workspaces/{id} renames
206
+ POST /api/workspaces/suggest-names {"filenames":["invoices.zip"]} → name ideas
207
+ POST /api/documents/{id}/jobs {"kind":"llm","pages":"1-5","llm":{"provider":"anthropic"}}
208
+ GET /api/jobs/{job_id} progress
209
+ GET /api/documents/{id}/sources what has been extracted
210
+ GET /api/documents/{id}/export?source=llm&amp;fmt=jsonl
211
+ GET /api/documents/{id}/compare?a=llm&amp;b=ocr per-page CER/WER
212
+ POST /api/documents/{id}/pages/{n}/llm transcribe one page (0-based n)</pre>
213
+
214
+ <h2 id="data">Data and privacy</h2>
215
+ <ul>
216
+ <li>Everything is stored under <code>DATA_DIR</code> (default <code>./data</code>): the original file, OCR results and LLM results as plain JSON. Workspaces are small JSON files in <code>workspaces/</code> that list document ids.</li>
217
+ <li>A page image goes to an LLM provider <b>only</b> when you start a transcription for that page, and only to the provider you chose. Native text and Tesseract never leave your machine.</li>
218
+ <li>API keys are read on the server and are never sent to the browser.</li>
219
+ <li>There is no login. Keep it on <code>127.0.0.1</code> (the default) or put it behind your own authentication before sharing it on a network.</li>
220
+ </ul>
221
+
222
+ <h2 id="faq">Troubleshooting and FAQ</h2>
223
+ <dl class="defs">
224
+ <dt>“Tesseract OCR is not available”</dt><dd>Install Tesseract (see <a href="/providers">Providers</a>) and restart. For languages other than English, install the matching pack (for example <code>tesseract-ocr-deu</code>) and set <code>TESSERACT_LANGUAGE</code>.</dd>
225
+ <dt>A provider says “not configured”</dt><dd>The required environment variable is not visible to the server. Put it in <code>.env</code> in the directory where you run <code>pyocr serve</code>, or export it, then restart.</dd>
226
+ <dt>“authentication failed” / “model not found”</dt><dd>Check the key and the model name. For Azure, the model box needs your <i>deployment</i> name, not the model family.</dd>
227
+ <dt>“output hit the max token limit”</dt><dd>The page has a lot of text. The transcription is truncated; try the verbatim prompt, which is shorter than Markdown, or a model with a larger output limit.</dd>
228
+ <dt>The LLM “fixed” words that are misspelled on the page</dt><dd>That is a known LLM habit. The verbatim prompt discourages it, and the diff view makes it visible. If exact characters matter (IDs, legal text), compare against native text or OCR.</dd>
229
+ <dt>OCR is slow</dt><dd>Tesseract at 300 DPI takes roughly 1–5 s per page. Results are cached, so each page is only OCR'd once. Lowering <code>OCR_DPI</code> to 200 is faster and slightly less accurate.</dd>
230
+ <dt>Native text has words in the wrong order or odd characters</dt><dd>The PDF's internal structure or font mapping is unusual. This is exactly the kind of problem this tool is for: compare against OCR or an LLM to see the difference.</dd>
231
+ <dt>Can I use it with a local model and no internet?</dt><dd>Yes. Run Ollama with a vision model and set <code>OPENAI_COMPATIBLE_BASE_URL=http://localhost:11434/v1</code>.</dd>
232
+ </dl>
233
+
234
+ <h2 id="keys">Keyboard shortcuts (page inspector)</h2>
235
+ <table class="table compact">
236
+ <tr><td><kbd>←</kbd> / <kbd>→</kbd> or <kbd>k</kbd> / <kbd>j</kbd></td><td>previous / next page</td></tr>
237
+ <tr><td><kbd>/</kbd></td><td>focus the search box</td></tr>
238
+ <tr><td><kbd>1</kbd>–<kbd>5</kbd></td><td>switch tab (native, OCR, LLM, compare, side by side). <i>Side by side</i> widens the text panel and shows all three texts in columns that scroll together; it stays on until you pick another tab.</td></tr>
239
+ <tr><td><kbd>t</kbd></td><td>transcribe the page with the selected LLM</td></tr>
240
+ <tr><td><kbd>o</kbd></td><td>run OCR on the page</td></tr>
241
+ </table>
242
+ </article>
243
+ </div>
244
+ {% endblock %}