Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

feat(gradio): inject host document operations

myhlolic50c61908c87
diff --git a/docs/next/cli/mineru-kit-webui.md b/docs/next/cli/mineru-kit-webui.md
index 074aa2f1..a964b35d 100644
--- a/docs/next/cli/mineru-kit-webui.md
+++ b/docs/next/cli/mineru-kit-webui.md
@@ -148,3 +148,15 @@ PDF 和图片会生成与解析范围一致的 `origin.pdf`;布局预览使用
`mineru-webui` 提供为 `mineru-kit webui` 的独立命令名,参数与行为完全相同;旧 HTTP 协议和旧 Gradio 专属参数不再提供。
Gradio 使用 Tasks 能力发现和逐文件 `upload` 描述,固定使用 PUT 上传;仅保存 Middle JSON 和素材,下载菜单从保存的 Middle JSON 按需导出。
+
+## 嵌入宿主的文档操作
+
+`mineru.kit.gradio` 公开导出 `GradioDocumentIO` 协议。调用 `build_gradio_app()` 时可通过关键字参数
+`document_io` 注入宿主实现,统一接管 `pdf_page_metadata()`、`effective_page_range()` 和
+`persist_parse_result()`。不传时沿用进程内的页数读取、选页校验和产物保存。
+
+界面页数回调与转换服务共享同一实例,各应用之间互不影响。选页与持久化仍在工作线程中执行,
+取消必须等待同步工作结束后再释放转换槽。实现的构造过程应只定义行为,不启动进程、打开 PDF 或加载模型。
+
+HF Demo 使用该接口将三类操作委托 CPU sidecar,生产与预检共用界面构建入口,不再替换 Gradio 模块函数。
+HF 适配代码要求支持此协议与 `document_io` 参数的 MinerU;跨越该接口升级边界时,应成对更新或回滚宿主与 MinerU。
diff --git a/mineru/kit/gradio/__init__.py b/mineru/kit/gradio/__init__.py
index 97f01308..eddbdcce 100644
--- a/mineru/kit/gradio/__init__.py
+++ b/mineru/kit/gradio/__init__.py
@@ -2,9 +2,11 @@
from .app import build_gradio_app, launch_gradio
from .client import GradioArtifactClient, ManagedLocalApiServer, V1ArtifactClient, V1ArtifactError, V1ServerCapabilities
+from .document_io import GradioDocumentIO
__all__ = [
"GradioArtifactClient",
+ "GradioDocumentIO",
"ManagedLocalApiServer",
"V1ArtifactClient",
"V1ArtifactError",
diff --git a/mineru/kit/gradio/app.py b/mineru/kit/gradio/app.py
index 4a2fe758..52cb1d0b 100644
--- a/mineru/kit/gradio/app.py
+++ b/mineru/kit/gradio/app.py
@@ -33,12 +33,13 @@ from .client import (
V1ServerCapabilities,
)
from .conversion import ConversionInput, SessionConversions, await_task_completion
-from .conversion_service import ConversionService
+from .conversion_service import ConversionService, ParseClient
from .conversion_ui import build_conversion_receipt, conversion_updates, download_updates
+from .document_io import GradioDocumentIO, LocalGradioDocumentIO
from .epub_preview import register_epub_preview_resources
from .i18n import MESSAGES, localized_text, preview_placeholder, translations
from .lifecycle import with_setup_loop
-from .page_range import pdf_page_metadata, validate_max_pages
+from .page_range import validate_max_pages
from .pdf_preview import pdf_preview_js, register_pdf_preview_resources
from .source_preview import prepare_source_preview
from .status import (
@@ -347,13 +348,14 @@ def _pdf_preview_update(gr: Any, value: str | None) -> Any:
@with_setup_loop
def build_gradio_app(
- client: V1ArtifactClient | GradioArtifactClient,
+ client: ParseClient,
capabilities: V1ServerCapabilities,
*,
output_root: Path,
enable_example: bool = True,
enable_api: bool = True,
max_pages: int | None = None,
+ document_io: GradioDocumentIO | None = None,
) -> Any:
"""构建不启动监听端口的 Gradio Blocks 应用,便于单元测试和外部托管。"""
import gradio as gr
@@ -361,6 +363,7 @@ def build_gradio_app(
viewer_entry = register_pdf_preview_resources()
epub_viewer_entry = register_epub_preview_resources()
validate_max_pages(max_pages)
+ document_io = document_io if document_io is not None else LocalGradioDocumentIO()
tier_choices = [tier for tier in TIERS if tier in capabilities.tiers]
if not tier_choices:
raise ValueError("V1 API server did not advertise any parsing tier")
@@ -388,6 +391,7 @@ def build_gradio_app(
output_root=output_root,
max_pages=max_pages,
slot=conversions.slot,
+ document_io=document_io,
)
with gr.Blocks() as demo:
@@ -790,7 +794,7 @@ def build_gradio_app(
def read_page_metadata(file_path: str | None) -> str:
"""把页数元数据编码为 JSON 文本,保持前端状态输入契约稳定。"""
- return json.dumps(pdf_page_metadata(file_path), ensure_ascii=False)
+ return json.dumps(document_io.pdf_page_metadata(file_path), ensure_ascii=False)
input_file.change(
fn=read_page_metadata,
diff --git a/mineru/kit/gradio/conversion_service.py b/mineru/kit/gradio/conversion_service.py
index abf5e65f..81448fef 100644
--- a/mineru/kit/gradio/conversion_service.py
+++ b/mineru/kit/gradio/conversion_service.py
@@ -24,7 +24,7 @@ from ...filetypes import (
)
from ...parser.base import ParseResult
from ...types import Tier
-from .artifacts import RunArtifacts, persist_parse_result, render_html_preview
+from .artifacts import RunArtifacts, render_html_preview
from .conversion import (
ConversionCancelled,
ConversionFailure,
@@ -37,7 +37,8 @@ from .conversion import (
await_task_completion,
run_sync_output,
)
-from .page_range import effective_page_range, validate_max_pages
+from .document_io import GradioDocumentIO, LocalGradioDocumentIO
+from .page_range import validate_max_pages
from .status import (
STATUS_COMPLETED,
STATUS_PREPARING_REQUEST,
@@ -83,6 +84,7 @@ class ConversionService:
output_root: Path,
max_pages: int | None,
slot: asyncio.Semaphore,
+ document_io: GradioDocumentIO | None = None,
) -> None:
"""显式接收解析能力、产物目录、页数限制和共享执行槽。"""
validate_max_pages(max_pages)
@@ -91,6 +93,7 @@ class ConversionService:
self.output_root = output_root
self.max_pages = max_pages
self.slot = slot
+ self.document_io = document_io if document_io is not None else LocalGradioDocumentIO()
async def execute(
self,
@@ -166,7 +169,7 @@ class ConversionService:
async with self.slot:
run.publish(STATUS_PREPARING_REQUEST)
page_text = await run_sync_output(
- effective_page_range, validated.source_path, inputs.page_range, max_pages=self.max_pages
+ self.document_io.effective_page_range, validated.source_path, inputs.page_range, max_pages=self.max_pages
)
result = await self.client.parse_file(
validated.source_path,
@@ -180,7 +183,7 @@ class ConversionService:
run.publish(STATUS_PROCESSING_OUTPUT)
output_started = time.monotonic()
artifacts = await run_sync_output(
- persist_parse_result,
+ self.document_io.persist_parse_result,
result,
validated.source_path,
output_root=self.output_root,
diff --git a/mineru/kit/gradio/document_io.py b/mineru/kit/gradio/document_io.py
new file mode 100644
index 00000000..a8badeac
--- /dev/null
+++ b/mineru/kit/gradio/document_io.py
@@ -0,0 +1,72 @@
+"""Gradio 宿主可替换的文档读写边界,显式隔离 PDFium 与产物持久化。"""
+
+from __future__ import annotations
+
+from pathlib import Path
+from typing import Protocol
+
+from ...parser.base import ParseResult
+from . import artifacts, page_range
+from .artifacts import RunArtifacts
+from .page_range import PdfPageMetadata
+
+
+class GradioDocumentIO(Protocol):
+ """定义界面和转换服务共享的同步文档操作,不约束宿主的进程实现。"""
+
+ def pdf_page_metadata(self, file_path: str | None) -> PdfPageMetadata:
+ """读取上传文件页数,返回可序列化的文件身份、页数和错误。"""
+ ...
+
+ def effective_page_range(
+ self,
+ path: str | Path | None,
+ raw_page_range: str | None,
+ *,
+ max_pages: int | None = None,
+ ) -> str:
+ """校验实际页范围及页数上限,保留既有范围规范化语义。"""
+ ...
+
+ def persist_parse_result(
+ self,
+ result: ParseResult,
+ source_path: Path,
+ *,
+ output_root: Path,
+ page_range: str,
+ ) -> RunArtifacts:
+ """物化解析结果及布局预览,只返回路径和可序列化的产物描述。"""
+ ...
+
+
+class LocalGradioDocumentIO:
+ """普通 WebUI 的进程内实现,实例化时不打开文档或创建目录。"""
+
+ def pdf_page_metadata(self, file_path: str | None) -> PdfPageMetadata:
+ """委托现有页数读取实现,沿用共享 PDFium 锁和错误格式。"""
+ return page_range.pdf_page_metadata(file_path)
+
+ def effective_page_range(
+ self,
+ path: str | Path | None,
+ raw_page_range: str | None,
+ *,
+ max_pages: int | None = None,
+ ) -> str:
+ """委托现有选页逻辑,保持整本解析和最大页数限制。"""
+ return page_range.effective_page_range(path, raw_page_range, max_pages=max_pages)
+
+ def persist_parse_result(
+ self,
+ result: ParseResult,
+ source_path: Path,
+ *,
+ output_root: Path,
+ page_range: str,
+ ) -> RunArtifacts:
+ """委托现有持久化实现,不在适配层保留解析树或 PDF 对象。"""
+ return artifacts.persist_parse_result(result, source_path, output_root=output_root, page_range=page_range)
+
+
+__all__ = ["GradioDocumentIO", "LocalGradioDocumentIO"]
diff --git a/tests/unittest/test_kit_gradio.py b/tests/unittest/test_kit_gradio.py
index 4ae4b394..024ec304 100644
--- a/tests/unittest/test_kit_gradio.py
+++ b/tests/unittest/test_kit_gradio.py
@@ -26,7 +26,7 @@ from mineru.filetypes import FLASH_ONLY_PARSE_EXTENSIONS, IMAGE_EXTENSIONS, PARS
from mineru.integrations.docvortex import build_metadata
from mineru.kit.commands import webui as webui_command
from mineru.kit.gradio import app as gradio_app
-from mineru.kit.gradio import conversion_service
+from mineru.kit.gradio import document_io
from mineru.kit.gradio.page_range import effective_page_range
from mineru.kit.gradio import client as gradio_client
from mineru.kit.gradio.app import build_gradio_app
@@ -1546,7 +1546,7 @@ def test_gradio_output_failure_stops_timer_and_allows_next_conversion(tmp_path:
"""模拟产物磁盘写入失败。"""
raise OSError("output disk unavailable")
- monkeypatch.setattr(conversion_service, "persist_parse_result", fail_persistence)
+ monkeypatch.setattr(document_io.artifacts, "persist_parse_result", fail_persistence)
capabilities = V1ServerCapabilities("http://127.0.0.1:1", ("flash",), ("default",), ("upload",))
demo = build_gradio_app(CompletedClient(), capabilities, output_root=tmp_path, enable_example=False)
handler = next(fn.fn for fn in demo.fns.values() if fn.name == "convert_handler")
@@ -1660,7 +1660,7 @@ def test_gradio_slow_precheck_keeps_polling_available_and_queues_other_sessions(
assert release.wait(10)
return "1"
- monkeypatch.setattr(conversion_service, "effective_page_range", precheck)
+ monkeypatch.setattr(document_io.page_range, "effective_page_range", precheck)
client = SimpleNamespace(parse_file=AsyncMock(side_effect=V1ArtifactError("test finished")))
capabilities = V1ServerCapabilities("http://127.0.0.1:1", ("flash",), ("default",), ("upload",))
demo = build_gradio_app(client, capabilities, output_root=tmp_path / "output", enable_example=False)
diff --git a/tests/unittest/test_kit_gradio_conversion.py b/tests/unittest/test_kit_gradio_conversion.py
index 7e728273..bf3ffdee 100644
--- a/tests/unittest/test_kit_gradio_conversion.py
+++ b/tests/unittest/test_kit_gradio_conversion.py
@@ -16,7 +16,7 @@ from urllib.parse import unquote
import pytest
-from mineru.kit.gradio import conversion_service
+from mineru.kit.gradio import document_io
from mineru.kit.gradio import app as gradio_app
from mineru.kit.gradio.client import V1ArtifactError, V1ServerCapabilities
from mineru.kit.gradio.conversion import ConversionRun, SessionConversions
@@ -281,7 +281,7 @@ def test_cancelled_sync_output_keeps_slot_until_thread_exits(tmp_path: Path, mon
source = tmp_path / "source.pdf"
source.write_bytes(_pdf_bytes())
started, release = threading.Event(), threading.Event()
- persist = conversion_service.persist_parse_result
+ persist = document_io.artifacts.persist_parse_result
client = SimpleNamespace(parse_file=AsyncMock(return_value=ParseResult(middle_json=_middle_json(with_image=False))))
calls = 0
@@ -294,7 +294,7 @@ def test_cancelled_sync_output_keeps_slot_until_thread_exits(tmp_path: Path, mon
assert release.wait(10)
return persist(*args, **kwargs)
- monkeypatch.setattr(conversion_service, "persist_parse_result", slow_output)
+ monkeypatch.setattr(document_io.artifacts, "persist_parse_result", slow_output)
app = _application(tmp_path, client)
convert, poll, cancel = (_callback(app, name) for name in ("convert_ui", "read_conversion_status", "cancel_ui_conversion"))
request = SimpleNamespace(session_hash="same-session")
diff --git a/tests/unittest/test_kit_gradio_document_io.py b/tests/unittest/test_kit_gradio_document_io.py
new file mode 100644
index 00000000..6aaaa815
--- /dev/null
+++ b/tests/unittest/test_kit_gradio_document_io.py
@@ -0,0 +1,219 @@
+"""验证宿主文档操作的完整回调接入、应用隔离及取消边界。"""
+
+from __future__ import annotations
+
+import asyncio
+import json
+import threading
+from pathlib import Path
+from types import SimpleNamespace
+from typing import Literal
+from unittest.mock import AsyncMock
+
+import pytest
+
+from mineru.kit.gradio import GradioDocumentIO, build_gradio_app
+from mineru.kit.gradio.artifacts import RunArtifacts
+from mineru.kit.gradio.client import V1ServerCapabilities
+from mineru.kit.gradio.conversion import ConversionCancelled, ConversionInput, ConversionRun, ConversionSuccess
+from mineru.kit.gradio.conversion_service import ConversionService
+from mineru.kit.gradio.document_io import LocalGradioDocumentIO
+from mineru.kit.gradio.page_range import PdfPageMetadata
+from mineru.parser.base import ParseResult
+from tests.unittest.test_kit_gradio import _middle_json, _pdf_bytes
+
+
+class _RecordingDocumentIO(LocalGradioDocumentIO):
+ """保留真实文档操作,只记录参数并允许单次失败注入。"""
+
+ def __init__(self) -> None:
+ """每个宿主实例独立保存调用记录和错误开关。"""
+ self.calls: list[tuple[object, ...]] = []
+ self.fail_at: Literal["range", "persist"] | None = None
+
+ def pdf_page_metadata(self, file_path: str | None) -> PdfPageMetadata:
+ """记录上传回调实际选择的宿主,再读取真实页数。"""
+ self.calls.append(("metadata", file_path))
+ return super().pdf_page_metadata(file_path)
+
+ def effective_page_range(
+ self,
+ path: str | Path | None,
+ raw_page_range: str | None,
+ *,
+ max_pages: int | None = None,
+ ) -> str:
+ """记录原始选页文本和上限,必要时模拟宿主预检失败。"""
+ self.calls.append(("range", path, raw_page_range, max_pages))
+ if self.fail_at == "range":
+ raise ValueError("host range unavailable")
+ return super().effective_page_range(path, raw_page_range, max_pages=max_pages)
+
+ def persist_parse_result(
+ self,
+ result: ParseResult,
+ source_path: Path,
+ *,
+ output_root: Path,
+ page_range: str,
+ ) -> RunArtifacts:
+ """记录输出目录及规范化范围,不在记录中延长解析树生命周期。"""
+ self.calls.append(("persist", source_path, output_root, page_range))
+ if self.fail_at == "persist":
+ raise OSError("host persistence unavailable")
+ return super().persist_parse_result(result, source_path, output_root=output_root, page_range=page_range)
+
+
[email protected]("callback_name", ["convert_handler", "convert_ui"])
+def test_callbacks_share_injected_io_without_crossing_app_instances(tmp_path: Path, callback_name: str) -> None:
+ """两个真实界面交错执行元数据和转换回调,验证宿主实例、选页和输出互不串用。"""
+ source = tmp_path / "source.pdf"
+ source.write_bytes(_pdf_bytes(page_count=2))
+ hosts = [_RecordingDocumentIO(), _RecordingDocumentIO()]
+ clients = [
+ SimpleNamespace(parse_file=AsyncMock(return_value=ParseResult(middle_json=_middle_json(page_indices=(index,)))))
+ for index in range(2)
+ ]
+ capabilities = V1ServerCapabilities("http://localhost:1", ("flash",), ("default",), ("upload",))
+ apps = [
+ build_gradio_app(
+ client,
+ capabilities,
+ output_root=tmp_path / f"output-{index}",
+ enable_example=False,
+ max_pages=index + 1,
+ document_io=host,
+ )
+ for index, (client, host) in enumerate(zip(clients, hosts))
+ ]
+
+ async def scenario() -> None:
+ """第二个应用构建后再运行第一个,防止全局替换被最终实例覆盖。"""
+ for index, (app, host, client) in enumerate(zip(apps, hosts, clients)):
+ callbacks = {function.name: function.fn for function in app.fns.values()}
+ metadata = json.loads(callbacks["read_page_metadata"](str(source)))
+ assert metadata == {"path": str(source), "page_count": 2, "error": ""}
+ raw_range = f" {index + 1} "
+ if callback_name == "convert_handler":
+ outputs = await callbacks[callback_name](str(source), 0, raw_range, True)
+ state = outputs[6]
+ else:
+ ticket = json.dumps({"run_id": f"{index + 1:032x}", "revision": 1})
+ request = SimpleNamespace(session_hash="same-session")
+ receipt = json.loads(await callbacks[callback_name](str(source), 0, raw_range, True, ticket, request))
+ outputs = receipt["outputs"]
+ state = {"root": str(Path(outputs[2]["value"]["path"]).parent)}
+ assert Path(state["root"]).name == outputs[6]
+ assert receipt["run_id"] == f"{index + 1:032x}"
+ assert "Completed" in outputs[0] and outputs[1] and outputs[-1]
+ assert Path(state["root"]).parent == tmp_path / f"output-{index}" / "gradio"
+ assert host.calls == [
+ ("metadata", str(source)),
+ ("range", source.resolve(), raw_range, index + 1),
+ ("persist", source.resolve(), tmp_path / f"output-{index}", str(index + 1)),
+ ]
+ client.parse_file.assert_awaited_once()
+ assert client.parse_file.call_args.kwargs["page_range"] == str(index + 1)
+ assert client.parse_file.call_args.kwargs["ocr_mode"] == "ocr"
+
+ try:
+ asyncio.run(scenario())
+ finally:
+ for app in apps:
+ app.close()
+
+
[email protected]("stage", ["range", "persist"])
+def test_host_failure_returns_error_and_allows_next_conversion(tmp_path: Path, stage: Literal["range", "persist"]) -> None:
+ """宿主页范围或保存失败不能生成可下载状态,也不能阻塞下一次转换。"""
+ source = tmp_path / "source.pdf"
+ source.write_bytes(_pdf_bytes())
+ host = _RecordingDocumentIO()
+ host.fail_at = stage
+ client = SimpleNamespace(parse_file=AsyncMock(return_value=ParseResult(middle_json=_middle_json(with_image=False))))
+ app = build_gradio_app(
+ client,
+ V1ServerCapabilities("http://localhost:1", ("flash",), ("default",), ("upload",)),
+ output_root=tmp_path / "output",
+ enable_example=False,
+ document_io=host,
+ )
+ convert = next(function.fn for function in app.fns.values() if function.name == "convert_handler")
+
+ async def scenario() -> None:
+ """首次失败后解除故障,下一次请求必须正常完成。"""
+ failed = await convert(str(source), 0, "1")
+ error = "host range unavailable" if stage == "range" else "host persistence unavailable"
+ assert f"Failed: {error}" in failed[0] and failed[6] is None
+ assert client.parse_file.await_count == (0 if stage == "range" else 1)
+ assert all(update["interactive"] is False for update in failed[8:15])
+ host.fail_at = None
+ completed = await convert(str(source), 0, "1")
+ assert "Completed" in completed[0] and completed[6]
+
+ try:
+ asyncio.run(scenario())
+ finally:
+ app.close()
+
+
[email protected]("stage", ["range", "persist"])
+def test_cancelled_host_work_retains_slot_until_sync_operation_finishes(tmp_path: Path, stage: str) -> None:
+ """注入的同步预检和保存被取消时,仍等待线程退出后才接纳下一份转换。"""
+ source = tmp_path / "source.pdf"
+ source.write_bytes(_pdf_bytes())
+ started, release = threading.Event(), threading.Event()
+
+ class BlockingDocumentIO(LocalGradioDocumentIO):
+ """仅阻塞第一次指定操作,验证取消与后续请求的真实互斥。"""
+
+ def wait_once(self, operation: str) -> None:
+ """在可控事件上等待,异常路径也由测试最终释放。"""
+ if operation == stage and not started.is_set():
+ started.set()
+ assert release.wait(10)
+
+ def effective_page_range(
+ self, path: str | Path | None, raw_page_range: str | None, *, max_pages: int | None = None
+ ) -> str:
+ """预检完成前持续占用转换槽。"""
+ self.wait_once("range")
+ return super().effective_page_range(path, raw_page_range, max_pages=max_pages)
+
+ def persist_parse_result(
+ self, result: ParseResult, source_path: Path, *, output_root: Path, page_range: str
+ ) -> RunArtifacts:
+ """保存完成前持续占用转换槽。"""
+ self.wait_once("persist")
+ return super().persist_parse_result(result, source_path, output_root=output_root, page_range=page_range)
+
+ async def scenario() -> None:
+ """失效旧任务并排队新任务,确认完成后只有新结果可被消费。"""
+ slot = asyncio.Semaphore(1)
+ host: GradioDocumentIO = BlockingDocumentIO()
+ client = SimpleNamespace(parse_file=AsyncMock(return_value=ParseResult(middle_json=_middle_json(with_image=False))))
+ service = ConversionService(
+ client, tier_choices=("flash",), output_root=tmp_path / "output", max_pages=1, slot=slot, document_io=host
+ )
+ old_run, new_run = ConversionRun("old"), ConversionRun("new")
+ inputs = ConversionInput(str(source), 0, "1")
+ first = asyncio.create_task(service.execute(old_run, inputs, public_base_url="http://localhost:7860"))
+ tasks = [first]
+ try:
+ assert await asyncio.to_thread(started.wait, 3)
+ old_run.cancel()
+ second = asyncio.create_task(service.execute(new_run, inputs, public_base_url="http://localhost:7860"))
+ tasks.append(second)
+ await asyncio.sleep(0.03)
+ assert slot.locked() and not first.done() and not second.done()
+ assert client.parse_file.await_count == (0 if stage == "range" else 1)
+ assert "Queued locally" in new_run.state.message
+ release.set()
+ assert isinstance(await first, ConversionCancelled)
+ assert isinstance(await second, ConversionSuccess)
+ assert old_run.artifacts is None and new_run.artifacts is not None and not slot.locked()
+ finally:
+ release.set()
+ await asyncio.gather(*tasks, return_exceptions=True)
+
+ asyncio.run(scenario())
diff --git a/tests/unittest/test_kit_gradio_i18n.py b/tests/unittest/test_kit_gradio_i18n.py
index 909ecd2d..d310c2d0 100644
--- a/tests/unittest/test_kit_gradio_i18n.py
+++ b/tests/unittest/test_kit_gradio_i18n.py
@@ -91,7 +91,7 @@ def test_conversion_preserves_all_preview_components_until_success(
outcome: str,
) -> None:
"""暂停普通转换请求,确认处理期间不发送预览更新且失败保留已有四种预览。"""
- from mineru.kit.gradio import conversion_service
+ from mineru.kit.gradio import document_io
source = tmp_path / "document.csv"
source.write_text("a,b\n1,2\n", encoding="utf-8")
@@ -115,7 +115,7 @@ def test_conversion_preserves_all_preview_components_until_success(
raise OSError("test output failure")
if outcome == "output_failure":
- monkeypatch.setattr(conversion_service, "persist_parse_result", fail_output)
+ monkeypatch.setattr(document_io.artifacts, "persist_parse_result", fail_output)
demo = build_gradio_app(
SimpleNamespace(parse_file=parse_file),
V1ServerCapabilities("http://localhost:1", ("flash",), ("zip",), ("file_id",)),
diff --git a/tests/unittest/test_kit_gradio_office_preview.py b/tests/unittest/test_kit_gradio_office_preview.py
index b3a31c5e..8b4f9263 100644
--- a/tests/unittest/test_kit_gradio_office_preview.py
+++ b/tests/unittest/test_kit_gradio_office_preview.py
@@ -14,7 +14,7 @@ import pytest
from mineru.filetypes import OFFICE_EXTENSIONS
from mineru.kit.gradio import app as app_module
-from mineru.kit.gradio import conversion_service
+from mineru.kit.gradio import document_io
from mineru.kit.gradio.client import V1ServerCapabilities
from mineru.kit.gradio.i18n import MESSAGES
from mineru.parser.base import ParseResult
@@ -116,7 +116,7 @@ def test_office_conversion_never_replaces_uploaded_preview(
raise OSError("output unavailable")
if outcome == "output_failure":
- monkeypatch.setattr(conversion_service, "persist_parse_result", fail_output)
+ monkeypatch.setattr(document_io.artifacts, "persist_parse_result", fail_output)
demo = app_module.build_gradio_app(
SimpleNamespace(parse_file=parse),
V1ServerCapabilities("http://localhost:1", ("flash",), ("zip",), ("file_id",)),