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
chore: speed up "mineru --help"
zjx205b26a38726fe
diff --git a/mineru/cli/client.py b/mineru/cli/client.pyindex 99121916..58c1f7a2 100644--- a/mineru/cli/client.py+++ b/mineru/cli/client.py@@ -7,7 +7,6 @@ from loguru import loggerfrom mineru.utils.config_reader import get_devicefrom mineru.utils.model_utils import get_vramfrom ..version import __version__-from .common import do_parse, read_fn, pdf_suffixes, image_suffixes@click.command()@@ -139,6 +138,8 @@ from .common import do_parse, read_fn, pdf_suffixes, image_suffixesdef main(input_path, output_dir, method, backend, lang, server_url, start_page_id, end_page_id, formula_enable, table_enable, device_mode, virtual_vram, model_source):+ from .common import do_parse, read_fn, pdf_suffixes, image_suffixes+def get_device_mode() -> str:if device_mode is not None:return device_modediff --git a/mineru/utils/config_reader.py b/mineru/utils/config_reader.pyindex c31ed8fb..f608044e 100644--- a/mineru/utils/config_reader.py+++ b/mineru/utils/config_reader.py@@ -2,7 +2,6 @@import jsonimport os-import torchfrom loguru import logger# 定义配置文件名常量@@ -72,6 +71,8 @@ def get_device():if device_mode is not None:return device_modeelse:+ import torch+if torch.cuda.is_available():return "cuda"elif torch.backends.mps.is_available():diff --git a/mineru/utils/model_utils.py b/mineru/utils/model_utils.pyindex ec724ffd..1755bdfe 100644--- a/mineru/utils/model_utils.py+++ b/mineru/utils/model_utils.py@@ -1,5 +1,4 @@import time-import torchimport gcfrom PIL import Imagefrom loguru import logger@@ -298,6 +297,8 @@ def get_res_list_from_layout_res(layout_res, iou_threshold=0.7, overlap_thresholdef clean_memory(device='cuda'):+ import torch+if device == 'cuda':if torch.cuda.is_available():torch.cuda.empty_cache()@@ -321,6 +322,8 @@ def clean_vram(device, vram_threshold=8):def get_vram(device):+ import torch+if torch.cuda.is_available() and str(device).startswith("cuda"):total_memory = torch.cuda.get_device_properties(device).total_memory / (1024 ** 3) # 将字节转换为 GBreturn total_memory