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.
- pyocr_toolkit/__init__.py +3 -0
- pyocr_toolkit/__main__.py +3 -0
- pyocr_toolkit/api.py +603 -0
- pyocr_toolkit/cli.py +315 -0
- pyocr_toolkit/compare.py +142 -0
- pyocr_toolkit/config.py +86 -0
- pyocr_toolkit/credentials.py +108 -0
- pyocr_toolkit/documents.py +326 -0
- pyocr_toolkit/env.example +48 -0
- pyocr_toolkit/jobs.py +205 -0
- pyocr_toolkit/llm/__init__.py +44 -0
- pyocr_toolkit/llm/anthropic_provider.py +188 -0
- pyocr_toolkit/llm/base.py +126 -0
- pyocr_toolkit/llm/catalog.py +337 -0
- pyocr_toolkit/llm/gemini_provider.py +98 -0
- pyocr_toolkit/llm/openai_provider.py +183 -0
- pyocr_toolkit/llm/prompts.py +61 -0
- pyocr_toolkit/search.py +88 -0
- pyocr_toolkit/service.py +269 -0
- pyocr_toolkit/static/common.js +538 -0
- pyocr_toolkit/static/compare.js +157 -0
- pyocr_toolkit/static/document.js +89 -0
- pyocr_toolkit/static/jobs.js +13 -0
- pyocr_toolkit/static/library.js +28 -0
- pyocr_toolkit/static/models.js +98 -0
- pyocr_toolkit/static/providers.js +44 -0
- pyocr_toolkit/static/reader.js +78 -0
- pyocr_toolkit/static/search.js +34 -0
- pyocr_toolkit/static/styles.css +819 -0
- pyocr_toolkit/static/workspace.js +420 -0
- pyocr_toolkit/static/workspaces.js +81 -0
- pyocr_toolkit/templates/_doc_card.html +30 -0
- pyocr_toolkit/templates/_doctabs.html +14 -0
- pyocr_toolkit/templates/_icons.html +55 -0
- pyocr_toolkit/templates/_llm_picker.html +12 -0
- pyocr_toolkit/templates/base.html +97 -0
- pyocr_toolkit/templates/compare.html +84 -0
- pyocr_toolkit/templates/document.html +80 -0
- pyocr_toolkit/templates/error.html +11 -0
- pyocr_toolkit/templates/help.html +244 -0
- pyocr_toolkit/templates/home.html +90 -0
- pyocr_toolkit/templates/jobs.html +15 -0
- pyocr_toolkit/templates/library.html +44 -0
- pyocr_toolkit/templates/models.html +67 -0
- pyocr_toolkit/templates/providers.html +104 -0
- pyocr_toolkit/templates/reader.html +28 -0
- pyocr_toolkit/templates/search.html +22 -0
- pyocr_toolkit/templates/workspace.html +109 -0
- pyocr_toolkit/templates/workspace_detail.html +42 -0
- pyocr_toolkit/templates/workspaces.html +42 -0
- pyocr_toolkit/web.py +186 -0
- pyocr_toolkit/workspaces.py +330 -0
- pyocr_toolkit-0.3.0.dist-info/METADATA +483 -0
- pyocr_toolkit-0.3.0.dist-info/RECORD +57 -0
- pyocr_toolkit-0.3.0.dist-info/WHEEL +4 -0
- pyocr_toolkit-0.3.0.dist-info/entry_points.txt +3 -0
- pyocr_toolkit-0.3.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/* Page inspector: one page image + native / OCR / LLM text + per-page diff. */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const root = $("#workspace");
|
|
5
|
+
const DOC_ID = root.dataset.docId;
|
|
6
|
+
const IS_PDF = root.dataset.isPdf === "true";
|
|
7
|
+
|
|
8
|
+
const state = {
|
|
9
|
+
config: null,
|
|
10
|
+
picker: null,
|
|
11
|
+
pages: [],
|
|
12
|
+
page: +root.dataset.page,
|
|
13
|
+
zoom: 1,
|
|
14
|
+
fit: true,
|
|
15
|
+
query: new URLSearchParams(location.search).get("q") || "",
|
|
16
|
+
searchHits: {}, // page -> {count, native: boxes[], ocr: boxes[]}
|
|
17
|
+
llmResults: [],
|
|
18
|
+
native: null,
|
|
19
|
+
ocr: null,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const docUrl = (suffix = "") => `/api/documents/${DOC_ID}${suffix}`;
|
|
23
|
+
const pageUrl = (n, suffix = "") => docUrl(`/pages/${n}${suffix}`);
|
|
24
|
+
|
|
25
|
+
function setText(el, text, emptyMsg) {
|
|
26
|
+
el.dataset.empty = emptyMsg || "";
|
|
27
|
+
el.innerHTML = text ? highlight(text, state.query) : "";
|
|
28
|
+
const first = el.querySelector("mark");
|
|
29
|
+
if (first) first.scrollIntoView({ block: "center" });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ------------------------------------------------------------------ page list
|
|
33
|
+
function pageBadges(p, n) {
|
|
34
|
+
const b = [];
|
|
35
|
+
if (p.looks_scanned) b.push('<span class="badge scan" title="Little or no embedded text - needs OCR">scan</span>');
|
|
36
|
+
else b.push(`<span class="badge" title="Characters in the embedded text layer">${p.native_chars} ch</span>`);
|
|
37
|
+
if (p.has_ocr_cache) b.push('<span class="badge ok" title="Tesseract OCR done">OCR</span>');
|
|
38
|
+
if (p.llm_results) b.push(`<span class="badge ok" title="LLM transcriptions stored">LLM${p.llm_results > 1 ? "×" + p.llm_results : ""}</span>`);
|
|
39
|
+
const hits = state.searchHits[n];
|
|
40
|
+
if (hits) b.push(`<span class="badge hit">${hits.count} hit${hits.count > 1 ? "s" : ""}</span>`);
|
|
41
|
+
return b.join("");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function renderPageList() {
|
|
45
|
+
const list = $("#page-list");
|
|
46
|
+
list.innerHTML = state.pages.map((p, n) => `
|
|
47
|
+
<li data-page="${n}">
|
|
48
|
+
<img loading="lazy" src="${pageUrl(n, "/image?dpi=36")}" alt="">
|
|
49
|
+
<div class="pinfo"><b>Page ${n + 1}</b><div class="badges">${pageBadges(p, n)}</div></div>
|
|
50
|
+
</li>`).join("");
|
|
51
|
+
$$("#page-list li").forEach((li) => li.addEventListener("click", () => gotoPage(+li.dataset.page)));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function refreshPageBadges(n) {
|
|
55
|
+
const el = $(`#page-list li[data-page="${n}"] .badges`);
|
|
56
|
+
if (el) el.innerHTML = pageBadges(state.pages[n], n);
|
|
57
|
+
if (n === state.page) $("#page-badges").innerHTML = pageBadges(state.pages[n], n);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ------------------------------------------------------------------ navigation
|
|
61
|
+
async function gotoPage(n) {
|
|
62
|
+
if (n < 0 || n >= state.pages.length) return;
|
|
63
|
+
state.page = n;
|
|
64
|
+
const qs = state.query ? `?q=${encodeURIComponent(state.query)}` : "";
|
|
65
|
+
history.replaceState(null, "", `/documents/${DOC_ID}/pages/${n + 1}${qs}${location.hash}`);
|
|
66
|
+
document.title = `Page ${n + 1} · ${document.title.split("·").slice(1).join("·").trim()}`;
|
|
67
|
+
$("#page-label").textContent = `${n + 1} / ${state.pages.length}`;
|
|
68
|
+
$("#prev-page").disabled = n === 0;
|
|
69
|
+
$("#next-page").disabled = n === state.pages.length - 1;
|
|
70
|
+
$("#page-badges").innerHTML = pageBadges(state.pages[n], n);
|
|
71
|
+
$("#open-image").href = pageUrl(n, "/image?dpi=200");
|
|
72
|
+
$$("#page-list li").forEach((li) => li.classList.toggle("active", +li.dataset.page === n));
|
|
73
|
+
$(`#page-list li[data-page="${n}"]`)?.scrollIntoView({ block: "nearest" });
|
|
74
|
+
|
|
75
|
+
const img = $("#page-img");
|
|
76
|
+
img.classList.add("loading"); // dimmed until the new render arrives
|
|
77
|
+
img.onload = () => { img.classList.remove("loading"); applyZoom(); };
|
|
78
|
+
img.onerror = () => img.classList.remove("loading");
|
|
79
|
+
img.src = pageUrl(n, `/image?dpi=${state.config.preview_dpi}`);
|
|
80
|
+
applyZoom();
|
|
81
|
+
|
|
82
|
+
$("#cmp-metrics").innerHTML = "";
|
|
83
|
+
$("#cmp-diff").innerHTML = "";
|
|
84
|
+
$("#cmp-legend").hidden = true;
|
|
85
|
+
$("#cmp-ref").innerHTML = $("#cmp-hyp").innerHTML = "";
|
|
86
|
+
|
|
87
|
+
const [native, ocr, llm] = await Promise.all([
|
|
88
|
+
api(pageUrl(n, "/text/native")),
|
|
89
|
+
api(pageUrl(n, "/text/ocr?cached_only=true")),
|
|
90
|
+
api(pageUrl(n, "/llm")),
|
|
91
|
+
]);
|
|
92
|
+
if (n !== state.page) return; // user moved on while loading
|
|
93
|
+
Object.assign(state, { native, ocr, llmResults: llm });
|
|
94
|
+
renderNative();
|
|
95
|
+
renderOcr();
|
|
96
|
+
renderLlm();
|
|
97
|
+
renderCompareOptions();
|
|
98
|
+
drawHighlights();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ------------------------------------------------------------------ tabs
|
|
102
|
+
function renderNative() {
|
|
103
|
+
const layer = state.native, p = state.pages[state.page];
|
|
104
|
+
$("#native-meta").innerHTML = IS_PDF
|
|
105
|
+
? `${layer.text.trim().length} characters · ${layer.words.length} words embedded in the file` +
|
|
106
|
+
(p.looks_scanned ? ' · <span class="warn">looks scanned: try OCR or an LLM</span>' : "")
|
|
107
|
+
: '<span class="warn">Image file: there is no embedded text layer. Use OCR or an LLM.</span>';
|
|
108
|
+
setText($("#native-text"), layer.text, "No embedded text on this page.");
|
|
109
|
+
renderSide();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function renderOcr() {
|
|
113
|
+
const layer = state.ocr;
|
|
114
|
+
const meta = $("#ocr-meta");
|
|
115
|
+
if (!state.config.tesseract_available) {
|
|
116
|
+
meta.innerHTML = '<span class="err">Tesseract is not installed on the server.</span> <a href="/providers">How to install</a>';
|
|
117
|
+
} else if (layer) {
|
|
118
|
+
meta.textContent = `${layer.text.trim().length} characters · ${layer.words.length} words · ` +
|
|
119
|
+
`${(layer.elapsed_ms / 1000).toFixed(1)}s · lang ${state.config.tesseract_language}`;
|
|
120
|
+
} else {
|
|
121
|
+
meta.textContent = "Not run yet for this page.";
|
|
122
|
+
}
|
|
123
|
+
$("#run-ocr .lbl").textContent = layer ? "Re-run OCR" : "Run OCR";
|
|
124
|
+
$("#run-ocr").disabled = !state.config.tesseract_available;
|
|
125
|
+
setText($("#ocr-text"), layer ? layer.text : "", "Click “Run OCR” (or press o) to OCR this page with Tesseract.");
|
|
126
|
+
renderSide();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function renderLlm(selectKey) {
|
|
130
|
+
const sel = $("#llm-result-select");
|
|
131
|
+
sel.innerHTML = state.llmResults.map((r) =>
|
|
132
|
+
`<option value="${esc(r.key)}">${esc(r.provider)} · ${esc(r.model)} · ${esc(r.prompt_mode)} · ${new Date(r.created_at * 1000).toLocaleString()}</option>`).join("");
|
|
133
|
+
sel.disabled = $("#delete-llm").disabled = state.llmResults.length === 0;
|
|
134
|
+
if (selectKey) sel.value = selectKey;
|
|
135
|
+
showLlmResult(sel.value);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function showLlmResult(key) {
|
|
139
|
+
const r = state.llmResults.find((x) => x.key === key);
|
|
140
|
+
if (!r) {
|
|
141
|
+
$("#llm-meta").innerHTML = "";
|
|
142
|
+
setText($("#llm-text"), "", "No transcription yet. Pick a provider and model above and click “Transcribe this page” (or press t).");
|
|
143
|
+
renderSide();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const tokens = r.input_tokens != null ? ` · ${fmtInt(r.input_tokens)} in / ${fmtInt(r.output_tokens)} out tokens` : "";
|
|
147
|
+
const warns = (r.warnings || []).map((w) => `<div class="warn">⚠ ${esc(w)}</div>`).join("");
|
|
148
|
+
$("#llm-meta").innerHTML = `${esc(r.provider_label || r.provider)} · <b>${esc(r.model)}</b> · ` +
|
|
149
|
+
`${(r.latency_ms / 1000).toFixed(1)}s${tokens}${r.cost ? ` · ${costHtml(r.cost)}` : ""} · ${r.text.length} chars${warns}`;
|
|
150
|
+
setText($("#llm-text"), r.text);
|
|
151
|
+
renderSide();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Side-by-side tab: the three sources in columns (LLM = the result picked in the LLM tab). */
|
|
155
|
+
function renderSide() {
|
|
156
|
+
if (!state.native) return;
|
|
157
|
+
const llm = state.llmResults.find((x) => x.key === $("#llm-result-select").value);
|
|
158
|
+
$("#side-native-meta").textContent = `${state.native.text.trim().length.toLocaleString()} ch`;
|
|
159
|
+
$("#side-ocr-meta").textContent = state.ocr ? `${state.ocr.text.trim().length.toLocaleString()} ch` : "not run";
|
|
160
|
+
$("#side-llm-meta").textContent = llm ? `${llm.model} · ${llm.text.length.toLocaleString()} ch` : "none yet";
|
|
161
|
+
setSideText($("#side-native"), state.native.text, "No embedded text.");
|
|
162
|
+
setSideText($("#side-ocr"), state.ocr?.text, "Not run yet (press o).");
|
|
163
|
+
setSideText($("#side-llm"), llm?.text, "No transcription yet (press t).");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function setSideText(el, text, emptyMsg) {
|
|
167
|
+
el.dataset.empty = emptyMsg;
|
|
168
|
+
el.innerHTML = text ? highlight(text, state.query) : "";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function switchTab(name) {
|
|
172
|
+
$$(".tabs button").forEach((x) => x.classList.toggle("active", x.dataset.tab === name));
|
|
173
|
+
$$(".tab-body").forEach((t) => { t.hidden = t.dataset.tab !== name; });
|
|
174
|
+
// "Side by side" is a layout mode: widen the text panel and remember it.
|
|
175
|
+
root.classList.toggle("side", name === "side");
|
|
176
|
+
try { localStorage.setItem("pyocr.sideBySide", name === "side" ? "1" : "0"); } catch (_) { /* private mode */ }
|
|
177
|
+
applyZoom();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ------------------------------------------------------------------ actions
|
|
181
|
+
async function runOcr(force = true) {
|
|
182
|
+
const n = state.page, btn = $("#run-ocr");
|
|
183
|
+
const done = setBusy(btn, "Running OCR…", [[$("#page-frame"), "is-reading"], [$("#ocr-text"), "is-thinking"]]);
|
|
184
|
+
try {
|
|
185
|
+
const layer = await api(pageUrl(n, `/text/ocr?force=${force}`));
|
|
186
|
+
state.pages[n].has_ocr_cache = true;
|
|
187
|
+
refreshPageBadges(n);
|
|
188
|
+
if (n === state.page) { state.ocr = layer; renderCompareOptions(); }
|
|
189
|
+
} finally {
|
|
190
|
+
done();
|
|
191
|
+
renderOcr();
|
|
192
|
+
if (n === state.page) replayAnimation($("#ocr-text"), "reveal");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function runLlm(force = false) {
|
|
197
|
+
const n = state.page, btn = $("#run-llm");
|
|
198
|
+
const body = state.picker.spec(force);
|
|
199
|
+
const out = $("#llm-text"), emptyMsg = out.dataset.empty;
|
|
200
|
+
out.dataset.empty = "Reading the page…";
|
|
201
|
+
const done = setBusy(btn, "Transcribing…", [[$("#page-frame"), "is-reading"], [out, "is-thinking"]]);
|
|
202
|
+
// One request, no progress events: an elapsed counter at least shows it's alive.
|
|
203
|
+
const t0 = Date.now();
|
|
204
|
+
const tick = setInterval(() => {
|
|
205
|
+
const s = fmtDuration((Date.now() - t0) / 1000);
|
|
206
|
+
btn.textContent = `Transcribing… ${s}`;
|
|
207
|
+
out.dataset.empty = `Reading the page… ${s}`;
|
|
208
|
+
}, 1000);
|
|
209
|
+
try {
|
|
210
|
+
const result = await postJSON(pageUrl(n, "/llm"), body);
|
|
211
|
+
if (!result.cached) state.pages[n].llm_results += 1;
|
|
212
|
+
refreshPageBadges(n);
|
|
213
|
+
if (n === state.page) {
|
|
214
|
+
state.llmResults = await api(pageUrl(n, "/llm"));
|
|
215
|
+
renderLlm(result.key);
|
|
216
|
+
replayAnimation(out, "reveal");
|
|
217
|
+
renderCompareOptions();
|
|
218
|
+
if (result.cached) toast("Showing the cached result. Use “re-run” to call the model again.");
|
|
219
|
+
}
|
|
220
|
+
} finally {
|
|
221
|
+
clearInterval(tick);
|
|
222
|
+
done();
|
|
223
|
+
if (!out.textContent) out.dataset.empty = emptyMsg; // failed: put the hint back
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function deleteLlm() {
|
|
228
|
+
const key = $("#llm-result-select").value;
|
|
229
|
+
if (!key || !confirm("Delete this stored transcription?")) return;
|
|
230
|
+
await api(pageUrl(state.page, `/llm/${encodeURIComponent(key)}`), { method: "DELETE" });
|
|
231
|
+
state.pages[state.page].llm_results -= 1;
|
|
232
|
+
state.llmResults = await api(pageUrl(state.page, "/llm"));
|
|
233
|
+
refreshPageBadges(state.page);
|
|
234
|
+
renderLlm();
|
|
235
|
+
renderCompareOptions();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ------------------------------------------------------------------ zoom & highlights
|
|
239
|
+
function applyZoom() {
|
|
240
|
+
const p = state.pages[state.page];
|
|
241
|
+
if (!p) return;
|
|
242
|
+
const naturalWidth = p.width * (state.config.preview_dpi / 72);
|
|
243
|
+
if (state.fit) {
|
|
244
|
+
const avail = $("#page-scroll").clientWidth - 32;
|
|
245
|
+
state.zoom = Math.max(0.2, Math.min(4, avail / naturalWidth));
|
|
246
|
+
}
|
|
247
|
+
$("#page-frame").style.width = `${naturalWidth * state.zoom}px`;
|
|
248
|
+
$("#zoom-label").textContent = `${Math.round(state.zoom * 100)}%`;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function drawHighlights() {
|
|
252
|
+
const layer = $("#highlight-layer");
|
|
253
|
+
layer.innerHTML = "";
|
|
254
|
+
const hits = state.searchHits[state.page], p = state.pages[state.page];
|
|
255
|
+
if (!hits || !p) return;
|
|
256
|
+
for (const [kind, boxes] of [["native", hits.native], ["ocr", hits.ocr]]) {
|
|
257
|
+
for (const [x0, y0, x1, y1] of boxes || []) {
|
|
258
|
+
const d = document.createElement("div");
|
|
259
|
+
d.className = kind;
|
|
260
|
+
Object.assign(d.style, {
|
|
261
|
+
left: `${(x0 / p.width) * 100}%`, top: `${(y0 / p.height) * 100}%`,
|
|
262
|
+
width: `${((x1 - x0) / p.width) * 100}%`, height: `${((y1 - y0) / p.height) * 100}%`,
|
|
263
|
+
});
|
|
264
|
+
layer.appendChild(d);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// ------------------------------------------------------------------ search
|
|
270
|
+
async function runSearch(ev) {
|
|
271
|
+
ev?.preventDefault();
|
|
272
|
+
const q = $("#search-input").value.trim();
|
|
273
|
+
state.query = q;
|
|
274
|
+
state.searchHits = {};
|
|
275
|
+
const box = $("#search-results");
|
|
276
|
+
history.replaceState(null, "", `/documents/${DOC_ID}/pages/${state.page + 1}${q ? `?q=${encodeURIComponent(q)}` : ""}`);
|
|
277
|
+
if (!q) {
|
|
278
|
+
box.hidden = true;
|
|
279
|
+
state.pages.forEach((_, n) => refreshPageBadges(n));
|
|
280
|
+
drawHighlights();
|
|
281
|
+
rerenderTexts();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const sources = $$(".search-sources input:checked").map((i) => i.value).join(",");
|
|
285
|
+
const res = await api(docUrl(`/search?q=${encodeURIComponent(q)}&sources=${sources}`));
|
|
286
|
+
let html = `<div class="sr-summary">${res.total} match${res.total === 1 ? "" : "es"} on ${res.pages.length} page(s)`;
|
|
287
|
+
if (res.pages_without_ocr && sources.includes("ocr")) html += ` · OCR not run on ${res.pages_without_ocr} page(s)`;
|
|
288
|
+
html += "</div>";
|
|
289
|
+
for (const pg of res.pages) {
|
|
290
|
+
state.searchHits[pg.page] = {
|
|
291
|
+
count: pg.hits.reduce((a, h) => a + h.count, 0),
|
|
292
|
+
native: pg.hits.filter((h) => h.source === "native").flatMap((h) => h.boxes),
|
|
293
|
+
ocr: pg.hits.filter((h) => h.source === "ocr").flatMap((h) => h.boxes),
|
|
294
|
+
};
|
|
295
|
+
html += `<div class="sr-page" data-page="${pg.page}"><b>Page ${pg.page + 1}</b>`;
|
|
296
|
+
for (const h of pg.hits) {
|
|
297
|
+
const s = h.snippets[0];
|
|
298
|
+
const snippet = s ? `${esc(s.before)}<mark>${esc(s.match)}</mark>${esc(s.after)}` : "";
|
|
299
|
+
html += `<div class="sr-hit"><span class="src">${esc(h.label)} · ${h.count}</span><div>${snippet}</div></div>`;
|
|
300
|
+
}
|
|
301
|
+
html += "</div>";
|
|
302
|
+
}
|
|
303
|
+
box.innerHTML = html;
|
|
304
|
+
box.hidden = false;
|
|
305
|
+
$$("#search-results .sr-page").forEach((el) => el.addEventListener("click", () => gotoPage(+el.dataset.page)));
|
|
306
|
+
state.pages.forEach((_, n) => refreshPageBadges(n));
|
|
307
|
+
drawHighlights();
|
|
308
|
+
rerenderTexts();
|
|
309
|
+
if (res.pages.length && !state.searchHits[state.page]) gotoPage(res.pages[0].page);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function rerenderTexts() {
|
|
313
|
+
if (!state.native) return;
|
|
314
|
+
renderNative();
|
|
315
|
+
renderOcr();
|
|
316
|
+
showLlmResult($("#llm-result-select").value);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// ------------------------------------------------------------------ compare
|
|
320
|
+
function renderCompareOptions() {
|
|
321
|
+
const opts = [["native", "Native text layer"]];
|
|
322
|
+
if (state.ocr) opts.push(["ocr", "Tesseract OCR"]);
|
|
323
|
+
for (const r of state.llmResults) opts.push([`llm:${r.key}`, `LLM: ${r.provider} / ${r.model} (${r.prompt_mode})`]);
|
|
324
|
+
const ref = $("#cmp-ref"), hyp = $("#cmp-hyp");
|
|
325
|
+
const prev = { ref: ref.value, hyp: hyp.value };
|
|
326
|
+
for (const sel of [ref, hyp]) sel.innerHTML = opts.map(([v, l]) => `<option value="${esc(v)}">${esc(l)}</option>`).join("");
|
|
327
|
+
const valid = (v) => opts.some(([o]) => o === v);
|
|
328
|
+
// Defaults: newest LLM transcription as the reference, OCR (or the native
|
|
329
|
+
// text if OCR hasn't run) as the candidate. User choices are kept while valid.
|
|
330
|
+
ref.value = valid(prev.ref) ? prev.ref : (state.llmResults.length ? `llm:${state.llmResults[0].key}` : "native");
|
|
331
|
+
const fallback = state.ocr ? "ocr" : "native";
|
|
332
|
+
hyp.value = valid(prev.hyp) && prev.hyp !== ref.value ? prev.hyp : (fallback !== ref.value ? fallback : "native");
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const textRef = (v) => (v.startsWith("llm:") ? { source: "llm", key: v.slice(4) } : { source: v });
|
|
336
|
+
|
|
337
|
+
async function runCompare() {
|
|
338
|
+
const refV = $("#cmp-ref").value, hypV = $("#cmp-hyp").value;
|
|
339
|
+
if (refV === hypV) { toast("Pick two different sources to compare.", true); return; }
|
|
340
|
+
const res = await postJSON(pageUrl(state.page, "/compare"), {
|
|
341
|
+
reference: textRef(refV), hypothesis: textRef(hypV),
|
|
342
|
+
ignore_case: $("#cmp-case").checked, ignore_punctuation: $("#cmp-punct").checked,
|
|
343
|
+
});
|
|
344
|
+
renderMetrics($("#cmp-metrics"), res.metrics);
|
|
345
|
+
$("#cmp-legend").hidden = false;
|
|
346
|
+
$("#cmp-diff").innerHTML = renderDiff(res.diff);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function renderMetrics(el, m) {
|
|
350
|
+
const metric = (k, v, cls = "") => `<div class="metric"><div class="v ${cls}">${v}</div><div class="k">${k}</div></div>`;
|
|
351
|
+
el.innerHTML =
|
|
352
|
+
metric("Char error rate", pct(m.cer), errorRateClass(m.cer)) +
|
|
353
|
+
metric("Word error rate", pct(m.wer), errorRateClass(m.wer)) +
|
|
354
|
+
metric("Char accuracy", pct(m.accuracy)) +
|
|
355
|
+
metric("Ref / cand chars", `${fmtInt(m.reference_chars)} / ${fmtInt(m.hypothesis_chars)}`) +
|
|
356
|
+
metric("Ref / cand words", `${fmtInt(m.reference_words)} / ${fmtInt(m.hypothesis_words)}`);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// ------------------------------------------------------------------ wiring
|
|
360
|
+
function wire() {
|
|
361
|
+
$("#prev-page").addEventListener("click", () => gotoPage(state.page - 1));
|
|
362
|
+
$("#next-page").addEventListener("click", () => gotoPage(state.page + 1));
|
|
363
|
+
$("#zoom-in").addEventListener("click", () => { state.fit = false; state.zoom = Math.min(4, state.zoom * 1.2); applyZoom(); });
|
|
364
|
+
$("#zoom-out").addEventListener("click", () => { state.fit = false; state.zoom = Math.max(0.2, state.zoom / 1.2); applyZoom(); });
|
|
365
|
+
$("#zoom-fit").addEventListener("click", () => { state.fit = true; applyZoom(); });
|
|
366
|
+
window.addEventListener("resize", () => state.fit && applyZoom());
|
|
367
|
+
$$(".tabs button").forEach((b) => b.addEventListener("click", () => switchTab(b.dataset.tab)));
|
|
368
|
+
$$("[data-copy]").forEach((b) => b.addEventListener("click", () => copyText($(b.dataset.copy).textContent)));
|
|
369
|
+
|
|
370
|
+
$("#run-ocr").addEventListener("click", guard(() => runOcr(true)));
|
|
371
|
+
$("#run-llm").addEventListener("click", guard(() => runLlm(false)));
|
|
372
|
+
$("#rerun-llm").addEventListener("click", guard(() => runLlm(true)));
|
|
373
|
+
$("#delete-llm").addEventListener("click", guard(deleteLlm));
|
|
374
|
+
$("#llm-result-select").addEventListener("change", (e) => showLlmResult(e.target.value));
|
|
375
|
+
$("#run-compare").addEventListener("click", guard(runCompare));
|
|
376
|
+
$("#search-form").addEventListener("submit", guard(runSearch));
|
|
377
|
+
// the (x) clear button fires "search" with an empty value (Enter is handled by submit)
|
|
378
|
+
$("#search-input").addEventListener("search", guard(() => !$("#search-input").value && runSearch()));
|
|
379
|
+
$$(".search-sources input").forEach((i) => i.addEventListener("change", guard(() => state.query && runSearch())));
|
|
380
|
+
|
|
381
|
+
// scroll the side-by-side columns together (proportionally, since lengths differ)
|
|
382
|
+
const cols = $$(".side-cols pre");
|
|
383
|
+
let lead = null;
|
|
384
|
+
cols.forEach((c) => {
|
|
385
|
+
c.addEventListener("pointerenter", () => { lead = c; });
|
|
386
|
+
c.addEventListener("scroll", () => {
|
|
387
|
+
if (lead !== c) return;
|
|
388
|
+
const f = c.scrollTop / Math.max(1, c.scrollHeight - c.clientHeight);
|
|
389
|
+
cols.forEach((o) => { if (o !== c) o.scrollTop = f * (o.scrollHeight - o.clientHeight); });
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
document.addEventListener("keydown", (e) => {
|
|
394
|
+
if (["INPUT", "TEXTAREA", "SELECT"].includes(e.target.tagName) || e.metaKey || e.ctrlKey || e.altKey) return;
|
|
395
|
+
const tabs = { 1: "native", 2: "ocr", 3: "llm", 4: "compare", 5: "side" };
|
|
396
|
+
if (e.key === "ArrowRight" || e.key === "j") gotoPage(state.page + 1);
|
|
397
|
+
else if (e.key === "ArrowLeft" || e.key === "k") gotoPage(state.page - 1);
|
|
398
|
+
else if (e.key === "/") { e.preventDefault(); $("#search-input").focus(); }
|
|
399
|
+
else if (tabs[e.key]) switchTab(tabs[e.key]);
|
|
400
|
+
else if (e.key === "t") { switchTab("llm"); guard(() => runLlm(false))(); }
|
|
401
|
+
else if (e.key === "o") { switchTab("ocr"); guard(() => runOcr(false))(); }
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
(async function main() {
|
|
406
|
+
wire();
|
|
407
|
+
try {
|
|
408
|
+
state.config = await getConfig();
|
|
409
|
+
state.picker = await initLlmPicker($("[data-llm-picker]"));
|
|
410
|
+
state.pages = await api(docUrl("/pages"));
|
|
411
|
+
renderPageList();
|
|
412
|
+
if (location.hash === "#llm") switchTab("llm");
|
|
413
|
+
if (location.hash === "#compare") switchTab("compare");
|
|
414
|
+
else if (!location.hash && localStorage.getItem("pyocr.sideBySide") === "1") switchTab("side");
|
|
415
|
+
await gotoPage(Math.min(state.page, state.pages.length - 1));
|
|
416
|
+
if (state.query) { $("#search-input").value = state.query; await runSearch(); }
|
|
417
|
+
} catch (e) {
|
|
418
|
+
toast(e.message, true);
|
|
419
|
+
}
|
|
420
|
+
})();
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* Workspaces list and workspace page: create, rename (with name suggestions), delete, manage documents. */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// ----------------------------------------------------------- list page
|
|
5
|
+
$("#ws-new")?.addEventListener("click", guard(async () => {
|
|
6
|
+
const [suggestion] = await suggestNames([], 1);
|
|
7
|
+
const name = prompt("Name for the new workspace:", suggestion);
|
|
8
|
+
if (name === null) return;
|
|
9
|
+
const ws = await postJSON("/api/workspaces", { name: name.trim() || suggestion });
|
|
10
|
+
location.href = `/workspaces/${ws.id}`;
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
// ----------------------------------------------------------- workspace page
|
|
14
|
+
const root = $("#ws-root");
|
|
15
|
+
if (root) {
|
|
16
|
+
const wsId = root.dataset.wsId;
|
|
17
|
+
const form = $("#ws-rename-form"), input = $("#ws-rename-input"), title = $("#ws-name"), chips = $("#ws-rename-suggest");
|
|
18
|
+
const filenames = $$("#lib-grid .lib-card").map((c) => c.dataset.name);
|
|
19
|
+
|
|
20
|
+
const markChips = () => $$("button", chips).forEach((b) => b.setAttribute("aria-pressed", String(b.textContent === input.value.trim())));
|
|
21
|
+
function showForm(show) {
|
|
22
|
+
form.hidden = !show;
|
|
23
|
+
title.parentElement.hidden = show;
|
|
24
|
+
if (!show) return;
|
|
25
|
+
input.value = root.dataset.wsName;
|
|
26
|
+
input.focus();
|
|
27
|
+
input.select();
|
|
28
|
+
guard(async () => {
|
|
29
|
+
const names = await suggestNames(filenames);
|
|
30
|
+
chips.innerHTML = '<span class="small muted">Ideas:</span>' +
|
|
31
|
+
names.map((n) => `<button type="button">${esc(n)}</button>`).join("");
|
|
32
|
+
markChips();
|
|
33
|
+
})();
|
|
34
|
+
}
|
|
35
|
+
$("#ws-rename").addEventListener("click", () => showForm(true));
|
|
36
|
+
$("#ws-rename-cancel").addEventListener("click", () => showForm(false));
|
|
37
|
+
title.addEventListener("dblclick", () => showForm(true));
|
|
38
|
+
input.addEventListener("input", markChips);
|
|
39
|
+
input.addEventListener("keydown", (e) => { if (e.key === "Escape") showForm(false); });
|
|
40
|
+
chips.addEventListener("click", (e) => {
|
|
41
|
+
const b = e.target.closest("button");
|
|
42
|
+
if (b) { input.value = b.textContent; markChips(); input.focus(); }
|
|
43
|
+
});
|
|
44
|
+
form.addEventListener("submit", guard(async (e) => {
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
const name = input.value.trim();
|
|
47
|
+
if (!name || name === root.dataset.wsName) return showForm(false);
|
|
48
|
+
const ws = await api(`/api/workspaces/${wsId}`, {
|
|
49
|
+
method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name }),
|
|
50
|
+
});
|
|
51
|
+
root.dataset.wsName = ws.name;
|
|
52
|
+
title.textContent = ws.name;
|
|
53
|
+
document.title = `${ws.name} · pyocr`;
|
|
54
|
+
showForm(false);
|
|
55
|
+
toast(`Renamed to ${ws.name}`);
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
$("#ws-delete").addEventListener("click", guard(async () => {
|
|
59
|
+
const name = root.dataset.wsName;
|
|
60
|
+
const count = $$("#lib-grid .lib-card").length;
|
|
61
|
+
if (!confirm(`Delete the workspace "${name}"?`)) return;
|
|
62
|
+
let alsoDocs = false;
|
|
63
|
+
if (count) alsoDocs = confirm(`Also delete its ${count} document${count === 1 ? "" : "s"} and all their OCR/LLM results?\n\n` +
|
|
64
|
+
"OK = delete the documents too. Cancel = keep them in the Library.");
|
|
65
|
+
await api(`/api/workspaces/${wsId}?delete_documents=${alsoDocs}`, { method: "DELETE" });
|
|
66
|
+
location.href = "/workspaces";
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
$$("[data-ws-remove]").forEach((btn) => btn.addEventListener("click", guard(async () => {
|
|
70
|
+
await api(`/api/workspaces/${wsId}/documents/${btn.dataset.wsRemove}`, { method: "DELETE" });
|
|
71
|
+
btn.closest(".lib-card").remove();
|
|
72
|
+
toast(`Removed ${btn.dataset.name} from ${root.dataset.wsName} (it is still in the Library)`);
|
|
73
|
+
})));
|
|
74
|
+
|
|
75
|
+
$$("[data-delete]").forEach((btn) => btn.addEventListener("click", guard(async () => {
|
|
76
|
+
if (!confirm(`Delete ${btn.dataset.name} and all of its OCR/LLM results?`)) return;
|
|
77
|
+
await api(`/api/documents/${btn.dataset.delete}`, { method: "DELETE" });
|
|
78
|
+
btn.closest(".lib-card").remove();
|
|
79
|
+
toast(`Deleted ${btn.dataset.name}`);
|
|
80
|
+
})));
|
|
81
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{# One document card (Library and workspace pages). Expects `d` (web.summary) and optional `ws`. #}
|
|
2
|
+
{% from "_icons.html" import icon %}
|
|
3
|
+
<article class="card lib-card" data-name="{{ d.filename|lower }}" data-status="{{ d.status }}" data-ws="{{ d.workspaces|map(attribute='id')|join(' ') }}">
|
|
4
|
+
<a class="lib-thumb" href="/documents/{{ d.id }}" tabindex="-1" aria-hidden="true">
|
|
5
|
+
<img loading="lazy" src="/api/documents/{{ d.id }}/pages/0/image?dpi=40" alt="">
|
|
6
|
+
<span class="badge {{ status_cls[d.status] }}">{% if d.status == 'complete' %}{{ icon('check') }}All pages have text{% else %}{{ 'Scanned · ' if d.status == 'scanned' }}{{ d.missing_pages }} page{{ 's' if d.missing_pages != 1 }} need{{ 's' if d.missing_pages == 1 }} text{% endif %}</span>
|
|
7
|
+
</a>
|
|
8
|
+
<div class="lib-body">
|
|
9
|
+
<a class="file-name" href="/documents/{{ d.id }}" title="{{ d.filename }}">{{ d.filename }}</a>
|
|
10
|
+
{% if d.workspaces and not ws %}<div class="ws-tags">{% for w in d.workspaces %}<a class="badge info" href="/workspaces/{{ w.id }}" title="Workspace">{{ icon('folders') }}{{ w.name }}</a>{% endfor %}</div>{% endif %}
|
|
11
|
+
<div class="small muted">{{ d.page_count }} page{{ 's' if d.page_count != 1 }} · {{ d.filetype|upper }} · {{ d.size_bytes|filesize }} · {{ d.created_at|datetime }}</div>
|
|
12
|
+
<div class="coverage" title="Pages with text from each source">
|
|
13
|
+
{% for key, label in [('native', 'Native'), ('ocr', 'OCR'), ('llm', 'LLM')] %}
|
|
14
|
+
{% set n = d[key ~ '_pages'] %}
|
|
15
|
+
<div class="cov {{ key }}">
|
|
16
|
+
<span class="cov-k">{{ icon({'native': 'type', 'ocr': 'cpu', 'llm': 'sparkles'}[key]) }}{{ label }}</span><span class="cov-v">{{ n }}/{{ d.page_count }}</span>
|
|
17
|
+
<span class="cov-bar"><i style="width: {{ (100 * n / d.page_count)|round(1) if d.page_count else 0 }}%"></i></span>
|
|
18
|
+
</div>
|
|
19
|
+
{% endfor %}
|
|
20
|
+
</div>
|
|
21
|
+
<div class="lib-actions">
|
|
22
|
+
<a class="btn small ghost" href="/documents/{{ d.id }}/pages/1">{{ icon('eye') }}Inspect</a>
|
|
23
|
+
<a class="btn small ghost" href="/documents/{{ d.id }}/text">{{ icon('text') }}Text</a>
|
|
24
|
+
<a class="btn small ghost" href="/documents/{{ d.id }}/compare">{{ icon('diff') }}Compare</a>
|
|
25
|
+
<div class="spacer"></div>
|
|
26
|
+
{% if ws %}<button class="btn small ghost icon-only" data-ws-remove="{{ d.id }}" data-name="{{ d.filename }}" title="Remove from this workspace (keeps the document)" aria-label="Remove {{ d.filename }} from this workspace">{{ icon('x') }}</button>{% endif %}
|
|
27
|
+
<button class="btn small ghost danger icon-only" data-delete="{{ d.id }}" data-name="{{ d.filename }}" title="Delete" aria-label="Delete {{ d.filename }}">{{ icon('trash') }}</button>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
</article>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{% from "_icons.html" import icon %}
|
|
2
|
+
<div class="doc-header">
|
|
3
|
+
<div class="doc-title">
|
|
4
|
+
{% if doc.workspaces %}<a href="/workspaces/{{ doc.workspaces[0].id }}" class="crumb" title="Workspace">{{ icon('folders') }}{{ doc.workspaces[0].name }}</a>{% else %}<a href="/documents" class="crumb">{{ icon('folder') }}Library</a>{% endif %}<span class="sep">/</span>
|
|
5
|
+
<b title="{{ doc.filename }}">{{ doc.filename }}</b>
|
|
6
|
+
<span class="muted">{{ doc.page_count }} page{{ 's' if doc.page_count != 1 }} · {{ doc.filetype|upper }} · {{ doc.size_bytes|filesize }}</span>
|
|
7
|
+
</div>
|
|
8
|
+
<nav class="doc-tabs">
|
|
9
|
+
<a href="/documents/{{ doc.id }}" class="{{ 'active' if doc_tab == 'overview' }}">{{ icon('info') }}Overview</a>
|
|
10
|
+
<a href="/documents/{{ doc.id }}/pages/1" class="{{ 'active' if doc_tab == 'pages' }}">{{ icon('eye') }}Page inspector</a>
|
|
11
|
+
<a href="/documents/{{ doc.id }}/text" class="{{ 'active' if doc_tab == 'text' }}">{{ icon('text') }}Full text</a>
|
|
12
|
+
<a href="/documents/{{ doc.id }}/compare" class="{{ 'active' if doc_tab == 'compare' }}">{{ icon('diff') }}Compare</a>
|
|
13
|
+
</nav>
|
|
14
|
+
</div>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{# Minimal inline SVG icon set (stroke icons, 24x24 grid). Usage: {{ icon('search') }} #}
|
|
2
|
+
{% macro icon(name) -%}
|
|
3
|
+
<svg class="icon" viewBox="0 0 24 24" aria-hidden="true">
|
|
4
|
+
{%- if name == 'search' %}<circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/>
|
|
5
|
+
{%- elif name == 'upload' %}<path d="M12 15V4"/><path d="m7 9 5-5 5 5"/><path d="M4 15v3a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-3"/>
|
|
6
|
+
{%- elif name == 'sun' %}<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/>
|
|
7
|
+
{%- elif name == 'moon' %}<path d="M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5Z"/>
|
|
8
|
+
{%- elif name == 'monitor' %}<rect x="3" y="4" width="18" height="12" rx="2"/><path d="M8 20h8M12 16v4"/>
|
|
9
|
+
{%- elif name == 'scan' %}<path d="M4 8V6a2 2 0 0 1 2-2h2M16 4h2a2 2 0 0 1 2 2v2M20 16v2a2 2 0 0 1-2 2h-2M8 20H6a2 2 0 0 1-2-2v-2"/><path d="M8 10h8M8 14h5"/>
|
|
10
|
+
{%- elif name == 'file' %}<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8Z"/><path d="M14 3v5h5M9 13h6M9 17h4"/>
|
|
11
|
+
{%- elif name == 'sparkles' %}<path d="M12 3l1.8 4.7L18.5 9.5 13.8 11.3 12 16l-1.8-4.7L5.5 9.5l4.7-1.8Z"/><path d="M19 15l.8 2.2L22 18l-2.2.8L19 21l-.8-2.2L16 18l2.2-.8Z"/>
|
|
12
|
+
{%- elif name == 'cpu' %}<rect x="6" y="6" width="12" height="12" rx="2"/><path d="M10 10h4v4h-4zM9 2v4M15 2v4M9 18v4M15 18v4M2 9h4M2 15h4M18 9h4M18 15h4"/>
|
|
13
|
+
{%- elif name == 'info' %}<circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/>
|
|
14
|
+
{%- elif name == 'alert' %}<path d="M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z"/><path d="M12 9v4M12 17h.01"/>
|
|
15
|
+
{%- elif name == 'trash' %}<path d="M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14"/>
|
|
16
|
+
{%- elif name == 'download' %}<path d="M12 4v11"/><path d="m7 10 5 5 5-5"/><path d="M4 20h16"/>
|
|
17
|
+
{%- elif name == 'arrow-right' %}<path d="M5 12h14M13 6l6 6-6 6"/>
|
|
18
|
+
{%- elif name == 'chevron-down' %}<path d="m6 9 6 6 6-6"/>
|
|
19
|
+
{%- elif name == 'chevron-left' %}<path d="m15 6-6 6 6 6"/>
|
|
20
|
+
{%- elif name == 'chevron-right' %}<path d="m9 6 6 6-6 6"/>
|
|
21
|
+
{%- elif name == 'copy' %}<rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V6a2 2 0 0 1 2-2h9"/>
|
|
22
|
+
{%- elif name == 'external' %}<path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/>
|
|
23
|
+
{%- elif name == 'swap' %}<path d="M7 4 3 8l4 4M3 8h14M17 20l4-4-4-4M21 16H7"/>
|
|
24
|
+
{%- elif name == 'inbox' %}<path d="M22 12h-6l-2 3h-4l-2-3H2"/><path d="M5.5 5h13L22 12v6a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-6Z"/>
|
|
25
|
+
{%- elif name == 'home' %}<path d="M3 11 12 4l9 7"/><path d="M5 10v9a1 1 0 0 0 1 1h4v-6h4v6h4a1 1 0 0 0 1-1v-9"/>
|
|
26
|
+
{%- elif name == 'folder' %}<path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"/>
|
|
27
|
+
{%- elif name == 'layers' %}<path d="m12 3 9 5-9 5-9-5Z"/><path d="m3 13 9 5 9-5"/>
|
|
28
|
+
{%- elif name == 'key' %}<circle cx="8" cy="15" r="4"/><path d="m11 12 9-9M17 6l3 3M14 9l2 2"/>
|
|
29
|
+
{%- elif name == 'help' %}<circle cx="12" cy="12" r="9"/><path d="M9.5 9.5a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .9-1 1.6v.6M12 17h.01"/>
|
|
30
|
+
{%- elif name == 'eye' %}<path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/>
|
|
31
|
+
{%- elif name == 'text' %}<path d="M4 6h16M4 10h16M4 14h10M4 18h13"/>
|
|
32
|
+
{%- elif name == 'type' %}<path d="M5 7V5h14v2M12 5v14M9 19h6"/>
|
|
33
|
+
{%- elif name == 'columns' %}<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M12 4v16"/>
|
|
34
|
+
{%- elif name == 'diff' %}<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M12 4v16M5.5 12h4M14.5 12h4M16.5 10v4"/>
|
|
35
|
+
{%- elif name == 'play' %}<path d="M7 4.5v15a.5.5 0 0 0 .8.4l11-7.5a.5.5 0 0 0 0-.8l-11-7.5a.5.5 0 0 0-.8.4Z"/>
|
|
36
|
+
{%- elif name == 'refresh' %}<path d="M20 11a8 8 0 0 0-14.6-4.5L4 8"/><path d="M4 4v4h4"/><path d="M4 13a8 8 0 0 0 14.6 4.5L20 16"/><path d="M20 20v-4h-4"/>
|
|
37
|
+
{%- elif name == 'zoom-in' %}<circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5M8 11h6M11 8v6"/>
|
|
38
|
+
{%- elif name == 'zoom-out' %}<circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5M8 11h6"/>
|
|
39
|
+
{%- elif name == 'maximize' %}<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>
|
|
40
|
+
{%- elif name == 'image' %}<rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="9" cy="10" r="2"/><path d="m21 16-5-5-9 9"/>
|
|
41
|
+
{%- elif name == 'check' %}<path d="m5 12 5 5 9-10"/>
|
|
42
|
+
{%- elif name == 'plug' %}<path d="M9 3v5M15 3v5M6 8h12v3a6 6 0 0 1-12 0Z"/><path d="M12 17v4"/>
|
|
43
|
+
{%- elif name == 'book' %}<path d="M3 5a2 2 0 0 1 2-1h5a2 2 0 0 1 2 2v14a2 2 0 0 0-2-2H3Z"/><path d="M21 5a2 2 0 0 0-2-1h-5a2 2 0 0 0-2 2v14a2 2 0 0 1 2-2h7Z"/>
|
|
44
|
+
{%- elif name == 'settings' %}<path d="M4 6h10M18 6h2M4 12h4M12 12h8M4 18h12M20 18h0"/><circle cx="16" cy="6" r="2"/><circle cx="10" cy="12" r="2"/><circle cx="18" cy="18" r="2"/>
|
|
45
|
+
{%- elif name == 'grid' %}<rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><rect x="14" y="14" width="7" height="7" rx="1.5"/>
|
|
46
|
+
{%- elif name == 'clock' %}<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>
|
|
47
|
+
{%- elif name == 'code' %}<path d="m8 8-4 4 4 4M16 8l4 4-4 4M14 5l-4 14"/>
|
|
48
|
+
{%- elif name == 'github' %}<path d="M9 19c-4 1.5-4-2-6-2.5M15 21v-3.5a3 3 0 0 0-.9-2.4c3-.3 6-1.5 6-6.6a5 5 0 0 0-1.4-3.6 4.6 4.6 0 0 0-.1-3.5s-1.1-.3-3.6 1.4a12.4 12.4 0 0 0-6.5 0C6 1.1 4.9 1.4 4.9 1.4a4.6 4.6 0 0 0-.1 3.5A5 5 0 0 0 3.4 8.5c0 5.1 3 6.3 6 6.6a3 3 0 0 0-.9 2.4V21"/>
|
|
49
|
+
{%- elif name == 'x' %}<path d="M6 6l12 12M18 6 6 18"/>
|
|
50
|
+
{%- elif name == 'pencil' %}<path d="M4 20h4L19 9l-4-4L4 16Z"/><path d="m13 7 4 4"/>
|
|
51
|
+
{%- elif name == 'shuffle' %}<path d="M3 7h3c4 0 6 10 10 10h5M3 17h3c1.6 0 2.8-1.6 3.9-3.6M14 10c.6-1.7 1.4-3 2-3h5"/><path d="m18 4 3 3-3 3M18 14l3 3-3 3"/>
|
|
52
|
+
{%- elif name == 'folders' %}<path d="M7 8a2 2 0 0 1 2-2h3l2 2h6a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H9a2 2 0 0 1-2-2Z"/><path d="M3 11v7a2 2 0 0 0 2 2h11"/>
|
|
53
|
+
{%- endif -%}
|
|
54
|
+
</svg>
|
|
55
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{# Provider / model / prompt picker. common.js fills it from /api/config. #}
|
|
2
|
+
<div class="llm-picker" data-llm-picker>
|
|
3
|
+
<label>Provider <select data-provider></select></label>
|
|
4
|
+
<label>Model <input data-model list="{{ picker_id|default('pk') }}-models" autocomplete="off">
|
|
5
|
+
<datalist id="{{ picker_id|default('pk') }}-models"></datalist></label>
|
|
6
|
+
<label>Prompt <select data-prompt></select></label>
|
|
7
|
+
<details data-custom-box hidden class="custom-prompt">
|
|
8
|
+
<summary>Custom prompt</summary>
|
|
9
|
+
<textarea data-custom rows="7"></textarea>
|
|
10
|
+
</details>
|
|
11
|
+
<div class="picker-status small" data-status></div>
|
|
12
|
+
</div>
|