Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -335,6 +335,7 @@ body, .gradio-container {
|
|
| 335 |
font-size: 1.1rem;
|
| 336 |
font-weight: 500;
|
| 337 |
}
|
|
|
|
| 338 |
.dark #subtitle p { color: #DAB2FF; }
|
| 339 |
|
| 340 |
/* Glassmorphism Cards */
|
|
@@ -358,51 +359,6 @@ body, .gradio-container {
|
|
| 358 |
border-color: rgba(168, 85, 247, 0.3) !important;
|
| 359 |
}
|
| 360 |
|
| 361 |
-
/* Custom Upload Area styling */
|
| 362 |
-
#custom-upload-zone {
|
| 363 |
-
border: 2px dashed #A855F7;
|
| 364 |
-
border-radius: 12px;
|
| 365 |
-
padding: 40px 20px;
|
| 366 |
-
text-align: center;
|
| 367 |
-
cursor: pointer;
|
| 368 |
-
background: rgba(168, 85, 247, 0.05);
|
| 369 |
-
transition: all 0.3s ease;
|
| 370 |
-
color: #A855F7;
|
| 371 |
-
}
|
| 372 |
-
|
| 373 |
-
#custom-upload-zone:hover {
|
| 374 |
-
background: rgba(168, 85, 247, 0.1);
|
| 375 |
-
border-color: #9333EA;
|
| 376 |
-
}
|
| 377 |
-
|
| 378 |
-
#custom-upload-zone h3 { margin: 0; font-weight: 600; color: #6B21A8; }
|
| 379 |
-
.dark #custom-upload-zone h3 { color: #DAB2FF; }
|
| 380 |
-
|
| 381 |
-
/* Global Drag Overlay */
|
| 382 |
-
#global-drag-overlay {
|
| 383 |
-
position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
|
| 384 |
-
background: rgba(168, 85, 247, 0.85);
|
| 385 |
-
z-index: 9999; display: flex; justify-content: center; align-items: center;
|
| 386 |
-
color: white; font-size: 3em; font-weight: bold; font-family: 'Outfit', sans-serif;
|
| 387 |
-
opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
|
| 388 |
-
backdrop-filter: blur(5px);
|
| 389 |
-
}
|
| 390 |
-
|
| 391 |
-
#global-drag-overlay.active {
|
| 392 |
-
opacity: 1; pointer-events: auto;
|
| 393 |
-
}
|
| 394 |
-
|
| 395 |
-
/* Hide Default Gradio File Upload */
|
| 396 |
-
.hidden-upload { display: none !important; }
|
| 397 |
-
|
| 398 |
-
/* Height Alignment & Stretching */
|
| 399 |
-
.stretch-col { display: flex !important; flex-direction: column !important; }
|
| 400 |
-
.stretch-group { flex-grow: 1 !important; display: flex !important; flex-direction: column !important; }
|
| 401 |
-
.stretch-group > .tabs { flex-grow: 1 !important; display: flex !important; flex-direction: column !important; }
|
| 402 |
-
.stretch-group .tabitem { flex-grow: 1 !important; display: flex !important; flex-direction: column !important; }
|
| 403 |
-
.stretch-group .log-box { flex-grow: 1 !important; }
|
| 404 |
-
.stretch-group .log-box textarea { height: 100% !important; min-height: 400px; }
|
| 405 |
-
|
| 406 |
/* Terminal Log Style */
|
| 407 |
.log-box textarea {
|
| 408 |
font-family: 'IBM Plex Mono', Consolas, monospace !important;
|
|
@@ -422,7 +378,9 @@ body, .gradio-container {
|
|
| 422 |
color: #6B21A8 !important;
|
| 423 |
}
|
| 424 |
|
| 425 |
-
.dark .status-text textarea {
|
|
|
|
|
|
|
| 426 |
|
| 427 |
/* Custom Scrollbars */
|
| 428 |
::-webkit-scrollbar { width: 8px; height: 8px; }
|
|
@@ -431,68 +389,14 @@ body, .gradio-container {
|
|
| 431 |
::-webkit-scrollbar-thumb:hover { background: linear-gradient(135deg, #9333EA, #A855F7); }
|
| 432 |
"""
|
| 433 |
|
| 434 |
-
# ==========================================
|
| 435 |
-
# --- π±οΈ JS for Global Drag & Drop Injection
|
| 436 |
-
# ==========================================
|
| 437 |
-
drag_drop_js = """
|
| 438 |
-
() => {
|
| 439 |
-
// 1. Create global overlay element
|
| 440 |
-
const overlay = document.createElement('div');
|
| 441 |
-
overlay.id = 'global-drag-overlay';
|
| 442 |
-
overlay.innerHTML = '<h2>π₯ Drop PDF Anywhere to Upload</h2>';
|
| 443 |
-
document.body.appendChild(overlay);
|
| 444 |
-
|
| 445 |
-
// Helper to find the hidden Gradio file input
|
| 446 |
-
const getFi = () => document.querySelector('#pdf-upload input[type="file"]');
|
| 447 |
-
|
| 448 |
-
// 2. Click anywhere in the custom zone to trigger file selector
|
| 449 |
-
setTimeout(() => {
|
| 450 |
-
const zone = document.getElementById('custom-upload-zone');
|
| 451 |
-
if(zone) {
|
| 452 |
-
zone.addEventListener('click', () => {
|
| 453 |
-
const fi = getFi();
|
| 454 |
-
if(fi) fi.click();
|
| 455 |
-
});
|
| 456 |
-
}
|
| 457 |
-
}, 500); // Small delay to ensure DOM is rendered
|
| 458 |
-
|
| 459 |
-
// 3. Global Drag & Drop events
|
| 460 |
-
let dragTimer;
|
| 461 |
-
document.body.addEventListener('dragover', (e) => {
|
| 462 |
-
e.preventDefault();
|
| 463 |
-
overlay.classList.add('active');
|
| 464 |
-
clearTimeout(dragTimer);
|
| 465 |
-
});
|
| 466 |
-
|
| 467 |
-
document.body.addEventListener('dragleave', (e) => {
|
| 468 |
-
e.preventDefault();
|
| 469 |
-
dragTimer = setTimeout(() => overlay.classList.remove('active'), 100);
|
| 470 |
-
});
|
| 471 |
-
|
| 472 |
-
document.body.addEventListener('drop', (e) => {
|
| 473 |
-
e.preventDefault();
|
| 474 |
-
overlay.classList.remove('active');
|
| 475 |
-
if(e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
| 476 |
-
const fi = getFi();
|
| 477 |
-
if(fi) {
|
| 478 |
-
fi.files = e.dataTransfer.files;
|
| 479 |
-
fi.dispatchEvent(new Event('change', {bubbles: true}));
|
| 480 |
-
}
|
| 481 |
-
}
|
| 482 |
-
});
|
| 483 |
-
}
|
| 484 |
-
"""
|
| 485 |
-
|
| 486 |
with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
|
| 487 |
with gr.Column(elem_id="col-container"):
|
| 488 |
gr.Markdown("# **PaperX / Mineru Parsing Platform**", elem_id="main-title")
|
| 489 |
gr.Markdown("One-click parsing of academic PDFs, DAG structuring, and multi-modal asset generation.", elem_id="subtitle")
|
| 490 |
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
# ================= LEFT COLUMN =================
|
| 495 |
-
with gr.Column(scale=1, elem_classes="stretch-col"):
|
| 496 |
|
| 497 |
# 1. API Configuration
|
| 498 |
with gr.Accordion("βοΈ 1. Global API Configuration", open=False, elem_classes="gradio-group"):
|
|
@@ -504,20 +408,9 @@ with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
|
|
| 504 |
# 2. Document Parsing
|
| 505 |
with gr.Group(elem_classes="gradio-group"):
|
| 506 |
gr.Markdown("### π 2. Document Parsing")
|
|
|
|
| 507 |
|
| 508 |
-
|
| 509 |
-
gr.HTML("""
|
| 510 |
-
<div id="custom-upload-zone">
|
| 511 |
-
<svg viewBox="0 0 24 24" fill="none" style="height: 60px; margin-bottom: 10px; margin: auto;">
|
| 512 |
-
<path d="M7 10V9C7 6.23858 9.23858 4 12 4C14.7614 4 17 6.23858 17 9V10C19.2091 10 21 11.7909 21 14C21 15.4806 20.1956 16.8084 19 17.5M7 10C4.79086 10 3 11.7909 3 14C3 15.4806 3.8044 16.8084 5 17.5M7 10C7.43285 10 7.84965 10.0688 8.24006 10.1959M12 12V21M12 12L15 15M12 12L9 15" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
|
| 513 |
-
</svg>
|
| 514 |
-
<h3>Click to Select PDF</h3>
|
| 515 |
-
<p style="margin-top: 5px; opacity: 0.8;">Or drop a file anywhere on this window to upload</p>
|
| 516 |
-
</div>
|
| 517 |
-
""")
|
| 518 |
-
|
| 519 |
-
# Hidden Gradio Input Target
|
| 520 |
-
pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"], elem_id="pdf-upload", elem_classes="hidden-upload")
|
| 521 |
|
| 522 |
parse_status = gr.Textbox(
|
| 523 |
show_label=False,
|
|
@@ -526,23 +419,21 @@ with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
|
|
| 526 |
interactive=False,
|
| 527 |
elem_classes="status-text"
|
| 528 |
)
|
| 529 |
-
parse_btn = gr.Button("π Start Mineru & DAG Extraction", variant="primary", size="lg")
|
| 530 |
|
| 531 |
# 3. Asset Generation
|
| 532 |
with gr.Group(elem_classes="gradio-group"):
|
| 533 |
gr.Markdown("### π― 3. Asset Generation")
|
| 534 |
gr.Markdown("Generate final formats based on DAG structure:")
|
| 535 |
|
| 536 |
-
# Scale=1 and min_width force identically sized buttons
|
| 537 |
with gr.Row():
|
| 538 |
-
gen_ppt_btn = gr.Button("π Generate PPT"
|
| 539 |
-
gen_poster_btn = gr.Button("πΌοΈ Generate Poster"
|
| 540 |
-
gen_pr_btn = gr.Button("π° Generate PR Article"
|
| 541 |
|
| 542 |
gen_all_btn = gr.Button("β¨ Generate All Assets (ALL)", variant="primary")
|
| 543 |
|
| 544 |
-
# ================= RIGHT COLUMN =================
|
| 545 |
-
with gr.Column(scale=1
|
| 546 |
|
| 547 |
# 4. Results & Downloads
|
| 548 |
with gr.Group(elem_classes="gradio-group"):
|
|
@@ -556,15 +447,15 @@ with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
|
|
| 556 |
)
|
| 557 |
download_file = gr.File(label="π₯ Get Final Zip Archive", interactive=False, visible=False)
|
| 558 |
|
| 559 |
-
# 5. Debugging & Terminal
|
| 560 |
-
with gr.Group(elem_classes="gradio-group
|
| 561 |
gr.Markdown("### π οΈ Developer Monitoring (Debug Only)")
|
| 562 |
with gr.Tabs():
|
| 563 |
with gr.Tab("π Terminal Stream"):
|
| 564 |
cmd_logs = gr.Textbox(
|
| 565 |
label="Stdout / Stderr",
|
| 566 |
placeholder="Waiting for task to start...",
|
| 567 |
-
lines=
|
| 568 |
interactive=False,
|
| 569 |
elem_classes="log-box"
|
| 570 |
)
|
|
@@ -573,16 +464,13 @@ with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
|
|
| 573 |
refresh_btn = gr.Button("π Refresh Directory Tree")
|
| 574 |
debug_view = gr.Textbox(
|
| 575 |
label="Workspace Files",
|
| 576 |
-
lines=
|
| 577 |
interactive=False,
|
| 578 |
value=get_debug_info(),
|
| 579 |
elem_classes="log-box"
|
| 580 |
)
|
| 581 |
|
| 582 |
# ================= LOGIC BINDINGS =================
|
| 583 |
-
# Load custom JS to handle the drag overlay and click triggers
|
| 584 |
-
demo.load(js=drag_drop_js)
|
| 585 |
-
|
| 586 |
key_btn.click(fn=save_api_settings, inputs=[key_input, api_base_url_input], outputs=[parse_status, debug_view])
|
| 587 |
|
| 588 |
pdf_input.upload(fn=save_pdf, inputs=pdf_input, outputs=[parse_status, debug_view])
|
|
|
|
| 335 |
font-size: 1.1rem;
|
| 336 |
font-weight: 500;
|
| 337 |
}
|
| 338 |
+
|
| 339 |
.dark #subtitle p { color: #DAB2FF; }
|
| 340 |
|
| 341 |
/* Glassmorphism Cards */
|
|
|
|
| 359 |
border-color: rgba(168, 85, 247, 0.3) !important;
|
| 360 |
}
|
| 361 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
/* Terminal Log Style */
|
| 363 |
.log-box textarea {
|
| 364 |
font-family: 'IBM Plex Mono', Consolas, monospace !important;
|
|
|
|
| 378 |
color: #6B21A8 !important;
|
| 379 |
}
|
| 380 |
|
| 381 |
+
.dark .status-text textarea {
|
| 382 |
+
color: #C084FC !important;
|
| 383 |
+
}
|
| 384 |
|
| 385 |
/* Custom Scrollbars */
|
| 386 |
::-webkit-scrollbar { width: 8px; height: 8px; }
|
|
|
|
| 389 |
::-webkit-scrollbar-thumb:hover { background: linear-gradient(135deg, #9333EA, #A855F7); }
|
| 390 |
"""
|
| 391 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
|
| 393 |
with gr.Column(elem_id="col-container"):
|
| 394 |
gr.Markdown("# **PaperX / Mineru Parsing Platform**", elem_id="main-title")
|
| 395 |
gr.Markdown("One-click parsing of academic PDFs, DAG structuring, and multi-modal asset generation.", elem_id="subtitle")
|
| 396 |
|
| 397 |
+
with gr.Row():
|
| 398 |
+
# ================= LEFT COLUMN: SETTINGS & ACTIONS =================
|
| 399 |
+
with gr.Column(scale=1):
|
|
|
|
|
|
|
| 400 |
|
| 401 |
# 1. API Configuration
|
| 402 |
with gr.Accordion("βοΈ 1. Global API Configuration", open=False, elem_classes="gradio-group"):
|
|
|
|
| 408 |
# 2. Document Parsing
|
| 409 |
with gr.Group(elem_classes="gradio-group"):
|
| 410 |
gr.Markdown("### π 2. Document Parsing")
|
| 411 |
+
pdf_input = gr.File(label="Drag and drop or click to upload PDF", file_types=[".pdf"])
|
| 412 |
|
| 413 |
+
parse_btn = gr.Button("π Start Mineru & DAG Extraction", variant="primary", size="lg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
|
| 415 |
parse_status = gr.Textbox(
|
| 416 |
show_label=False,
|
|
|
|
| 419 |
interactive=False,
|
| 420 |
elem_classes="status-text"
|
| 421 |
)
|
|
|
|
| 422 |
|
| 423 |
# 3. Asset Generation
|
| 424 |
with gr.Group(elem_classes="gradio-group"):
|
| 425 |
gr.Markdown("### π― 3. Asset Generation")
|
| 426 |
gr.Markdown("Generate final formats based on DAG structure:")
|
| 427 |
|
|
|
|
| 428 |
with gr.Row():
|
| 429 |
+
gen_ppt_btn = gr.Button("π Generate PPT")
|
| 430 |
+
gen_poster_btn = gr.Button("πΌοΈ Generate Poster")
|
| 431 |
+
gen_pr_btn = gr.Button("π° Generate PR Article")
|
| 432 |
|
| 433 |
gen_all_btn = gr.Button("β¨ Generate All Assets (ALL)", variant="primary")
|
| 434 |
|
| 435 |
+
# ================= RIGHT COLUMN: OUTPUTS & LOGS =================
|
| 436 |
+
with gr.Column(scale=1):
|
| 437 |
|
| 438 |
# 4. Results & Downloads
|
| 439 |
with gr.Group(elem_classes="gradio-group"):
|
|
|
|
| 447 |
)
|
| 448 |
download_file = gr.File(label="π₯ Get Final Zip Archive", interactive=False, visible=False)
|
| 449 |
|
| 450 |
+
# 5. Debugging & Terminal
|
| 451 |
+
with gr.Group(elem_classes="gradio-group"):
|
| 452 |
gr.Markdown("### π οΈ Developer Monitoring (Debug Only)")
|
| 453 |
with gr.Tabs():
|
| 454 |
with gr.Tab("π Terminal Stream"):
|
| 455 |
cmd_logs = gr.Textbox(
|
| 456 |
label="Stdout / Stderr",
|
| 457 |
placeholder="Waiting for task to start...",
|
| 458 |
+
lines=14,
|
| 459 |
interactive=False,
|
| 460 |
elem_classes="log-box"
|
| 461 |
)
|
|
|
|
| 464 |
refresh_btn = gr.Button("π Refresh Directory Tree")
|
| 465 |
debug_view = gr.Textbox(
|
| 466 |
label="Workspace Files",
|
| 467 |
+
lines=13,
|
| 468 |
interactive=False,
|
| 469 |
value=get_debug_info(),
|
| 470 |
elem_classes="log-box"
|
| 471 |
)
|
| 472 |
|
| 473 |
# ================= LOGIC BINDINGS =================
|
|
|
|
|
|
|
|
|
|
| 474 |
key_btn.click(fn=save_api_settings, inputs=[key_input, api_base_url_input], outputs=[parse_status, debug_view])
|
| 475 |
|
| 476 |
pdf_input.upload(fn=save_pdf, inputs=pdf_input, outputs=[parse_status, debug_view])
|