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
54913fc2
Commit
54913fc2
authored
Jul 04, 2025
by
myhloli
Browse files
refactor: enhance command-line argument parsing to support additional parameters in gradio_app.py
parent
09eecea4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
27 deletions
+43
-27
mineru/cli/gradio_app.py
mineru/cli/gradio_app.py
+43
-27
No files found.
mineru/cli/gradio_app.py
View file @
54913fc2
...
@@ -188,7 +188,8 @@ def update_interface(backend_choice):
...
@@ -188,7 +188,8 @@ def update_interface(backend_choice):
pass
pass
@
click
.
command
()
@
click
.
command
(
context_settings
=
dict
(
ignore_unknown_options
=
True
,
allow_extra_args
=
True
))
@
click
.
pass_context
@
click
.
option
(
@
click
.
option
(
'--enable-example'
,
'--enable-example'
,
'example_enable'
,
'example_enable'
,
...
@@ -204,20 +205,6 @@ def update_interface(backend_choice):
...
@@ -204,20 +205,6 @@ def update_interface(backend_choice):
help
=
"Enable SgLang engine backend for faster processing."
,
help
=
"Enable SgLang engine backend for faster processing."
,
default
=
False
,
default
=
False
,
)
)
@
click
.
option
(
'--mem-fraction-static'
,
'mem_fraction_static'
,
type
=
float
,
help
=
"Set the static memory fraction for SgLang engine. "
,
default
=
None
,
)
@
click
.
option
(
'--enable-torch-compile'
,
'torch_compile_enable'
,
type
=
bool
,
help
=
"Enable torch compile for SgLang engine. "
,
default
=
False
,
)
@
click
.
option
(
@
click
.
option
(
'--enable-api'
,
'--enable-api'
,
'api_enable'
,
'api_enable'
,
...
@@ -246,28 +233,57 @@ def update_interface(backend_choice):
...
@@ -246,28 +233,57 @@ def update_interface(backend_choice):
help
=
"Set the server port for the Gradio app."
,
help
=
"Set the server port for the Gradio app."
,
default
=
None
,
default
=
None
,
)
)
def
main
(
def
main
(
ctx
,
example_enable
,
sglang_engine_enable
,
mem_fraction_static
,
torch_compile_enable
,
api_enable
,
max_convert_pages
,
example_enable
,
sglang_engine_enable
,
api_enable
,
max_convert_pages
,
server_name
,
server_port
server_name
,
server_port
,
**
kwargs
):
):
# 解析额外参数
extra_kwargs
=
{}
i
=
0
while
i
<
len
(
ctx
.
args
):
arg
=
ctx
.
args
[
i
]
if
arg
.
startswith
(
'--'
):
param_name
=
arg
[
2
:].
replace
(
'-'
,
'_'
)
# 转换参数名格式
i
+=
1
if
i
<
len
(
ctx
.
args
)
and
not
ctx
.
args
[
i
].
startswith
(
'--'
):
# 参数有值
try
:
# 尝试转换为适当的类型
if
ctx
.
args
[
i
].
lower
()
==
'true'
:
extra_kwargs
[
param_name
]
=
True
elif
ctx
.
args
[
i
].
lower
()
==
'false'
:
extra_kwargs
[
param_name
]
=
False
elif
'.'
in
ctx
.
args
[
i
]:
try
:
extra_kwargs
[
param_name
]
=
float
(
ctx
.
args
[
i
])
except
ValueError
:
extra_kwargs
[
param_name
]
=
ctx
.
args
[
i
]
else
:
try
:
extra_kwargs
[
param_name
]
=
int
(
ctx
.
args
[
i
])
except
ValueError
:
extra_kwargs
[
param_name
]
=
ctx
.
args
[
i
]
except
:
extra_kwargs
[
param_name
]
=
ctx
.
args
[
i
]
else
:
# 布尔型标志参数
extra_kwargs
[
param_name
]
=
True
i
-=
1
i
+=
1
# 将解析出的参数合并到kwargs
kwargs
.
update
(
extra_kwargs
)
if
sglang_engine_enable
:
if
sglang_engine_enable
:
try
:
try
:
print
(
"Start init SgLang engine..."
)
print
(
"Start init SgLang engine..."
)
from
mineru.backend.vlm.vlm_analyze
import
ModelSingleton
from
mineru.backend.vlm.vlm_analyze
import
ModelSingleton
model_singleton
=
ModelSingleton
()
model_singleton
=
ModelSingleton
()
model_params
=
{
"enable_torch_compile"
:
torch_compile_enable
}
# 只有当mem_fraction_static不为None时才添加该参数
if
mem_fraction_static
is
not
None
:
model_params
[
"mem_fraction_static"
]
=
mem_fraction_static
predictor
=
model_singleton
.
get_model
(
predictor
=
model_singleton
.
get_model
(
"sglang-engine"
,
"sglang-engine"
,
None
,
None
,
None
,
None
,
**
model_param
s
**
kwarg
s
)
)
print
(
"SgLang engine init successfully."
)
print
(
"SgLang engine init successfully."
)
except
Exception
as
e
:
except
Exception
as
e
:
...
...
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