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: add effort parameter to API for hybrid backend processing control
myhlolibff0a7b1d550
diff --git a/mineru/cli_old/gradio_app.py b/mineru/cli_old/gradio_app.pyindex 3bb146c8..3589faf6 100644--- a/mineru/cli_old/gradio_app.py+++ b/mineru/cli_old/gradio_app.py@@ -47,6 +47,7 @@ from mineru.utils.backend_options import (DEFAULT_HYBRID_EFFORT,HTTP_CLIENT_BACKEND_CHOICES,HYBRID_EFFORT_CHOICES,+ HYBRID_EFFORT_HELP,LOCAL_BACKEND_CHOICES,)@@ -1615,7 +1616,7 @@ def main(ctx,"image_analysis_enable": "Enable image analysis","image_analysis_info": "If disabled, image/chart blocks will keep layout positions but skip VLM image/chart analysis.","effort": "Hybrid effort",- "effort_info": "Medium is faster. High is more accurate and may take longer.",+ "effort_info": HYBRID_EFFORT_HELP,"formula_label_vlm": "Enable display formula recognition","formula_label_pipeline": "Enable formula recognition","formula_label_hybrid": "Enable inline formula recognition",diff --git a/mineru/parser/api_server.py b/mineru/parser/api_server.pyindex 500eac6b..3eee5e5f 100644--- a/mineru/parser/api_server.py+++ b/mineru/parser/api_server.py@@ -31,6 +31,7 @@ from fastapi.responses import JSONResponse, StreamingResponsefrom pydantic import BaseModel, ConfigDict, Fieldfrom ..types import Tier+from ..utils.backend_options import HYBRID_EFFORT_HELP, validate_effortfrom .tier import PARSER_BACKENDS, resolve_tier_and_backend_API_SERVER_BACKENDS = tuple(backend for backend in PARSER_BACKENDS if backend != "flash")@@ -1194,6 +1195,7 @@ async def _run_job(table_enable: bool,formula_enable: bool,image_analysis: bool,+ effort: str = "medium",url_timeout: int = 60,) -> None:rec.status = "running"@@ -1226,6 +1228,7 @@ async def _run_job(backend=server_backend,language=language,ocr_mode=ocr_mode,+ effort=effort,disable_table=not table_enable,disable_formula=not formula_enable,disable_image_analysis=not image_analysis,@@ -1694,6 +1697,7 @@ async def create_job(url_timeout_val: int = request.app.state.url_timeoutlanguage_val: str = request.app.state.languageocr_mode_val: str = request.app.state.ocr_mode+ effort_val: str = request.app.state.efforttable_enable_val: bool = request.app.state.table_enableformula_enable_val: bool = request.app.state.formula_enableimage_analysis_val: bool = request.app.state.image_analysis@@ -1708,6 +1712,7 @@ async def create_job(server_backend=backend,language=language_val,ocr_mode=ocr_mode_val,+ effort=effort_val,table_enable=table_enable_val,formula_enable=formula_enable_val,image_analysis=image_analysis_val,@@ -1738,6 +1743,7 @@ async def create_job(server_backend=backend,language=language_val,ocr_mode=ocr_mode_val,+ effort=effort_val,table_enable=table_enable_val,formula_enable=formula_enable_val,image_analysis=image_analysis_val,@@ -1958,6 +1964,7 @@ def create_app(api_key: str | None = None,language: str = "ch",ocr_mode: str = "auto",+ effort: str = "medium",table_enable: bool = True,formula_enable: bool = True,image_analysis: bool = True,@@ -1988,6 +1995,9 @@ def create_app(Parser language hint.ocr_mode:PDF OCR/text extraction mode for pipeline and hybrid backends.+ effort:+ Hybrid backend effort level. Medium is faster. High is more accurate+ and may take longer.table_enable:Whether table recognition is enabled.formula_enable:@@ -1997,6 +2007,7 @@ def create_app("""upload_dir = upload_dir or ""tier, backend = _resolve_server_tier_and_backend(tier=tier, backend=backend)+ effort = validate_effort(effort)_api_key: str | None = api_key or None_upload_dir = pathlib.Path(upload_dir) if upload_dir else pathlib.Path(tempfile.mkdtemp(prefix="mineru_"))_upload_dir.mkdir(parents=True, exist_ok=True)@@ -2016,6 +2027,7 @@ def create_app(application.state.api_key = _api_keyapplication.state.language = languageapplication.state.ocr_mode = ocr_mode+ application.state.effort = effortapplication.state.table_enable = table_enableapplication.state.formula_enable = formula_enableapplication.state.image_analysis = image_analysis@@ -2044,6 +2056,7 @@ def create_app(application.state.api_key = _api_keyapplication.state.language = languageapplication.state.ocr_mode = ocr_mode+ application.state.effort = effortapplication.state.table_enable = table_enableapplication.state.formula_enable = formula_enableapplication.state.image_analysis = image_analysis@@ -2095,7 +2108,7 @@ def create_app("--backend",default=None,type=click.Choice(_API_SERVER_BACKENDS),- help="Advanced parser backend. Defaults from --tier: standard -> pipeline, pro -> hybrid-auto-engine.",+ help="Advanced parser backend. Defaults from --tier: standard -> pipeline, pro -> hybrid-engine.",)@click.option("--tier",@@ -2133,6 +2146,12 @@ def create_app(type=click.Choice(_OCR_MODES),help="PDF OCR/text extraction mode. Applies to pipeline and hybrid-* backends.",)+ "--effort",+ default="medium",+ type=click.Choice(("medium", "high")),+ help=HYBRID_EFFORT_HELP,+)@click.option("--disable-table", is_flag=True, help="Disable table recognition.")@click.option("--disable-formula", is_flag=True, help="Disable formula recognition.")@click.option("--disable-image-analysis", is_flag=True, help="Disable image analysis for VLM/hybrid backends.")@@ -2153,6 +2172,7 @@ def main(max_wait: int,language: str,ocr_mode: str,+ effort: str,disable_table: bool,disable_formula: bool,disable_image_analysis: bool,@@ -2172,6 +2192,7 @@ def main(api_key=api_key,language=language,ocr_mode=ocr_mode,+ effort=effort,table_enable=not disable_table,formula_enable=not disable_formula,image_analysis=not disable_image_analysis,diff --git a/mineru/utils/backend_options.py b/mineru/utils/backend_options.pyindex 3e80a959..b9b8e5e0 100644--- a/mineru/utils/backend_options.py+++ b/mineru/utils/backend_options.py@@ -8,6 +8,7 @@ CANONICAL_HYBRID_ENGINE: Final = "hybrid-engine"DEFAULT_BACKEND: Final = CANONICAL_HYBRID_ENGINEDEFAULT_HYBRID_EFFORT: Final = "medium"DEFAULT_EFFORT: Final = DEFAULT_HYBRID_EFFORT+HYBRID_EFFORT_HELP: Final = "Medium is faster. High is more accurate and may take longer."LOCAL_BACKEND_CHOICES: Final[tuple[str, ...]] = ("pipeline",@@ -18,6 +19,7 @@ HTTP_CLIENT_BACKEND_CHOICES: Final[tuple[str, ...]] = ("vlm-http-client","hybrid-http-client",)+PUBLIC_BACKEND_CHOICES: Final[tuple[str, ...]] = LOCAL_BACKEND_CHOICES + HTTP_CLIENT_BACKEND_CHOICESHYBRID_EFFORT_CHOICES: Final[tuple[str, ...]] = ("medium", "high")BACKEND_ALIASES: Final[dict[str, str]] = {@@ -25,7 +27,7 @@ BACKEND_ALIASES: Final[dict[str, str]] = {"hybrid-auto-engine": CANONICAL_HYBRID_ENGINE,}-SUPPORTED_BACKENDS: Final[tuple[str, ...]] = LOCAL_BACKEND_CHOICES + HTTP_CLIENT_BACKEND_CHOICES + ("flash",)+SUPPORTED_BACKENDS: Final[tuple[str, ...]] = PUBLIC_BACKEND_CHOICES + ("flash",)SUPPORTED_EFFORTS: Final[tuple[str, ...]] = HYBRID_EFFORT_CHOICES@@ -40,6 +42,16 @@ def normalize_backend(backend: str | None) -> str:raise ValueError(f"Unsupported backend '{backend}'. Supported backends: {', '.join(SUPPORTED_BACKENDS)}")+def normalize_public_backend(backend: str | None) -> str:+ """规范化公开 CLI/API backend 名称,但不暴露 parser 内部 flash 后端。"""+ normalized = (backend or "").strip()+ if normalized in BACKEND_ALIASES:+ return BACKEND_ALIASES[normalized]+ if normalized in PUBLIC_BACKEND_CHOICES:+ return normalized+ raise ValueError(f"Unsupported backend '{backend}'. Supported backends: {', '.join(PUBLIC_BACKEND_CHOICES)}")++def validate_effort(effort: str | None) -> str:"""校验 Hybrid effort 级别,入口层统一使用 medium 作为默认值。"""normalized = (effort or DEFAULT_EFFORT).strip().lower()diff --git a/tests/unittest/test_parser_api_contract.py b/tests/unittest/test_parser_api_contract.pyindex b7d2db8b..adc4a13b 100644--- a/tests/unittest/test_parser_api_contract.py+++ b/tests/unittest/test_parser_api_contract.py@@ -647,3 +647,10 @@ def test_api_server_cli_exposes_parser_runtime_options() -> None:assert "--disable-table" in option_namesassert "--disable-formula" in option_namesassert "--disable-image-analysis" in option_names+++def test_api_server_cli_effort_help_matches_gradio_copy() -> None:+ """校验 api server 的 effort 帮助文案与 Gradio 英文提示保持一致。"""+ effort_option = next(param for param in main.params if "--effort" in param.opts)++ assert effort_option.help == "Medium is faster. High is more accurate and may take longer."