Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:lipstick: Improve OCR model file selection controls https://github.com/siyuan-note/siyuan/issues/20430

Daniel8ecb053ce5b7
diff --git a/app/src/config/ocr.test.ts b/app/src/config/ocr.test.ts
index 7e539754d9..14cce206bc 100644
--- a/app/src/config/ocr.test.ts
+++ b/app/src/config/ocr.test.ts
@@ -63,6 +63,7 @@ const createOCRPanel = async () => {
const controls = Object.fromEntries([
"ocrProvider", "ocrModel", "ocrAIModel", "ocrReasoningEffort", "ocrAuto", "ocrImportModels", "ocrImport",
"detector", "detectorConfig", "recognizer", "recognizerConfig",
+ "detectorName", "detectorConfigName", "recognizerName", "recognizerConfigName",
"ocrThreshold_detection", "ocrThreshold_box", "ocrThreshold_recognition",
].map(id => [id, {
id, value: id === "ocrProvider" ? "paddleocr" : id === "ocrAIModel" || id === "ocrReasoningEffort" ? "" : "tiny", checked: false, disabled: false, innerHTML: "",
diff --git a/app/src/config/ocr.ts b/app/src/config/ocr.ts
index fe212168ed..50a2a52c3a 100644
--- a/app/src/config/ocr.ts
+++ b/app/src/config/ocr.ts
@@ -77,7 +77,9 @@ export const registerOCRTab = (tab: SettingTabBuilder) => {
key: "ocrImportModels",
keywords: ["ONNX", "YAML", "Tiny", languages.ocrImportModels, languages.ocrDetector, languages.ocrRecognizer],
html: () => `<div id="ocrImportModels" class="b3-label config-item">${genConfigItemMainHtml(languages.ocrImportModels, languages.ocrImportModelsTip)}
-${getModelFiles().map(file => `<div class="fn__hr"></div><label class="fn__block"><span class="b3-label__text">${file.title}</span><div class="fn__hr--small"></div><input id="${file.id}" class="b3-text-field fn__block" type="file" accept="${file.suffix.split(",").map(suffix => `.${suffix}`).join(",")}"></label>`).join("")}</div>`,
+${getModelFiles().map(file => `<div class="fn__hr"></div><div class="fn__block"><div id="${file.id}Label" class="b3-label__text">${file.title}</div><div class="fn__hr--small"></div>
+<div class="fn__flex"><button type="button" class="b3-button b3-button--outline fn__flex-center" data-ocr-file="${file.id}" aria-describedby="${file.id}Label">${languages.select}</button><span class="fn__space"></span><span id="${file.id}Name" class="fn__flex-1 fn__flex-center fn__ellipsis" aria-live="polite"></span></div>
+<input id="${file.id}" class="fn__none" type="file" accept="${file.suffix.split(",").map(suffix => `.${suffix}`).join(",")}"></div>`).join("")}</div>`,
}).slot({
key: "ocrImport",
keywords: ["ONNX", "YAML", languages.ocrImportModels, languages.import],
@@ -135,6 +137,11 @@ export const mountOCRSettings = (root: HTMLElement): (() => void) => {
root.querySelector<HTMLInputElement>(`#ocrThreshold_${field.key}`).disabled = busy || !isPaddleOCR;
});
root.querySelector<HTMLButtonElement>("#ocrImport").disabled = busy || pendingSaves > 0 || !isPaddleOCR || files.some(file => !root.querySelector<HTMLInputElement>(`#${file.id}`).files?.length);
+ files.forEach(file => {
+ const name = root.querySelector<HTMLElement>(`#${file.id}Name`);
+ name.textContent = root.querySelector<HTMLInputElement>(`#${file.id}`).files?.[0]?.name || "";
+ name.title = name.textContent;
+ });
};
const providerOptions = () => {
const providers = [...data.providers].sort((left, right) => Number(right.id === "paddleocr") - Number(left.id === "paddleocr"));
@@ -337,7 +344,9 @@ export const mountOCRSettings = (root: HTMLElement): (() => void) => {
if (!button || busy || pendingSaves > 0 || !data) {
return;
}
- if (button.id === "ocrImport") {
+ if (button.dataset.ocrFile && files.some(file => file.id === button.dataset.ocrFile)) {
+ root.querySelector<HTMLInputElement>(`#${button.dataset.ocrFile}`).click();
+ } else if (button.id === "ocrImport") {
writeRevision++;
busy = true;
updateControls();