Skip to content

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

feat: implement autoscroll functionality for status box in gradio_app

myhloli12aebcfe17e4
diff --git a/mineru/cli/gradio_app.py b/mineru/cli/gradio_app.py
index 6444d6f8..cc3f9d6f 100644
--- a/mineru/cli/gradio_app.py
+++ b/mineru/cli/gradio_app.py
@@ -188,14 +188,25 @@ class GradioRequestConcurrencyLimiter:
_gradio_request_concurrency_limiter = GradioRequestConcurrencyLimiter()
-STATUS_BOX_ELEM_ID = "convert-status-box"
-STATUS_BOX_CSS = f"""
-#{STATUS_BOX_ELEM_ID} textarea {{
- min-height: 7.5rem !important;
- height: 7.5rem !important;
- max-height: 7.5rem !important;
-}}
+STATUS_BOX_AUTOSCROLL_JS = """
+(value) => {
+ const scrollToBottom = () => {
+ const textarea = document.querySelector(".convert-status-box textarea");
+ if (!textarea) {
+ return;
+ }
+ textarea.scrollTop = textarea.scrollHeight;
+ };
+
+ requestAnimationFrame(() => {
+ scrollToBottom();
+ requestAnimationFrame(scrollToBottom);
+ });
+
+ return [];
+}
"""
+
STATUS_TIMER_INTERVAL_SECONDS = 0.1
STATUS_QUEUE_ANIMATION_INTERVAL_SECONDS = 1.0
STATUS_QUEUE_ANIMATION_MAX_DOTS = 10
@@ -1177,7 +1188,7 @@ def main(ctx,
# suffixes = [f".{suffix}" for suffix in pdf_suffixes + image_suffixes + office_suffixes]
suffixes = [f".{suffix}" for suffix in pdf_suffixes + image_suffixes + docx_suffixes]
- with gr.Blocks(css=STATUS_BOX_CSS) as demo:
+ with gr.Blocks() as demo:
gr.HTML(header)
with gr.Row():
with gr.Column(variant='panel', scale=5):
@@ -1226,7 +1237,8 @@ def main(ctx,
lines=4,
max_lines=4,
interactive=False,
- elem_id=STATUS_BOX_ELEM_ID,
+ autoscroll=True,
+ elem_classes=["convert-status-box"],
)
output_file = gr.File(label=i18n("convert_result"), interactive=False)
with gr.Blocks():
@@ -1266,6 +1278,13 @@ def main(ctx,
outputs=[client_options, ocr_options, formula_enable, backend],
**_private_api_kwargs
)
+ status_box.change(
+ fn=None,
+ inputs=[status_box],
+ outputs=[],
+ js=STATUS_BOX_AUTOSCROLL_JS,
+ **_private_api_kwargs
+ )
clear_bu.add([input_file, md, doc_show, md_text, output_file, is_ocr, office_html, status_box])
# 清除按钮额外重置 UI 可见性(ClearButton 不一定触发 input_file.change)