Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
feat(webui): add file type icons and clarify upload completion
myhloli32f8df00a167
diff --git a/mineru/resources/gradio_app.css b/mineru/resources/gradio_app.cssindex e21e0fa6..f6900ff6 100644--- a/mineru/resources/gradio_app.css+++ b/mineru/resources/gradio_app.css@@ -438,15 +438,32 @@ body.dark .gradio-container {.dark .mineru-upload-fill { background: rgba(249, 115, 22, 0.18); }.mineru-upload-file-row.is-settled .mineru-upload-fill { opacity: 0; }.mineru-upload-file-icon {- display: flex; align-items: center; justify-content: center; flex: 0 0 30px; width: 30px; height: 38px;+ position: relative; display: flex; align-items: center; justify-content: center;+ flex: none; width: 34px; height: 34px; box-sizing: border-box;border-radius: 7px; color: #b95810; background: #fff1e3;}.dark .mineru-upload-file-icon { color: #f4ad72; background: #39291d; }+.mineru-upload-file-icon svg { width: 20px; height: 20px; }+/* PDF/OFD 的纸张和文字共用固定坐标,不受外层 flex 主轴或文件条高度影响。 */+.mineru-upload-file-icon[data-file-kind="pdf"] svg,+.mineru-upload-file-icon[data-file-kind="ofd"] svg {+ position: absolute; left: 5px; top: 1.5px; width: 24px; height: 25px;+}+.mineru-upload-format-badge {+ position: absolute; top: 18px; left: 50%; transform: translateX(-50%); padding: 0 2px;+ color: inherit !important; background: inherit; font-size: 11px; line-height: 13px; font-weight: 500;+ letter-spacing: 0.1px;+}.mineru-upload-details { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; gap: 2px; }.mineru-upload-label { display: flex; min-width: 0; font-size: 14px; font-weight: 500; line-height: 20px; }.mineru-upload-stem { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }.mineru-upload-extension { flex: 0 0 auto; }-.mineru-upload-size { font-size: 12px; line-height: 16px; color: var(--body-text-color-subdued); font-variant-numeric: tabular-nums; }+.mineru-upload-meta {+ display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 4px;+ font-size: 12px; line-height: 16px; color: var(--body-text-color-subdued); font-variant-numeric: tabular-nums;+}+.mineru-upload-meta > span { color: inherit !important; }+.mineru-upload-finished { white-space: nowrap; }.mineru-upload-indicator {display: flex; justify-content: flex-end; align-items: center; flex: 0 0 28px;font-size: 12px; color: var(--body-text-color-subdued); font-variant-numeric: tabular-nums;diff --git a/mineru/resources/gradio_upload.LICENSE b/mineru/resources/gradio_upload.LICENSEindex f7a80122..249c4dab 100644--- a/mineru/resources/gradio_upload.LICENSE+++ b/mineru/resources/gradio_upload.LICENSE@@ -1,5 +1,6 @@Lucide 0.468.0 — upload, square-dashed-mouse-pointer, clipboard-paste,-file-text, image, check and x icons used in gradio_upload.html.+file, file-text, image, file-spreadsheet, presentation, file-code-2,+book-open and x icons used in gradio_upload.html.Source: https://github.com/lucide-icons/lucide/tree/0.468.0ISC Licensediff --git a/mineru/resources/gradio_upload.html b/mineru/resources/gradio_upload.htmlindex 1a97a05b..0c662248 100644--- a/mineru/resources/gradio_upload.html+++ b/mineru/resources/gradio_upload.html@@ -60,30 +60,59 @@</label><div class="mineru-upload-file-row" hidden><span class="mineru-upload-fill" aria-hidden="true"></span>- <span class="mineru-upload-file-icon" aria-hidden="true">- <svg class="mineru-upload-document-icon" xmlns="http://www.w3.org/2000/svg" width="20" height="20"+ <span class="mineru-upload-file-icon" data-file-kind="file" aria-hidden="true">+ <svg data-mineru-upload-icon="file" xmlns="http://www.w3.org/2000/svg" width="20" height="20"viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"stroke-linecap="round" stroke-linejoin="round" focusable="false"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z" />+ <path d="M14 2v4a2 2 0 0 0 2 2h4" />+ </svg>+ <svg class="mineru-upload-document-icon" xmlns="http://www.w3.org/2000/svg" width="20" height="20"+ viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"+ stroke-linecap="round" stroke-linejoin="round" focusable="false" data-mineru-upload-icon="document" hidden>+ <path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z" /><path d="M14 2v4a2 2 0 0 0 2 2h4M10 9H8M16 13H8M16 17H8" /></svg><svg class="mineru-upload-image-icon" xmlns="http://www.w3.org/2000/svg" width="20" height="20"viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"- stroke-linecap="round" stroke-linejoin="round" focusable="false" hidden>+ stroke-linecap="round" stroke-linejoin="round" focusable="false" data-mineru-upload-icon="image" hidden><rect width="18" height="18" x="3" y="3" rx="2" ry="2" /><circle cx="9" cy="9" r="2" /><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" /></svg>+ <svg data-mineru-upload-icon="sheet" xmlns="http://www.w3.org/2000/svg" width="20" height="20"+ viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"+ stroke-linecap="round" stroke-linejoin="round" focusable="false" hidden>+ <path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z" />+ <path d="M14 2v4a2 2 0 0 0 2 2h4M8 13h2M14 13h2M8 17h2M14 17h2" />+ </svg>+ <svg data-mineru-upload-icon="slides" xmlns="http://www.w3.org/2000/svg" width="20" height="20"+ viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"+ stroke-linecap="round" stroke-linejoin="round" focusable="false" hidden>+ <path d="M2 3h20M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3M7 21l5-5 5 5" />+ </svg>+ <svg data-mineru-upload-icon="web" xmlns="http://www.w3.org/2000/svg" width="20" height="20"+ viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"+ stroke-linecap="round" stroke-linejoin="round" focusable="false" hidden>+ <path d="M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4M14 2v4a2 2 0 0 0 2 2h4M5 12l-3 3 3 3M9 18l3-3-3-3" />+ </svg>+ <svg data-mineru-upload-icon="ebook" xmlns="http://www.w3.org/2000/svg" width="20" height="20"+ viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"+ stroke-linecap="round" stroke-linejoin="round" focusable="false" hidden>+ <path d="M12 7v14" />+ <path d="M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z" />+ </svg>+ <span class="mineru-upload-format-badge" hidden></span></span><span class="mineru-upload-details"><span class="mineru-upload-label"><span class="mineru-upload-stem"></span><span class="mineru-upload-extension"></span></span>- <span class="mineru-upload-size"></span>+ <span class="mineru-upload-meta">+ <span class="mineru-upload-size"></span>+ <span class="mineru-upload-finished" hidden></span>+ </span></span><span class="mineru-upload-indicator" aria-hidden="true"><span class="mineru-upload-percent"></span>- <svg class="mineru-upload-complete" xmlns="http://www.w3.org/2000/svg" width="17" height="17"- viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"- stroke-linecap="round" stroke-linejoin="round" focusable="false" hidden><path d="m20 6-11 11-5-5" /></svg></span><button type="button" class="mineru-upload-remove" aria-label="Clear file" title="Clear file"><svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24" fill="none"diff --git a/mineru/resources/gradio_upload.js b/mineru/resources/gradio_upload.jsindex e401e507..15f229ef 100644--- a/mineru/resources/gradio_upload.js+++ b/mineru/resources/gradio_upload.js@@ -19,6 +19,22 @@const text = key => window.__mineruI18n?.text(key) || key;const identity = () => Array.from(crypto.getRandomValues(new Uint8Array(16)), value => value.toString(16).padStart(2, "0")).join("");const isImage = name => imageExtensions.some(extension => name.toLowerCase().endsWith(`.${extension}`));+ // 文件图标只按用途分组,不改变可上传格式;图片仍复用后端提供的扩展名集合。+ const iconByExtension = {+ pdf: "pdf", ofd: "ofd",+ doc: "document", docx: "document", odt: "document", rtf: "document",+ xls: "sheet", xlsx: "sheet", ods: "sheet", csv: "sheet", tsv: "sheet",+ ppt: "slides", pptx: "slides", odp: "slides",+ html: "web", htm: "web", shtml: "web", mhtml: "web", mht: "web",+ epub: "ebook",+ };+ // 大小写后缀使用相同图标,无后缀或未知格式回退到普通文件图标。+ const fileIconKind = name => {+ if (isImage(name)) return "image";+ const dot = name.lastIndexOf(".");+ const extension = dot > 0 ? name.slice(dot + 1).toLowerCase() : "";+ return Object.hasOwn(iconByExtension, extension) ? iconByExtension[extension] : "file";+ };// 本地 File 和 Gradio FileData 共用文件名规则,不把文件名当作 HTML。const fileName = file => file?.orig_name || file?.name || file?.path?.split(/[\\/]/).pop() || "";// 使用十进制单位;未知大小不能伪装成空文件。@@ -41,13 +57,20 @@node("label").title = name;node("size").textContent = pending && progress !== null? `${formatSize(transferred)} / ${formatSize(size)}` : formatSize(size);- node("document-icon").toggleAttribute("hidden", isImage(name));- node("image-icon").toggleAttribute("hidden", !isImage(name));- node("indicator").hidden = !complete && (!pending || progress === null);+ // 完成状态放在文件大小旁,右侧仅保留上传百分比或清除操作。+ node("finished").hidden = !complete;+ node("finished").textContent = `· ${text("upload_complete")}`;+ const kind = fileIconKind(name);+ const hasBadge = kind === "pdf" || kind === "ofd";+ node("file-icon").setAttribute("data-file-kind", kind);+ element.querySelectorAll("[data-mineru-upload-icon]").forEach(icon => {+ icon.toggleAttribute("hidden", icon.dataset.mineruUploadIcon !== (hasBadge ? "file" : kind));+ });+ node("format-badge").hidden = !hasBadge;+ node("format-badge").textContent = hasBadge ? kind.toUpperCase() : "";+ node("indicator").hidden = !pending || progress === null;node("percent").hidden = !pending || progress === null;node("percent").textContent = `${Math.floor(progress || 0)}%`;- node("complete").toggleAttribute("hidden", !complete);- node("complete").setAttribute("aria-label", text("upload_complete"));node("fill").style.width = `${progress || 0}%`;node("fill").hidden = failed || (!pending && !uploadedFile);node("meter").hidden = !pending;diff --git a/tests/unittest/test_kit_gradio_upload.cjs b/tests/unittest/test_kit_gradio_upload.cjsindex d0b4aa51..a1f039d0 100644--- a/tests/unittest/test_kit_gradio_upload.cjs+++ b/tests/unittest/test_kit_gradio_upload.cjs@@ -24,12 +24,15 @@ function makeNode() {};}const names = ["target", "file-row", "stem", "extension", "label", "size", "document-icon", "image-icon", "indicator",- "percent", "complete", "fill", "meter", "remove", "status", "retry"];+ "percent", "finished", "fill", "meter", "remove", "status", "retry", "file-icon", "format-badge"];const nodes = Object.fromEntries(names.map(name => [name, makeNode()]));+const icons = ["file", "document", "image", "sheet", "slides", "web", "ebook"].map(kind =>+ Object.assign(kind === "document" || kind === "image" ? nodes[`${kind}-icon`] : makeNode(), {dataset: {mineruUploadIcon: kind}}));nodes["file-row"].classList = { toggle: (name, value) => value ? nodes["file-row"].classes.add(name) : nodes["file-row"].classes.delete(name) };const input = Object.assign(makeNode(), {value: "", files: []});const element = {querySelector: selector => selector === 'input[type="file"]' ? input : nodes[selector.replace(".mineru-upload-", "")],+ querySelectorAll: selector => selector === "[data-mineru-upload-icon]" ? icons : [],addEventListener: (name, handler) => { handlers[name] = handler; },};const requests = [];@@ -105,7 +108,8 @@ const clear = () => nodes.remove.events.click({preventDefault() {}});assert.equal(nodes.size.textContent, "2.5 KB / 10.0 KB");first.progress(10000, 10000);assert.equal(nodes.status.textContent, "upload_confirming");- assert.equal(nodes.complete.hidden, true);+ assert.equal(nodes.finished.hidden, true);+ assert.equal(nodes.indicator.hidden, false);const secondFile = new File([new Uint8Array(20000)], "same.pdf");handlers.drop({preventDefault() {}, dataTransfer: {files: [secondFile]}});await tick();@@ -125,16 +129,27 @@ const clear = () => nodes.remove.events.click({preventDefault() {}});const data = window.__mineruUpload.bridge(receipt);assert.equal(data.url, context.file_url_prefix + "/cache/new%20%231.pdf");assert.equal(data.size, 20000);- assert.equal(nodes.complete.hidden, false);+ assert.equal(nodes.finished.hidden, false);+ assert.equal(nodes.finished.textContent, "· upload_complete");+ assert.equal(nodes.indicator.hidden, true);+ assert.equal(nodes.percent.hidden, true);+ assert.equal(nodes.size.textContent, "20.0 KB");+ // 语言重新初始化只更新完成文案,不丢失文件大小或重新显示百分比。+ window.__mineruI18n.text = key => key === "upload_complete" ? "已上传" : key;+ window.__mineruUpload.localize();+ assert.equal(nodes.finished.textContent, "· 已上传");assert.equal(nodes.size.textContent, "20.0 KB");+ window.__mineruI18n.text = key => key;assert.equal(window.__mineruUpload.bridge(receipt).__type__, "update");window.__mineruUpload.prepared("prepare failed");assert.equal(nodes.retry.hidden, false);+ assert.equal(nodes.finished.hidden, true);const requestCount = requests.length;nodes.retry.events.click();await tick();assert.equal(requests.length, requestCount);assert.equal(JSON.parse(values.at(-1)).file.path, "/cache/new #1.pdf");+ assert.equal(nodes.finished.hidden, false);assert.equal(window.__mineruUpload.bridge(receipt).__type__, "update");await choose(new File(["file"], '<img src=x onerror=alert(1)>.pdf'));@@ -145,7 +160,9 @@ const clear = () => nodes.remove.events.click({preventDefault() {}});assert.equal(nodes.status.textContent, "File too large");assert.equal(nodes.status.attributes.role, "alert");assert.equal(nodes.retry.hidden, false);+ assert.equal(nodes.finished.hidden, true);nodes.retry.events.click();+ assert.equal(nodes.finished.hidden, true);await tick();assert.notEqual(requests.at(-1), rejected);requests.at(-1).dispatchEvent(new Event("error"));@@ -168,6 +185,7 @@ const clear = () => nodes.remove.events.click({preventDefault() {}});await tick();assert.equal(nodes.target.hidden, false);assert.equal(nodes["file-row"].hidden, true);+ assert.equal(nodes.finished.hidden, true);assert.equal(values.length, beforeClear);assert.equal(window.__mineruUpload.bridge(receipt).__type__, "update");