Skip to content

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

feat: update hybrid effort descriptions and refactor frontend controls for improved clarity

myhlolif3591e956ad8
diff --git a/mineru/cli_old/gradio_app.py b/mineru/cli_old/gradio_app.py
index 9be4cd9e..7cbaab59 100644
--- a/mineru/cli_old/gradio_app.py
+++ b/mineru/cli_old/gradio_app.py
@@ -1674,7 +1674,7 @@ def main(ctx,
"image_analysis_enable": "启用图片分析",
"image_analysis_info": "禁用后,图片/图表块仍保留版面位置,但跳过 VLM 图片/图表分析。",
"effort": "解析强度",
- "effort_info": "Low 使用本地 Hybrid 处理;Medium 速度更快;High 精度更高,耗时可能更长。",
+ "effort_info": "解析强度越高,解析质量越好但速度越慢;解析强度越低,速度更快但质量可能下降。",
"formula_label_vlm": "启用行间公式识别",
"formula_label_hybrid": "启用行内公式识别",
"formula_info_vlm": "禁用后,行间公式将显示为图片。",
@@ -1835,23 +1835,33 @@ def main(ctx,
elem_classes=["mineru-upload-file"],
)
preferred_option = DEFAULT_BACKEND
- backend = gr.Dropdown(
- build_backend_choices(http_client_enable, i18n),
- label=i18n("backend"),
- value=preferred_option,
- info=get_backend_info(preferred_option),
- elem_classes=["mineru-backend-select"],
- )
- with gr.Row(
- visible=frontend_managed_initial_visibility(is_http_client_backend(preferred_option)),
- elem_classes=["mineru-client-options"],
- ) as client_options:
- url = gr.Textbox(
- label=i18n("server_url"),
- value='http://localhost:30000',
- placeholder='http://localhost:30000',
- info=i18n("server_url_info"),
+ with gr.Group(elem_classes=["mineru-backend-options-block"]):
+ backend = gr.Dropdown(
+ build_backend_choices(http_client_enable, i18n),
+ label=i18n("backend"),
+ value=preferred_option,
+ info=get_backend_info(preferred_option),
+ elem_classes=["mineru-backend-select"],
)
+ with gr.Row(
+ visible=frontend_managed_initial_visibility(is_http_client_backend(preferred_option)),
+ elem_classes=["mineru-client-options"],
+ ) as client_options:
+ url = gr.Textbox(
+ label=i18n("server_url"),
+ value='http://localhost:30000',
+ placeholder='http://localhost:30000',
+ info=i18n("server_url_info"),
+ )
+ with gr.Column(elem_classes=["mineru-hybrid-effort-option"]):
+ effort = gr.Dropdown(
+ list(HYBRID_EFFORT_CHOICES),
+ label=i18n("effort"),
+ value=DEFAULT_HYBRID_EFFORT,
+ visible=is_effort_option_visible(preferred_option),
+ info=i18n("effort_info"),
+ elem_classes=["mineru-hybrid-effort"],
+ )
# 下面这些选项在上传 office 文件时会被自动隐藏
with gr.Group() as options_group:
max_pages = gr.Slider(1, max_convert_pages, max_convert_pages, step=1, label=i18n("max_pages"))
@@ -1957,15 +1967,6 @@ def main(ctx,
info=i18n("image_analysis_info"),
elem_classes=["mineru-image-analysis-option"],
)
- with gr.Column(elem_classes=["mineru-hybrid-effort-option"]):
- effort = gr.Radio(
- list(HYBRID_EFFORT_CHOICES),
- label=i18n("effort"),
- value=DEFAULT_HYBRID_EFFORT,
- visible=is_effort_option_visible(preferred_option),
- info=i18n("effort_info"),
- elem_classes=["mineru-hybrid-effort"],
- )
with gr.Column(elem_classes=["mineru-force-ocr-option"]) as ocr_options:
with gr.Group():
with gr.Column(elem_classes=["mineru-ocr-language-options"]):
diff --git a/mineru/resources/gradio_app.js b/mineru/resources/gradio_app.js
index 1ce07d58..9fb8e523 100644
--- a/mineru/resources/gradio_app.js
+++ b/mineru/resources/gradio_app.js
@@ -118,13 +118,11 @@
return (backendControl?.value || backendControl?.textContent || "").trim();
};
- // 读取 Hybrid effort 当前值;控件在非 hybrid 后端会被 Gradio 隐藏,缺失时按空值处理。
+ // 读取 Hybrid effort 下拉框当前值;控件在非 hybrid 后端会被 Gradio 隐藏,缺失时按空值处理。
const getEffortValue = () => {
const effortRoot = findEffortRoot();
- const checkedRadio = effortRoot?.querySelector(
- 'input[type="radio"]:checked, input[type="radio"][aria-checked="true"]'
- );
- return (checkedRadio?.value || "").trim();
+ const effortControl = effortRoot?.querySelector('[role="listbox"]');
+ return (effortControl?.value || effortControl?.textContent || "").trim();
};
// 根据当前 backend/effort 刷新前端状态类,避免依赖 Gradio 重新挂载隐藏组件。
@@ -148,7 +146,7 @@
}
};
- // Gradio 控件会异步写回 value,延后一帧再读可以覆盖 Dropdown option 点击和 Radio 切换。
+ // Gradio 控件会异步写回 value,延后一帧再读可以覆盖 Dropdown option 点击和控件切换。
const queueMineruOptionVisibilityRefresh = () => {
requestAnimationFrame(() => {
refreshMineruOptionVisibility();
diff --git a/mineru/utils/backend_options.py b/mineru/utils/backend_options.py
index 294d75d4..e73ae164 100644
--- a/mineru/utils/backend_options.py
+++ b/mineru/utils/backend_options.py
@@ -7,7 +7,9 @@ CANONICAL_HYBRID_ENGINE: Final = "hybrid-engine"
DEFAULT_BACKEND: Final = CANONICAL_HYBRID_ENGINE
DEFAULT_HYBRID_EFFORT: Final = "medium"
DEFAULT_EFFORT: Final = DEFAULT_HYBRID_EFFORT
-HYBRID_EFFORT_HELP: Final = "Low uses local Hybrid processing. Medium is faster. High is more accurate and may take longer."
+HYBRID_EFFORT_HELP: Final = (
+ "Higher effort improves parsing quality but may be slower; lower effort is faster but may reduce quality."
+)
LOCAL_BACKEND_CHOICES: Final[tuple[str, ...]] = (
CANONICAL_HYBRID_ENGINE,
diff --git a/tests/unittest/test_kit_commands.py b/tests/unittest/test_kit_commands.py
index de89127f..b715ea22 100644
--- a/tests/unittest/test_kit_commands.py
+++ b/tests/unittest/test_kit_commands.py
@@ -537,9 +537,28 @@ def test_gradio_language_option_only_visible_for_hybrid_low() -> None:
def test_gradio_frontend_shows_ocr_language_for_hybrid_low() -> None:
js_text = Path("mineru/resources/gradio_app.js").read_text(encoding="utf-8")
+ assert 'const effortControl = effortRoot?.querySelector(\'[role="listbox"]\');' in js_text
+ assert 'input[type="radio"]' not in js_text
assert 'const showOcrLanguage = backend.startsWith("hybrid") && effort === "low";' in js_text
+def test_gradio_effort_option_is_below_backend_selector() -> None:
+ """校验解析后端、服务器地址、解析强度归在同一个配置块内。"""
+ gradio_text = Path("mineru/cli_old/gradio_app.py").read_text(encoding="utf-8")
+
+ backend_block_idx = gradio_text.index('elem_classes=["mineru-backend-options-block"]')
+ backend_idx = gradio_text.index("backend = gr.Dropdown(")
+ client_options_idx = gradio_text.index('elem_classes=["mineru-client-options"]')
+ effort_idx = gradio_text.index("effort = gr.Dropdown(")
+ max_pages_idx = gradio_text.index("max_pages = gr.Slider(")
+ advanced_popover_idx = gradio_text.index('elem_classes=["mineru-advanced-popover"]')
+
+ assert "effort = gr.Radio(" not in gradio_text
+ assert "解析强度越高,解析质量越好但速度越慢;解析强度越低,速度更快但质量可能下降。" in gradio_text
+ assert "Low 使用本地 Hybrid 处理;Medium 速度更快;High 精度更高,耗时可能更长。" not in gradio_text
+ assert backend_block_idx < backend_idx < client_options_idx < effort_idx < max_pages_idx < advanced_popover_idx
+
+
def test_parse_forwards_flash_backend(monkeypatch: Any, tmp_path: Path) -> None:
source = tmp_path / "demo.pdf"
output = tmp_path / "out.md"
diff --git a/tests/unittest/test_parser_api_contract.py b/tests/unittest/test_parser_api_contract.py
index 9080a573..6082752d 100644
--- a/tests/unittest/test_parser_api_contract.py
+++ b/tests/unittest/test_parser_api_contract.py
@@ -1309,7 +1309,7 @@ def test_api_server_cli_effort_help_matches_gradio_copy() -> None:
effort_option = next(param for param in main.params if "--effort" in param.opts)
assert effort_option.help == (
- "Low uses local Hybrid processing. Medium is faster. High is more accurate and may take longer."
+ "Higher effort improves parsing quality but may be slower; lower effort is faster but may reduce quality."
)