Skip to content

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

feat: refactor demo script for async API integration and enhance input file handling

myhloli0e1ea31d391e
diff --git a/demo/demo.py b/demo/demo.py
index f6f1c5ad..8a4235a9 100644
--- a/demo/demo.py
+++ b/demo/demo.py
@@ -1,394 +1,256 @@
# Copyright (c) Opendatalab. All rights reserved.
-import copy
-import json
+import asyncio
import os
-from concurrent.futures import ThreadPoolExecutor
+import tempfile
from pathlib import Path
-from loguru import logger
-
-from mineru.cli.common import convert_pdf_bytes_to_bytes, prepare_env, read_fn, pptx_suffixes, \
- xlsx_suffixes, pdf_suffixes, image_suffixes, office_suffixes, docx_suffixes
-from mineru.data.data_reader_writer import FileBasedDataWriter
-from mineru.utils.draw_bbox import draw_layout_bbox, draw_span_bbox
-from mineru.utils.engine_utils import get_vlm_engine
-from mineru.utils.enum_class import MakeMode
-from mineru.backend.vlm.vlm_analyze import doc_analyze as vlm_doc_analyze
-from mineru.backend.pipeline.pipeline_analyze import doc_analyze_streaming as pipeline_doc_analyze_streaming
-from mineru.backend.pipeline.pipeline_middle_json_mkcontent import union_make as pipeline_union_make
-from mineru.backend.vlm.vlm_middle_json_mkcontent import union_make as vlm_union_make
-from mineru.backend.hybrid.hybrid_analyze import doc_analyze as hybrid_doc_analyze
-from mineru.backend.office.office_middle_json_mkcontent import union_make as office_union_make
-from mineru.backend.office.docx_analyze import office_docx_analyze
-from mineru.utils.guess_suffix_or_lang import guess_suffix_by_path, guess_suffix_by_bytes
-
-
-def do_parse(
- output_dir, # Output directory for storing parsing results
- pdf_file_names: list[str], # List of PDF file names to be parsed
- pdf_bytes_list: list[bytes], # List of PDF bytes to be parsed
- p_lang_list: list[str], # List of languages for each PDF, default is 'ch' (Chinese)
- backend="hybrid-auto-engine", # The backend for parsing PDF, default is 'hybrid-auto-engine'
- parse_method="auto", # The method for parsing PDF, default is 'auto'
- formula_enable=True, # Enable formula parsing
- table_enable=True, # Enable table parsing
- server_url=None, # Server URL for vlm-http-client backend
- f_draw_layout_bbox=True, # Whether to draw layout bounding boxes
- f_draw_span_bbox=True, # Whether to draw span bounding boxes
- f_dump_md=True, # Whether to dump markdown files
- f_dump_middle_json=True, # Whether to dump middle JSON files
- f_dump_model_output=True, # Whether to dump model output files
- f_dump_orig_pdf=True, # Whether to dump original PDF files
- f_dump_content_list=True, # Whether to dump content list files
- f_make_md_mode=MakeMode.MM_MD, # The mode for making markdown content, default is MM_MD
- start_page_id=0, # Start page ID for parsing, default is 0
- end_page_id=None, # End page ID for parsing, default is None (parse all pages until the end of the document)
-):
- need_remove_index = _process_office_doc(
- output_dir,
- pdf_file_names=pdf_file_names,
- pdf_bytes_list=pdf_bytes_list,
- f_dump_md=f_dump_md,
- f_dump_middle_json=f_dump_middle_json,
- f_dump_model_output=f_dump_model_output,
- f_dump_orig_file=f_dump_orig_pdf,
- f_dump_content_list=f_dump_content_list,
- f_make_md_mode=f_make_md_mode,
- )
- for index in sorted(need_remove_index, reverse=True):
- del pdf_bytes_list[index]
- del pdf_file_names[index]
- del p_lang_list[index]
- if not pdf_bytes_list:
- logger.warning("No valid PDF or image files to process.")
- return
+import httpx
- if backend == "pipeline":
- for idx, pdf_bytes in enumerate(pdf_bytes_list):
- new_pdf_bytes = convert_pdf_bytes_to_bytes(pdf_bytes, start_page_id, end_page_id)
- pdf_bytes_list[idx] = new_pdf_bytes
-
- image_writer_list = []
- md_writer_list = []
- local_output_info = []
- for idx, pdf_bytes in enumerate(pdf_bytes_list):
- pdf_file_name = pdf_file_names[idx]
- local_image_dir, local_md_dir = prepare_env(output_dir, pdf_file_name, parse_method)
- image_writer, md_writer = FileBasedDataWriter(local_image_dir), FileBasedDataWriter(local_md_dir)
- image_writer_list.append(image_writer)
- md_writer_list.append(md_writer)
- local_output_info.append((pdf_file_name, local_image_dir, local_md_dir))
-
- output_futures = []
-
- def run_output_task(doc_index, middle_json, model_list):
- pdf_file_name, local_image_dir, local_md_dir = local_output_info[doc_index]
- md_writer = md_writer_list[doc_index]
- pdf_bytes = pdf_bytes_list[doc_index]
- logger.info(f"Pipeline output start: doc{doc_index}")
- try:
- _process_output(
- middle_json["pdf_info"], pdf_bytes, pdf_file_name, local_md_dir, local_image_dir,
- md_writer, f_draw_layout_bbox, f_draw_span_bbox, f_dump_orig_pdf,
- f_dump_md, f_dump_content_list, f_dump_middle_json, f_dump_model_output,
- f_make_md_mode, middle_json, model_list, process_mode="pipeline"
- )
- logger.info(f"Pipeline output complete: doc{doc_index}")
- except Exception:
- logger.exception(f"Pipeline output failed: doc{doc_index}")
- raise
-
- with ThreadPoolExecutor(max_workers=1) as output_executor:
- def on_doc_ready(doc_index, model_list, middle_json, ocr_enable):
- logger.info(
- f"Pipeline doc ready: doc{doc_index} pages={len(middle_json['pdf_info'])} output_submitted=1"
- )
- future = output_executor.submit(run_output_task, doc_index, middle_json, model_list)
- output_futures.append(future)
-
- pipeline_doc_analyze_streaming(
- pdf_bytes_list,
- image_writer_list,
- p_lang_list,
- on_doc_ready,
- parse_method=parse_method,
- formula_enable=formula_enable,
- table_enable=table_enable,
- )
+from mineru.cli import api_client as _api_client
+from mineru.cli.common import image_suffixes, office_suffixes, pdf_suffixes
+from mineru.utils.guess_suffix_or_lang import guess_suffix_by_path
- for future in output_futures:
- future.result()
- return
- else:
- f_draw_span_bbox = False
-
- if backend.startswith("vlm-"):
- backend = backend[4:]
-
- if backend == "auto-engine":
- backend = get_vlm_engine(inference_engine='auto', is_async=False)
-
- parse_method = "vlm"
- for idx, pdf_bytes in enumerate(pdf_bytes_list):
- pdf_file_name = pdf_file_names[idx]
- pdf_bytes = convert_pdf_bytes_to_bytes(pdf_bytes, start_page_id, end_page_id)
- local_image_dir, local_md_dir = prepare_env(output_dir, pdf_file_name, parse_method)
- image_writer, md_writer = FileBasedDataWriter(local_image_dir), FileBasedDataWriter(local_md_dir)
- middle_json, infer_result = vlm_doc_analyze(
- pdf_bytes, image_writer=image_writer, backend=backend, server_url=server_url
- )
+SUPPORTED_INPUT_SUFFIXES = set(pdf_suffixes + image_suffixes + office_suffixes)
- pdf_info = middle_json["pdf_info"]
- _process_output(
- pdf_info, pdf_bytes, pdf_file_name, local_md_dir, local_image_dir,
- md_writer, f_draw_layout_bbox, f_draw_span_bbox, f_dump_orig_pdf,
- f_dump_md, f_dump_content_list, f_dump_middle_json, f_dump_model_output,
- f_make_md_mode, middle_json, infer_result, process_mode="vlm"
- )
- elif backend.startswith("hybrid-"):
- backend = backend[7:]
-
- if backend == "auto-engine":
- backend = get_vlm_engine(inference_engine='auto', is_async=False)
-
- parse_method = f"hybrid_{parse_method}"
- for idx, pdf_bytes in enumerate(pdf_bytes_list):
- pdf_file_name = pdf_file_names[idx]
- pdf_bytes = convert_pdf_bytes_to_bytes(pdf_bytes, start_page_id, end_page_id)
- local_image_dir, local_md_dir = prepare_env(output_dir, pdf_file_name, parse_method)
- image_writer, md_writer = FileBasedDataWriter(local_image_dir), FileBasedDataWriter(local_md_dir)
- middle_json, infer_result, _vlm_ocr_enable = hybrid_doc_analyze(
- pdf_bytes,
- image_writer=image_writer,
- backend=backend,
- parse_method=parse_method,
- language=p_lang_list[idx],
- inline_formula_enable=formula_enable,
- server_url=server_url,
- )
+def collect_input_files(input_path: str | Path) -> list[Path]:
+ path = Path(input_path).expanduser().resolve()
+ if not path.exists():
+ raise FileNotFoundError(f"Input path does not exist: {path}")
- pdf_info = middle_json["pdf_info"]
-
- _process_output(
- pdf_info, pdf_bytes, pdf_file_name, local_md_dir, local_image_dir,
- md_writer, f_draw_layout_bbox, f_draw_span_bbox, f_dump_orig_pdf,
- f_dump_md, f_dump_content_list, f_dump_middle_json, f_dump_model_output,
- f_make_md_mode, middle_json, infer_result, process_mode="vlm"
- )
+ if path.is_file():
+ file_suffix = guess_suffix_by_path(path)
+ if file_suffix not in SUPPORTED_INPUT_SUFFIXES:
+ raise ValueError(f"Unsupported input file type: {path.name}")
+ return [path]
+ if not path.is_dir():
+ raise ValueError(f"Input path must be a file or directory: {path}")
-def _process_office_doc(
- output_dir,
- pdf_file_names: list[str],
- pdf_bytes_list: list[bytes],
- f_dump_md=True,
- f_dump_middle_json=True,
- f_dump_model_output=True,
- f_dump_orig_file=True,
- f_dump_content_list=True,
- f_make_md_mode=MakeMode.MM_MD,
-):
- need_remove_index = []
- for i, file_bytes in enumerate(pdf_bytes_list):
- pdf_file_name = pdf_file_names[i]
- file_suffix = guess_suffix_by_bytes(file_bytes)
- if file_suffix in docx_suffixes:
-
- need_remove_index.append(i)
-
- local_image_dir, local_md_dir = prepare_env(output_dir, pdf_file_name, f"office")
- image_writer, md_writer = FileBasedDataWriter(local_image_dir), FileBasedDataWriter(local_md_dir)
- middle_json, infer_result = office_docx_analyze(
- file_bytes,
- image_writer=image_writer,
- )
+ input_files = sorted(
+ (
+ candidate.resolve()
+ for candidate in path.iterdir()
+ if candidate.is_file()
+ and guess_suffix_by_path(candidate) in SUPPORTED_INPUT_SUFFIXES
+ ),
+ key=lambda item: item.name,
+ )
+ if not input_files:
+ raise ValueError(f"No supported files found in directory: {path}")
+ return input_files
+
+
+def build_form_data(
+ language: str,
+ backend: str,
+ parse_method: str,
+ formula_enable: bool,
+ table_enable: bool,
+ server_url: str | None,
+ start_page_id: int,
+ end_page_id: int | None,
+) -> dict[str, str | list[str]]:
+ return _api_client.build_parse_request_form_data(
+ lang_list=[language],
+ backend=backend,
+ parse_method=parse_method,
+ formula_enable=formula_enable,
+ table_enable=table_enable,
+ server_url=server_url,
+ start_page_id=start_page_id,
+ end_page_id=end_page_id,
+ return_md=True,
+ return_middle_json=False,
+ return_model_output=False,
+ return_content_list=False,
+ return_images=True,
+ response_format_zip=True,
+ return_original_file=False,
+ )
- f_draw_layout_bbox = False
- f_draw_span_bbox = False
- pdf_info = middle_json["pdf_info"]
- _process_output(
- pdf_info, file_bytes, pdf_file_name, local_md_dir, local_image_dir,
- md_writer, f_draw_layout_bbox, f_draw_span_bbox, f_dump_orig_file,
- f_dump_md, f_dump_content_list, f_dump_middle_json, f_dump_model_output,
- f_make_md_mode, middle_json, infer_result, process_mode="docx"
- )
- elif file_suffix in pptx_suffixes:
- need_remove_index.append(i)
- logger.warning(f"Currently, PPTX files are not supported: {pdf_file_name}")
- elif file_suffix in xlsx_suffixes:
- need_remove_index.append(i)
- logger.warning(f"Currently, XLSX files are not supported: {pdf_file_name}")
-
- return need_remove_index
-
-
-def _process_output(
- pdf_info,
- pdf_bytes,
- pdf_file_name,
- local_md_dir,
- local_image_dir,
- md_writer,
- f_draw_layout_bbox,
- f_draw_span_bbox,
- f_dump_orig_pdf,
- f_dump_md,
- f_dump_content_list,
- f_dump_middle_json,
- f_dump_model_output,
- f_make_md_mode,
- middle_json,
- model_output=None,
- process_mode="vlm"
-):
-
- if process_mode == "pipeline":
- make_func = pipeline_union_make
- elif process_mode == "vlm":
- make_func = vlm_union_make
- elif process_mode in office_suffixes:
- make_func = office_union_make
- else:
- raise Exception(f"Unknown process_mode: {process_mode}")
-
- """处理输出文件"""
- if f_draw_layout_bbox:
- draw_layout_bbox(pdf_info, pdf_bytes, local_md_dir, f"{pdf_file_name}_layout.pdf")
-
- if f_draw_span_bbox:
- draw_span_bbox(pdf_info, pdf_bytes, local_md_dir, f"{pdf_file_name}_span.pdf")
-
- if f_dump_orig_pdf:
- if process_mode in ["pipeline", "vlm"]:
- md_writer.write(
- f"{pdf_file_name}_origin.pdf",
- pdf_bytes,
- )
- elif process_mode in office_suffixes:
- md_writer.write(
- f"{pdf_file_name}_origin.{process_mode}",
- pdf_bytes,
- )
+def format_status_message(status_snapshot: _api_client.TaskStatusSnapshot) -> str:
+ if status_snapshot.queued_ahead is None:
+ return status_snapshot.status
+ return f"{status_snapshot.status} (queued_ahead={status_snapshot.queued_ahead})"
- image_dir = str(os.path.basename(local_image_dir))
- if f_dump_md:
- md_content_str = make_func(pdf_info, f_make_md_mode, image_dir)
- md_writer.write_string(
- f"{pdf_file_name}.md",
- md_content_str,
- )
+def prepare_local_api_temp_dir() -> None:
+ current_temp_dir = Path(tempfile.gettempdir())
+ if os.name == "nt" or not Path("/tmp").exists():
+ return
+ if not str(current_temp_dir).startswith("/mnt/"):
+ return
- if f_dump_content_list:
- content_list = make_func(pdf_info, MakeMode.CONTENT_LIST, image_dir)
- md_writer.write_string(
- f"{pdf_file_name}_content_list.json",
- json.dumps(content_list, ensure_ascii=False, indent=4),
- )
+ # vLLM/ZeroMQ IPC sockets fail on drvfs-backed temp directories under WSL.
+ os.environ["TMPDIR"] = "/tmp"
+ tempfile.tempdir = None
+
+
+async def run_demo(
+ input_path: str | Path,
+ output_dir: str | Path,
+ *,
+ api_url: str | None = None,
+ backend: str = "hybrid-auto-engine",
+ parse_method: str = "auto",
+ language: str = "ch",
+ formula_enable: bool = True,
+ table_enable: bool = True,
+ server_url: str | None = None,
+ start_page_id: int = 0,
+ end_page_id: int | None = None,
+) -> None:
+ api_url = api_url or None
+ server_url = server_url or None
+ if backend.endswith("http-client") and not server_url:
+ raise ValueError(f"backend={backend} requires server_url")
+
+ input_files = collect_input_files(input_path)
+ output_path = Path(output_dir).expanduser().resolve()
+ output_path.mkdir(parents=True, exist_ok=True)
+
+ form_data = build_form_data(
+ language=language,
+ backend=backend,
+ parse_method=parse_method,
+ formula_enable=formula_enable,
+ table_enable=table_enable,
+ server_url=server_url,
+ start_page_id=start_page_id,
+ end_page_id=end_page_id,
+ )
+ upload_assets = [
+ _api_client.UploadAsset(path=file_path, upload_name=file_path.name)
+ for file_path in input_files
+ ]
+
+ local_server: _api_client.LocalAPIServer | None = None
+ result_zip_path: Path | None = None
+ task_label = f"{len(input_files)} file(s)"
+
+ async with httpx.AsyncClient(
+ timeout=_api_client.build_http_timeout(),
+ follow_redirects=True,
+ ) as http_client:
+ try:
+ if api_url is None:
+ prepare_local_api_temp_dir()
+ local_server = _api_client.LocalAPIServer()
+ base_url = local_server.start()
+ print(f"Started local mineru-api: {base_url}")
+ server_health = await _api_client.wait_for_local_api_ready(
+ http_client,
+ local_server,
+ )
+ else:
+ server_health = await _api_client.fetch_server_health(
+ http_client,
+ _api_client.normalize_base_url(api_url),
+ )
- if process_mode != "pipeline":
- content_list_v2 = make_func(pdf_info, MakeMode.CONTENT_LIST_V2, image_dir)
- md_writer.write_string(
- f"{pdf_file_name}_content_list_v2.json",
- json.dumps(content_list_v2, ensure_ascii=False, indent=4),
- )
+ print(f"Using API: {server_health.base_url}")
+ print(f"Submitting {len(upload_assets)} file(s)")
+ submit_response = await _api_client.submit_parse_task(
+ base_url=server_health.base_url,
+ upload_assets=upload_assets,
+ form_data=form_data,
+ )
+ print(f"task_id: {submit_response.task_id}")
+ if submit_response.queued_ahead is not None:
+ print(f"status: pending (queued_ahead={submit_response.queued_ahead})")
+
+ last_status_message = None
+
+ def on_status_update(status_snapshot: _api_client.TaskStatusSnapshot) -> None:
+ nonlocal last_status_message
+ message = format_status_message(status_snapshot)
+ if message == last_status_message:
+ return
+ last_status_message = message
+ print(f"status: {message}")
+
+ await _api_client.wait_for_task_result(
+ client=http_client,
+ submit_response=submit_response,
+ task_label=task_label,
+ status_snapshot_callback=on_status_update,
+ )
+ print("status: completed")
+ result_zip_path = await _api_client.download_result_zip(
+ client=http_client,
+ submit_response=submit_response,
+ task_label=task_label,
+ )
+ finally:
+ if local_server is not None:
+ local_server.stop()
- if f_dump_middle_json:
- md_writer.write_string(
- f"{pdf_file_name}_middle.json",
- json.dumps(middle_json, ensure_ascii=False, indent=4),
- )
+ assert result_zip_path is not None
+ try:
+ _api_client.safe_extract_zip(result_zip_path, output_path)
+ finally:
+ result_zip_path.unlink(missing_ok=True)
+ print(f"Extracted result to: {output_path}")
+
+
+def main() -> None:
+ demo_dir = Path(__file__).resolve().parent
+
+ # Input can be a single supported file or a directory containing supported files.
+ input_path = demo_dir / "pdfs"
+ # Parsed outputs will be extracted into this directory.
+ output_dir = demo_dir / "api_output"
+ # Set this to an existing MinerU FastAPI base URL, for example:
+ # "http://127.0.0.1:8000"
+ # Leave it as None to start a temporary local mineru-api automatically.
+ api_url = None
+
+ # Available examples:
+ # "hybrid-auto-engine" -> local hybrid parsing, recommended default
+ # "pipeline" -> more general OCR/text pipeline
+ # "vlm-auto-engine" -> local VLM parsing
+ # "vlm-http-client" -> remote OpenAI-compatible VLM server
+ # "hybrid-http-client" -> remote OpenAI-compatible hybrid server
+ backend = "hybrid-auto-engine"
+ # Available options:
+ # "auto" -> let MinerU choose between text extraction and OCR
+ # "txt" -> force text extraction
+ # "ocr" -> force OCR
+ parse_method = "auto"
+ # OCR language hint. This is mainly used by pipeline and hybrid backends.
+ language = "ch"
+ # Enable formula parsing in the output.
+ formula_enable = True
+ # Enable table parsing in the output.
+ table_enable = True
+ # Required only for "*-http-client" backends, for example:
+ # "http://127.0.0.1:30000"
+ server_url = None
+ # Zero-based page range. Set end_page_id to None to parse to the last page.
+ start_page_id = 0
+ end_page_id = None
- if f_dump_model_output:
- md_writer.write_string(
- f"{pdf_file_name}_model.json",
- json.dumps(model_output, ensure_ascii=False, indent=4),
- )
+ """如果您由于网络问题无法下载模型,可以设置环境变量MINERU_MODEL_SOURCE为modelscope使用免代理仓库下载模型"""
+ # os.environ['MINERU_MODEL_SOURCE'] = "modelscope"
- logger.info(f"local output dir is {local_md_dir}")
-
-
-def parse_doc(
- path_list: list[Path],
- output_dir,
- lang="ch",
- backend="hybrid-auto-engine",
- method="auto",
- server_url=None,
- start_page_id=0,
- end_page_id=None
-):
- """
- Parameter description:
- path_list: List of document paths to be parsed, can be PDF or image files.
- output_dir: Output directory for storing parsing results.
- lang: Language option, default is 'ch', optional values include['ch', 'ch_server', 'ch_lite', 'en', 'korean', 'japan', 'chinese_cht', 'ta', 'te', 'ka', 'th', 'el',
- 'latin', 'arabic', 'east_slavic', 'cyrillic', 'devanagari']。
- Input the languages in the pdf (if known) to improve OCR accuracy. Optional.
- Adapted only for the case where the backend is set to 'pipeline' and 'hybrid-*'
- backend: the backend for parsing pdf:
- pipeline: More general.
- vlm-auto-engine: High accuracy via local computing power.
- vlm-http-client: High accuracy via remote computing power(client suitable for openai-compatible servers).
- hybrid-auto-engine: Next-generation high accuracy solution via local computing power.
- hybrid-http-client: High accuracy but requires a little local computing power(client suitable for openai-compatible servers).
- Without method specified, hybrid-auto-engine will be used by default.
- method: the method for parsing pdf:
- auto: Automatically determine the method based on the file type.
- txt: Use text extraction method.
- ocr: Use OCR method for image-based PDFs.
- Without method specified, 'auto' will be used by default.
- Adapted only for the case where the backend is set to 'pipeline' and 'hybrid-*'.
- server_url: When the backend is `http-client`, you need to specify the server_url, for example:`http://127.0.0.1:30000`
- start_page_id: Start page ID for parsing, default is 0
- end_page_id: End page ID for parsing, default is None (parse all pages until the end of the document)
- """
- try:
- file_name_list = []
- pdf_bytes_list = []
- lang_list = []
- for path in path_list:
- file_name = str(Path(path).stem)
- pdf_bytes = read_fn(path)
- file_name_list.append(file_name)
- pdf_bytes_list.append(pdf_bytes)
- lang_list.append(lang)
- do_parse(
+ asyncio.run(
+ run_demo(
+ input_path=input_path,
output_dir=output_dir,
- pdf_file_names=file_name_list,
- pdf_bytes_list=pdf_bytes_list,
- p_lang_list=lang_list,
+ api_url=api_url,
backend=backend,
- parse_method=method,
+ parse_method=parse_method,
+ language=language,
+ formula_enable=formula_enable,
+ table_enable=table_enable,
server_url=server_url,
start_page_id=start_page_id,
- end_page_id=end_page_id
+ end_page_id=end_page_id,
)
- except Exception as e:
- logger.exception(e)
-
-
-if __name__ == '__main__':
- # args
- __dir__ = os.path.dirname(os.path.abspath(__file__))
- pdf_files_dir = os.path.join(__dir__, "docx")
- output_dir = os.path.join(__dir__, "output")
-
- doc_path_list = []
- for doc_path in Path(pdf_files_dir).glob('*'):
- if guess_suffix_by_path(doc_path) in pdf_suffixes + image_suffixes + office_suffixes:
- doc_path_list.append(doc_path)
-
- """如果您由于网络问题无法下载模型,可以设置环境变量MINERU_MODEL_SOURCE为modelscope使用免代理仓库下载模型"""
- # os.environ['MINERU_MODEL_SOURCE'] = "modelscope"
+ )
- """Use hybrid mode and local computing power to parse documents"""
- parse_doc(doc_path_list, output_dir, backend="hybrid-auto-engine")
- """Other backends for parsing documents, you can uncomment and try"""
- # parse_doc(doc_path_list, output_dir, backend="pipeline") # more general.
- # parse_doc(doc_path_list, output_dir, backend="vlm-auto-engine") # high accuracy via local computing power.
- # parse_doc(doc_path_list, output_dir, backend="vlm-http-client", server_url="http://127.0.0.1:30000") # high accuracy via remote computing power(client suitable for openai-compatible servers).
- # parse_doc(doc_path_list, output_dir, backend="hybrid-http-client", server_url="http://127.0.0.1:30000") # high accuracy but requires a little local computing power(client suitable for openai-compatible servers).
+if __name__ == "__main__":
+ main()
diff --git a/pyproject.toml b/pyproject.toml
index cadbe958..9b4a564a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -49,6 +49,9 @@ dependencies = [
"lxml>=4.0.0,<7.0.0",
"pandas>=2.3.3,<3",
"openpyxl>=3.1.5,<4",
+ "fastapi",
+ "python-multipart",
+ "uvicorn",
]
[project.optional-dependencies]
@@ -85,11 +88,6 @@ pipeline = [
"transformers>=4.57.3,<5.0.0",
"onnxruntime>1.17.0",
]
-api = [
- "fastapi",
- "python-multipart",
- "uvicorn",
-]
gradio = [
"gradio>=5.49.1,!=6.0.0,!=6.0.1,!=6.0.2,!=6.1.0,!=6.2.0,!=6.3.0,!=6.4.0,!=6.5.0,!=6.5.1,!=6.6.0,!=6.7.0,<6.9.0",
"gradio-pdf>=0.0.22",
@@ -97,7 +95,6 @@ gradio = [
core = [
"mineru[vlm]",
"mineru[pipeline]",
- "mineru[api]",
"mineru[gradio]",
]
all = [