Skip to content

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

refactor: add local models directory handling and update config version

myhlolia149a49cdec1
diff --git a/magic-pdf.template.json b/magic-pdf.template.json
index f61e7d12..9b9971db 100644
--- a/magic-pdf.template.json
+++ b/magic-pdf.template.json
@@ -21,5 +21,9 @@
"enable": false
}
},
- "config_version": "1.2.2"
+ "models-dir": {
+ "pipeline": "",
+ "vlm": ""
+ },
+ "config_version": "1.3.0"
}
\ No newline at end of file
diff --git a/mineru/utils/config_reader.py b/mineru/utils/config_reader.py
index b78acbaa..f80d92b9 100644
--- a/mineru/utils/config_reader.py
+++ b/mineru/utils/config_reader.py
@@ -114,4 +114,12 @@ def get_llm_aided_config():
logger.warning(f"'llm-aided-config' not found in {CONFIG_FILE_NAME}, use 'None' as default")
return None
else:
- return llm_aided_config
\ No newline at end of file
+ return llm_aided_config
+
+
+def get_local_models_dir():
+ config = read_config()
+ models_dir = config.get('models-dir')
+ if models_dir is None:
+ logger.warning(f"'models-dir' not found in {CONFIG_FILE_NAME}, use None as default")
+ return models_dir
\ No newline at end of file
diff --git a/mineru/utils/models_download_utils.py b/mineru/utils/models_download_utils.py
index b222a4f5..af0c9a1c 100644
--- a/mineru/utils/models_download_utils.py
+++ b/mineru/utils/models_download_utils.py
@@ -2,6 +2,7 @@ import os
from huggingface_hub import snapshot_download as hf_snapshot_download
from modelscope import snapshot_download as ms_snapshot_download
+from mineru.utils.config_reader import get_local_models_dir
from mineru.utils.enum_class import ModelPath
def get_file_from_repos(relative_path: str, repo_mode='pipeline') -> str:
@@ -15,6 +16,13 @@ def get_file_from_repos(relative_path: str, repo_mode='pipeline') -> str:
"""
model_source = os.getenv('MINERU_MODEL_SOURCE', None)
+ if model_source == 'local':
+ local_models_config = get_local_models_dir()
+ root_path = local_models_config.get(repo_mode, None)
+ if not root_path:
+ raise ValueError(f"Local path for repo_mode '{repo_mode}' is not configured.")
+ return os.path.join(root_path, relative_path.strip('/'))
+
# 建立仓库模式到路径的映射
repo_mapping = {
'pipeline': {