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
5b6d27d6
Commit
5b6d27d6
authored
Jul 01, 2025
by
myhloli
Browse files
feat: add api_enable switch for gradio app
parent
0679fd85
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
22 deletions
+40
-22
mineru/cli/gradio_app.py
mineru/cli/gradio_app.py
+40
-22
No files found.
mineru/cli/gradio_app.py
View file @
5b6d27d6
...
@@ -175,6 +175,19 @@ def to_pdf(file_path):
...
@@ -175,6 +175,19 @@ def to_pdf(file_path):
return
tmp_file_path
return
tmp_file_path
# 更新界面函数
def
update_interface
(
backend_choice
):
if
backend_choice
in
[
"vlm-transformers"
,
"vlm-sglang-engine"
]:
return
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
False
)
elif
backend_choice
in
[
"vlm-sglang-client"
]:
# pipeline
return
gr
.
update
(
visible
=
True
),
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
False
)
elif
backend_choice
in
[
"pipeline"
]:
return
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
True
),
gr
.
update
(
visible
=
True
)
else
:
pass
@
click
.
command
()
@
click
.
command
()
@
click
.
option
(
@
click
.
option
(
'--enable-example'
,
'--enable-example'
,
...
@@ -200,12 +213,19 @@ def to_pdf(file_path):
...
@@ -200,12 +213,19 @@ def to_pdf(file_path):
)
)
@
click
.
option
(
@
click
.
option
(
'--enable-torch-compile'
,
'--enable-torch-compile'
,
'
enable_
torch_compile'
,
'torch_compile
_enable
'
,
type
=
bool
,
type
=
bool
,
help
=
"Enable torch compile for SgLang engine. "
,
help
=
"Enable torch compile for SgLang engine. "
,
default
=
True
,
default
=
True
,
)
)
def
main
(
example_enable
,
sglang_engine_enable
,
mem_fraction_static
,
enable_torch_compile
):
@
click
.
option
(
'--enable-api'
,
'api_enable'
,
type
=
bool
,
help
=
"Enable gradio API for serving the application."
,
default
=
True
,
)
def
main
(
example_enable
,
sglang_engine_enable
,
mem_fraction_static
,
torch_compile_enable
,
api_enable
):
if
sglang_engine_enable
:
if
sglang_engine_enable
:
try
:
try
:
print
(
"Start init SgLang engine..."
)
print
(
"Start init SgLang engine..."
)
...
@@ -216,7 +236,7 @@ def main(example_enable, sglang_engine_enable, mem_fraction_static, enable_torch
...
@@ -216,7 +236,7 @@ def main(example_enable, sglang_engine_enable, mem_fraction_static, enable_torch
None
,
None
,
None
,
None
,
mem_fraction_static
=
mem_fraction_static
,
mem_fraction_static
=
mem_fraction_static
,
enable_torch_compile
=
enable_
torch_compile
,
enable_torch_compile
=
torch_compile
_enable
,
)
)
print
(
"SgLang engine init successfully."
)
print
(
"SgLang engine init successfully."
)
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -271,37 +291,35 @@ def main(example_enable, sglang_engine_enable, mem_fraction_static, enable_torch
...
@@ -271,37 +291,35 @@ def main(example_enable, sglang_engine_enable, mem_fraction_static, enable_torch
with
gr
.
Tab
(
'Markdown text'
):
with
gr
.
Tab
(
'Markdown text'
):
md_text
=
gr
.
TextArea
(
lines
=
45
,
show_copy_button
=
True
)
md_text
=
gr
.
TextArea
(
lines
=
45
,
show_copy_button
=
True
)
# 更新界面函数
def
update_interface
(
backend_choice
):
if
backend_choice
in
[
"vlm-transformers"
,
"vlm-sglang-engine"
]:
return
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
False
)
elif
backend_choice
in
[
"vlm-sglang-client"
]:
# pipeline
return
gr
.
update
(
visible
=
True
),
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
False
)
elif
backend_choice
in
[
"pipeline"
]:
return
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
True
),
gr
.
update
(
visible
=
True
)
else
:
pass
# 添加事件处理
# 添加事件处理
backend
.
change
(
backend
.
change
(
fn
=
update_interface
,
fn
=
update_interface
,
inputs
=
[
backend
],
inputs
=
[
backend
],
outputs
=
[
client_options
,
ocr_options
,
pipeline_options
]
outputs
=
[
client_options
,
ocr_options
,
pipeline_options
],
api_name
=
False
)
)
# 添加demo.load事件,在页面加载时触发一次界面更新
# 添加demo.load事件,在页面加载时触发一次界面更新
demo
.
load
(
demo
.
load
(
fn
=
update_interface
,
fn
=
update_interface
,
inputs
=
[
backend
],
inputs
=
[
backend
],
outputs
=
[
client_options
,
ocr_options
,
pipeline_options
]
outputs
=
[
client_options
,
ocr_options
,
pipeline_options
],
api_name
=
False
)
)
input_file
.
change
(
fn
=
to_pdf
,
inputs
=
input_file
,
outputs
=
pdf_show
)
change_bu
.
click
(
fn
=
to_markdown
,
inputs
=
[
input_file
,
max_pages
,
is_ocr
,
formula_enable
,
table_enable
,
language
,
backend
,
url
],
outputs
=
[
md
,
md_text
,
output_file
,
pdf_show
])
clear_bu
.
add
([
input_file
,
md
,
pdf_show
,
md_text
,
output_file
,
is_ocr
])
clear_bu
.
add
([
input_file
,
md
,
pdf_show
,
md_text
,
output_file
,
is_ocr
])
if
api_enable
:
api_name
=
None
else
:
api_name
=
False
input_file
.
change
(
fn
=
to_pdf
,
inputs
=
input_file
,
outputs
=
pdf_show
,
api_name
=
api_name
)
change_bu
.
click
(
fn
=
to_markdown
,
inputs
=
[
input_file
,
max_pages
,
is_ocr
,
formula_enable
,
table_enable
,
language
,
backend
,
url
],
outputs
=
[
md
,
md_text
,
output_file
,
pdf_show
],
api_name
=
api_name
)
demo
.
launch
()
demo
.
launch
()
...
...
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