Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
MinerU
Commits
f407079b
Commit
f407079b
authored
Jun 06, 2025
by
myhloli
Browse files
refactor: improve configuration handling and enhance environment variable support
parent
2688e3f7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
53 deletions
+22
-53
magic-pdf.template.json
magic-pdf.template.json
+1
-30
mineru/backend/pipeline/config_reader.py
mineru/backend/pipeline/config_reader.py
+21
-23
No files found.
magic-pdf.template.json
View file @
f407079b
...
@@ -3,23 +3,6 @@
...
@@ -3,23 +3,6 @@
"bucket-name-1"
:[
"ak"
,
"sk"
,
"endpoint"
],
"bucket-name-1"
:[
"ak"
,
"sk"
,
"endpoint"
],
"bucket-name-2"
:[
"ak"
,
"sk"
,
"endpoint"
]
"bucket-name-2"
:[
"ak"
,
"sk"
,
"endpoint"
]
},
},
"models-dir"
:
"/tmp/models"
,
"layoutreader-model-dir"
:
"/tmp/layoutreader"
,
"device-mode"
:
"cpu"
,
"layout-config"
:
{
"model"
:
"doclayout_yolo"
},
"formula-config"
:
{
"mfd_model"
:
"yolo_v8_mfd"
,
"mfr_model"
:
"unimernet_small"
,
"enable"
:
true
},
"table-config"
:
{
"model"
:
"rapid_table"
,
"sub_model"
:
"slanet_plus"
,
"enable"
:
true
,
"max_time"
:
400
},
"latex-delimiter-config"
:
{
"latex-delimiter-config"
:
{
"display"
:
{
"display"
:
{
"left"
:
"$$"
,
"left"
:
"$$"
,
...
@@ -31,18 +14,6 @@
...
@@ -31,18 +14,6 @@
}
}
},
},
"llm-aided-config"
:
{
"llm-aided-config"
:
{
"formula_aided"
:
{
"api_key"
:
"your_api_key"
,
"base_url"
:
"https://dashscope.aliyuncs.com/compatible-mode/v1"
,
"model"
:
"qwen2.5-7b-instruct"
,
"enable"
:
false
},
"text_aided"
:
{
"api_key"
:
"your_api_key"
,
"base_url"
:
"https://dashscope.aliyuncs.com/compatible-mode/v1"
,
"model"
:
"qwen2.5-7b-instruct"
,
"enable"
:
false
},
"title_aided"
:
{
"title_aided"
:
{
"api_key"
:
"your_api_key"
,
"api_key"
:
"your_api_key"
,
"base_url"
:
"https://dashscope.aliyuncs.com/compatible-mode/v1"
,
"base_url"
:
"https://dashscope.aliyuncs.com/compatible-mode/v1"
,
...
@@ -50,5 +21,5 @@
...
@@ -50,5 +21,5 @@
"enable"
:
false
"enable"
:
false
}
}
},
},
"config_version"
:
"1.2.
1
"
"config_version"
:
"1.2.
2
"
}
}
\ No newline at end of file
mineru/backend/pipeline/config_reader.py
View file @
f407079b
...
@@ -16,8 +16,9 @@ def read_config():
...
@@ -16,8 +16,9 @@ def read_config():
config_file
=
os
.
path
.
join
(
home_dir
,
CONFIG_FILE_NAME
)
config_file
=
os
.
path
.
join
(
home_dir
,
CONFIG_FILE_NAME
)
if
not
os
.
path
.
exists
(
config_file
):
if
not
os
.
path
.
exists
(
config_file
):
raise
FileNotFoundError
(
f
'
{
config_file
}
not found'
)
logger
.
warning
(
f
'
{
config_file
}
not found, using default configuration'
)
return
None
else
:
with
open
(
config_file
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
with
open
(
config_file
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
config
=
json
.
load
(
f
)
config
=
json
.
load
(
f
)
return
config
return
config
...
@@ -88,33 +89,30 @@ def get_local_layoutreader_model_dir():
...
@@ -88,33 +89,30 @@ def get_local_layoutreader_model_dir():
def
get_device
():
def
get_device
():
config
=
read_config
()
device_mode
=
os
.
getenv
(
'MINERU_DEVICE_MODE'
,
None
)
device
=
config
.
get
(
'device-mode'
)
if
device_mode
is
not
None
:
if
device
is
None
:
return
device_mode
logger
.
warning
(
f
"'device-mode' not found in
{
CONFIG_FILE_NAME
}
, use 'cpu' as default"
)
return
'cpu'
else
:
else
:
return
device
logger
.
warning
(
f
"not found 'MINERU_DEVICE_MODE' in environment variable, use 'cpu' as default."
)
return
'cpu'
def
get_table_recog_config
():
def
get_table_recog_config
():
config
=
read_config
()
table_enable
=
os
.
getenv
(
'MINERU_TABLE_ENABLE'
,
None
)
table_config
=
config
.
get
(
'table-config'
)
if
table_enable
is
not
None
:
if
table_config
is
None
:
return
json
.
loads
(
f
'{{"enable":
{
table_enable
}
}}'
)
logger
.
warning
(
f
"'table-config' not found in
{
CONFIG_FILE_NAME
}
, use 'False' as default"
)
return
json
.
loads
(
f
'{{"enable": true}}'
)
else
:
else
:
return
table_config
logger
.
warning
(
f
"not found 'MINERU_TABLE_ENABLE' in environment variable, use 'true' as default."
)
return
json
.
loads
(
f
'{{"enable": true}}'
)
def
get_formula_config
():
def
get_formula_config
():
config
=
read_config
()
formula_enable
=
os
.
getenv
(
'MINERU_FORMULA_ENABLE'
,
None
)
formula_config
=
config
.
get
(
'formula-config'
)
if
formula_enable
is
not
None
:
if
formula_config
is
None
:
return
json
.
loads
(
f
'{{"enable":
{
formula_enable
}
}}'
)
logger
.
warning
(
f
"'formula-config' not found in
{
CONFIG_FILE_NAME
}
, use 'True' as default"
)
return
json
.
loads
(
f
'{{"enable": true}}'
)
else
:
else
:
return
formula_config
logger
.
warning
(
f
"not found 'MINERU_FORMULA_ENABLE' in environment variable, use 'true' as default."
)
return
json
.
loads
(
f
'{{"enable": true}}'
)
def
get_latex_delimiter_config
():
def
get_latex_delimiter_config
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment