Skip to content

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

feat: add image analysis option to various API endpoints and processing functions

myhlolic272f160e0ef
diff --git a/mineru/backend/hybrid/hybrid_analyze.py b/mineru/backend/hybrid/hybrid_analyze.py
index a4f54c12..f7612a27 100644
--- a/mineru/backend/hybrid/hybrid_analyze.py
+++ b/mineru/backend/hybrid/hybrid_analyze.py
@@ -551,6 +551,7 @@ def doc_analyze(
inline_formula_enable: bool = True,
model_path: str | None = None,
server_url: str | None = None,
+ image_analysis: bool = True,
**kwargs,
):
if predictor is None:
@@ -604,12 +605,16 @@ def doc_analyze(
)
if _vlm_ocr_enable:
with predictor_execution_guard(predictor):
- window_model_list = predictor.batch_two_step_extract(images=images_pil_list)
+ window_model_list = predictor.batch_two_step_extract(
+ images=images_pil_list,
+ image_analysis=image_analysis,
+ )
else:
with predictor_execution_guard(predictor):
window_model_list = predictor.batch_two_step_extract(
images=images_pil_list,
- not_extract_list=not_extract_list
+ not_extract_list=not_extract_list,
+ image_analysis=image_analysis,
)
window_model_list, hybrid_pipeline_model = _process_ocr_and_formulas(
images_pil_list,
@@ -679,6 +684,7 @@ async def aio_doc_analyze(
inline_formula_enable: bool = True,
model_path: str | None = None,
server_url: str | None = None,
+ image_analysis: bool = True,
**kwargs,
):
if predictor is None:
@@ -731,12 +737,16 @@ async def aio_doc_analyze(
)
if _vlm_ocr_enable:
async with aio_predictor_execution_guard(predictor):
- window_model_list = await predictor.aio_batch_two_step_extract(images=images_pil_list)
+ window_model_list = await predictor.aio_batch_two_step_extract(
+ images=images_pil_list,
+ image_analysis=image_analysis,
+ )
else:
async with aio_predictor_execution_guard(predictor):
window_model_list = await predictor.aio_batch_two_step_extract(
images=images_pil_list,
- not_extract_list=not_extract_list
+ not_extract_list=not_extract_list,
+ image_analysis=image_analysis,
)
window_model_list, hybrid_pipeline_model = _process_ocr_and_formulas(
images_pil_list,
diff --git a/mineru/backend/vlm/vlm_analyze.py b/mineru/backend/vlm/vlm_analyze.py
index ef484329..6b18cd03 100644
--- a/mineru/backend/vlm/vlm_analyze.py
+++ b/mineru/backend/vlm/vlm_analyze.py
@@ -427,6 +427,7 @@ def doc_analyze(
backend="transformers",
model_path: str | None = None,
server_url: str | None = None,
+ image_analysis: bool = True,
**kwargs,
):
if predictor is None:
@@ -472,7 +473,10 @@ def doc_analyze(
f'({len(images_pil_list)} pages)'
)
with predictor_execution_guard(predictor):
- window_results = predictor.batch_two_step_extract(images=images_pil_list)
+ window_results = predictor.batch_two_step_extract(
+ images=images_pil_list,
+ image_analysis=image_analysis,
+ )
results.extend(window_results)
if progress_bar is None:
progress_bar = tqdm(total=page_count, desc="Processing pages")
@@ -519,6 +523,7 @@ async def aio_doc_analyze(
backend="transformers",
model_path: str | None = None,
server_url: str | None = None,
+ image_analysis: bool = True,
**kwargs,
):
if predictor is None:
@@ -563,7 +568,10 @@ async def aio_doc_analyze(
f'({len(images_pil_list)} pages)'
)
async with aio_predictor_execution_guard(predictor):
- window_results = await predictor.aio_batch_two_step_extract(images=images_pil_list)
+ window_results = await predictor.aio_batch_two_step_extract(
+ images=images_pil_list,
+ image_analysis=image_analysis,
+ )
results.extend(window_results)
if progress_bar is None:
progress_bar = tqdm(total=page_count, desc="Processing pages")
diff --git a/mineru/cli/api_client.py b/mineru/cli/api_client.py
index ad81cd46..4f3be448 100644
--- a/mineru/cli/api_client.py
+++ b/mineru/cli/api_client.py
@@ -811,6 +811,7 @@ def build_parse_request_form_data(
start_page_id: int,
end_page_id: Optional[int],
*,
+ image_analysis: bool = True,
return_md: bool,
return_middle_json: bool,
return_model_output: bool,
@@ -826,6 +827,7 @@ def build_parse_request_form_data(
"parse_method": parse_method,
"formula_enable": str(formula_enable).lower(),
"table_enable": str(table_enable).lower(),
+ "image_analysis": str(image_analysis).lower(),
"return_md": str(return_md).lower(),
"return_middle_json": str(return_middle_json).lower(),
"return_model_output": str(return_model_output).lower(),
diff --git a/mineru/cli/client.py b/mineru/cli/client.py
index bc7a5815..42d13a3e 100644
--- a/mineru/cli/client.py
+++ b/mineru/cli/client.py
@@ -622,6 +622,7 @@ def build_request_form_data(
server_url: Optional[str],
start_page_id: int,
end_page_id: Optional[int],
+ image_analysis: bool = True,
) -> dict[str, str | list[str]]:
return _api_client.build_parse_request_form_data(
lang_list=[lang],
@@ -629,6 +630,7 @@ def build_request_form_data(
parse_method=method,
formula_enable=formula_enable,
table_enable=table_enable,
+ image_analysis=image_analysis,
server_url=server_url,
start_page_id=start_page_id,
end_page_id=end_page_id,
@@ -843,6 +845,7 @@ async def run_orchestrated_cli(
end_page_id: Optional[int],
formula_enable: bool,
table_enable: bool,
+ image_analysis: bool = True,
extra_cli_args: tuple[str, ...] = (),
) -> None:
if start_page_id < 0:
@@ -909,6 +912,7 @@ async def run_orchestrated_cli(
method=method,
formula_enable=formula_enable,
table_enable=table_enable,
+ image_analysis=image_analysis,
server_url=server_url,
start_page_id=start_page_id,
end_page_id=end_page_id,
@@ -1088,6 +1092,13 @@ async def run_orchestrated_cli(
default=True,
help="Enable table parsing. Default is True. ",
)
+ "--image-analysis",
+ "image_analysis",
+ type=bool,
+ default=True,
+ help="Enable image/chart analysis for VLM and hybrid backends. Default is True. ",
+)
def main(
ctx: click.Context,
input_path: Path,
@@ -1101,6 +1112,7 @@ def main(
end_page_id: Optional[int],
formula_enable: bool,
table_enable: bool,
+ image_analysis: bool,
) -> None:
asyncio.run(
run_orchestrated_cli(
@@ -1115,6 +1127,7 @@ def main(
end_page_id=end_page_id,
formula_enable=formula_enable,
table_enable=table_enable,
+ image_analysis=image_analysis,
extra_cli_args=tuple(ctx.args),
)
)
diff --git a/mineru/cli/common.py b/mineru/cli/common.py
index 96d559fa..ba4b87fc 100644
--- a/mineru/cli/common.py
+++ b/mineru/cli/common.py
@@ -636,6 +636,7 @@ def do_parse(
f_make_md_mode=MakeMode.MM_MD,
start_page_id=0,
end_page_id=None,
+ image_analysis=True,
**kwargs,
):
need_remove_index = _process_office_doc(
@@ -684,7 +685,7 @@ def do_parse(
output_dir, pdf_file_names, pdf_bytes_list, backend,
f_draw_layout_bbox, f_draw_span_bbox, f_dump_md, f_dump_middle_json,
f_dump_model_output, f_dump_orig_pdf, f_dump_content_list, f_make_md_mode,
- server_url, **kwargs,
+ server_url, image_analysis=image_analysis, **kwargs,
)
elif backend.startswith("hybrid-"):
ensure_backend_dependencies(backend)
@@ -704,7 +705,7 @@ def do_parse(
output_dir, pdf_file_names, pdf_bytes_list, p_lang_list, parse_method, formula_enable, backend,
f_draw_layout_bbox, f_draw_span_bbox, f_dump_md, f_dump_middle_json,
f_dump_model_output, f_dump_orig_pdf, f_dump_content_list, f_make_md_mode,
- server_url, **kwargs,
+ server_url, image_analysis=image_analysis, **kwargs,
)
@@ -728,6 +729,7 @@ async def aio_do_parse(
f_make_md_mode=MakeMode.MM_MD,
start_page_id=0,
end_page_id=None,
+ image_analysis=True,
**kwargs,
):
need_remove_index = _process_office_doc(
@@ -777,7 +779,7 @@ async def aio_do_parse(
output_dir, pdf_file_names, pdf_bytes_list, backend,
f_draw_layout_bbox, f_draw_span_bbox, f_dump_md, f_dump_middle_json,
f_dump_model_output, f_dump_orig_pdf, f_dump_content_list, f_make_md_mode,
- server_url, **kwargs,
+ server_url, image_analysis=image_analysis, **kwargs,
)
elif backend.startswith("hybrid-"):
ensure_backend_dependencies(backend)
@@ -796,7 +798,7 @@ async def aio_do_parse(
output_dir, pdf_file_names, pdf_bytes_list, p_lang_list, parse_method, formula_enable, backend,
f_draw_layout_bbox, f_draw_span_bbox, f_dump_md, f_dump_middle_json,
f_dump_model_output, f_dump_orig_pdf, f_dump_content_list, f_make_md_mode,
- server_url, **kwargs,
+ server_url, image_analysis=image_analysis, **kwargs,
)
diff --git a/mineru/cli/fast_api.py b/mineru/cli/fast_api.py
index c54f9d80..8a0692c5 100644
--- a/mineru/cli/fast_api.py
+++ b/mineru/cli/fast_api.py
@@ -146,6 +146,7 @@ class ParseRequestOptions:
parse_method: str
formula_enable: bool
table_enable: bool
+ image_analysis: bool
server_url: Optional[str]
return_md: bool
return_middle_json: bool
@@ -177,6 +178,7 @@ class AsyncParseTask:
lang_list: list[str]
formula_enable: bool
table_enable: bool
+ image_analysis: bool
server_url: Optional[str]
return_md: bool
return_middle_json: bool
@@ -842,6 +844,10 @@ async def parse_request_form(
bool,
Form(description="Enable table parsing."),
] = True,
+ image_analysis: Annotated[
+ bool,
+ Form(description="Enable image/chart analysis for VLM and hybrid backends."),
+ ] = True,
server_url: Annotated[
Optional[str],
Form(
@@ -908,6 +914,7 @@ async def parse_request_form(
parse_method=validate_parse_method(parse_method),
formula_enable=formula_enable,
table_enable=table_enable,
+ image_analysis=image_analysis,
server_url=server_url,
return_md=return_md,
return_middle_json=return_middle_json,
@@ -1015,6 +1022,7 @@ async def run_parse_job(
parse_method=request_options.parse_method,
formula_enable=request_options.formula_enable,
table_enable=request_options.table_enable,
+ image_analysis=request_options.image_analysis,
server_url=request_options.server_url,
f_draw_layout_bbox=False,
f_draw_span_bbox=False,
@@ -1067,6 +1075,7 @@ async def create_async_parse_task(
lang_list=request_options.lang_list,
formula_enable=request_options.formula_enable,
table_enable=request_options.table_enable,
+ image_analysis=request_options.image_analysis,
server_url=request_options.server_url,
return_md=request_options.return_md,
return_middle_json=request_options.return_middle_json,
diff --git a/mineru/cli/gradio_app.py b/mineru/cli/gradio_app.py
index 6724157c..1a5f660b 100644
--- a/mineru/cli/gradio_app.py
+++ b/mineru/cli/gradio_app.py
@@ -501,6 +501,11 @@ def resolve_parse_method(file_path, is_ocr, backend):
return "ocr" if is_ocr else "auto"
+def is_image_analysis_option_visible(backend):
+ """判断 Gradio 图片分析开关是否应展示;pipeline 后端不消费该参数。"""
+ return backend.startswith("vlm") or backend.startswith("hybrid")
+
+
def create_gradio_run_paths(file_path, output_root="./output"):
run_id = f"{time.strftime('%y%m%d_%H%M%S')}_{uuid.uuid4().hex[:8]}_{safe_stem(Path(file_path).stem)}"
run_root = Path(output_root) / "gradio" / run_id
@@ -614,6 +619,7 @@ async def _run_to_markdown_job(
is_ocr=False,
formula_enable=True,
table_enable=True,
+ image_analysis=True,
language="ch",
backend="pipeline",
url=None,
@@ -640,6 +646,7 @@ async def _run_to_markdown_job(
parse_method=parse_method,
formula_enable=formula_enable,
table_enable=table_enable,
+ image_analysis=image_analysis,
server_url=url,
start_page_id=0,
end_page_id=end_pages - 1,
@@ -753,6 +760,7 @@ async def stream_to_markdown(
is_ocr=False,
formula_enable=True,
table_enable=True,
+ image_analysis=True,
language="ch",
backend="pipeline",
url=None,
@@ -781,6 +789,7 @@ async def stream_to_markdown(
is_ocr=is_ocr,
formula_enable=formula_enable,
table_enable=table_enable,
+ image_analysis=image_analysis,
language=language,
backend=backend,
url=url,
@@ -1094,6 +1103,8 @@ def main(ctx,
"recognition_options": "**Recognition Options:**",
"table_enable": "Enable table recognition",
"table_info": "If disabled, tables will be shown as images.",
+ "image_analysis_enable": "Enable image analysis",
+ "image_analysis_info": "If disabled, image/chart blocks will keep layout positions but skip VLM image/chart analysis.",
"formula_label_vlm": "Enable display formula recognition",
"formula_label_pipeline": "Enable formula recognition",
"formula_label_hybrid": "Enable inline formula recognition",
@@ -1126,6 +1137,8 @@ def main(ctx,
"recognition_options": "**识别选项:**",
"table_enable": "启用表格识别",
"table_info": "禁用后,表格将显示为图片。",
+ "image_analysis_enable": "启用图片分析",
+ "image_analysis_info": "禁用后,图片/图表块仍保留版面位置,但跳过 VLM 图片/图表分析。",
"formula_label_vlm": "启用行间公式识别",
"formula_label_pipeline": "启用公式识别",
"formula_label_hybrid": "启用行内公式识别",
@@ -1186,6 +1199,7 @@ def main(ctx,
def update_interface(backend_choice):
formula_label_update = gr.update(label=get_formula_label(backend_choice), info=get_formula_info(backend_choice))
backend_info_update = gr.update(info=get_backend_info(backend_choice))
+ image_analysis_update = gr.update(visible=is_image_analysis_option_visible(backend_choice))
if "http-client" in backend_choice:
client_options_update = gr.update(visible=True)
else:
@@ -1195,7 +1209,7 @@ def main(ctx,
else:
ocr_options_update = gr.update(visible=True)
- return client_options_update, ocr_options_update, formula_label_update, backend_info_update
+ return client_options_update, ocr_options_update, formula_label_update, backend_info_update, image_analysis_update
del kwargs
@@ -1223,6 +1237,7 @@ def main(ctx,
is_ocr=False,
formula_enable=True,
table_enable=True,
+ image_analysis=True,
language="ch",
backend="pipeline",
url=None,
@@ -1233,6 +1248,7 @@ def main(ctx,
is_ocr=is_ocr,
formula_enable=formula_enable,
table_enable=table_enable,
+ image_analysis=image_analysis,
language=language,
backend=backend,
url=url,
@@ -1264,6 +1280,12 @@ def main(ctx,
gr.Markdown(i18n("recognition_options"))
table_enable = gr.Checkbox(label=i18n("table_enable"), value=True, info=i18n("table_info"))
formula_enable = gr.Checkbox(label=get_formula_label(preferred_option), value=True, info=get_formula_info(preferred_option))
+ image_analysis = gr.Checkbox(
+ label=i18n("image_analysis_enable"),
+ value=True,
+ visible=is_image_analysis_option_visible(preferred_option),
+ info=i18n("image_analysis_info"),
+ )
with gr.Column() as ocr_options:
language = gr.Dropdown(all_lang, label=i18n("ocr_language"), value='ch (Chinese, English, Chinese Traditional)', info=i18n("ocr_language_info"))
is_ocr = gr.Checkbox(label=i18n("force_ocr"), value=False, info=i18n("force_ocr_info"))
@@ -1321,14 +1343,14 @@ def main(ctx,
backend.change(
fn=update_interface,
inputs=[backend],
- outputs=[client_options, ocr_options, formula_enable, backend],
+ outputs=[client_options, ocr_options, formula_enable, backend, image_analysis],
**_private_api_kwargs
)
# 添加demo.load事件,在页面加载时触发一次界面更新
demo.load(
fn=update_interface,
inputs=[backend],
- outputs=[client_options, ocr_options, formula_enable, backend],
+ outputs=[client_options, ocr_options, formula_enable, backend, image_analysis],
**_private_api_kwargs
)
status_box.change(
@@ -1382,7 +1404,7 @@ def main(ctx,
)
change_bu.click(
fn=convert_to_markdown_stream,
- inputs=[input_file, max_pages, is_ocr, formula_enable, table_enable, language, backend, url],
+ inputs=[input_file, max_pages, is_ocr, formula_enable, table_enable, image_analysis, language, backend, url],
outputs=[status_box, output_file, md, md_text, doc_show],
**_to_md_api_kwargs
)