Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ from gradio.themes.utils import colors, fonts, sizes
|
|
| 15 |
# 自动安装 Playwright 浏览器(如果不存在)
|
| 16 |
try:
|
| 17 |
import playwright
|
|
|
|
| 18 |
subprocess.run(["playwright", "install", "chromium"], check=True)
|
| 19 |
except Exception as e:
|
| 20 |
print(f"Playwright setup failed: {e}")
|
|
@@ -41,17 +42,42 @@ def get_user_dirs(session_id):
|
|
| 41 |
# --- 🎨 Custom Purple Theme Definition ---
|
| 42 |
# ==========================================
|
| 43 |
colors.purple = colors.Color(
|
| 44 |
-
name="purple",
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
)
|
| 48 |
|
| 49 |
class PurpleTheme(Soft):
|
| 50 |
-
def __init__(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
super().__init__(
|
| 52 |
-
primary_hue=
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
)
|
| 56 |
super().set(
|
| 57 |
background_fill_primary="*primary_50",
|
|
@@ -59,14 +85,26 @@ class PurpleTheme(Soft):
|
|
| 59 |
body_background_fill="linear-gradient(135deg, *primary_200, *primary_100)",
|
| 60 |
body_background_fill_dark="linear-gradient(135deg, *primary_900, *primary_800)",
|
| 61 |
button_primary_text_color="white",
|
|
|
|
| 62 |
button_primary_background_fill="linear-gradient(90deg, *secondary_500, *secondary_600)",
|
| 63 |
button_primary_background_fill_hover="linear-gradient(90deg, *secondary_600, *secondary_700)",
|
|
|
|
|
|
|
| 64 |
button_secondary_text_color="black",
|
|
|
|
| 65 |
button_secondary_background_fill="linear-gradient(90deg, *primary_300, *primary_300)",
|
|
|
|
|
|
|
|
|
|
| 66 |
slider_color="*secondary_500",
|
|
|
|
|
|
|
| 67 |
block_border_width="3px",
|
| 68 |
block_shadow="*shadow_drop_lg",
|
| 69 |
button_primary_shadow="*shadow_drop_lg",
|
|
|
|
|
|
|
|
|
|
| 70 |
)
|
| 71 |
|
| 72 |
purple_theme = PurpleTheme()
|
|
@@ -236,7 +274,6 @@ def run_mineru_parsing_and_dag_gen(session_id, api_key, api_base_url, progress=g
|
|
| 236 |
error_log = full_log + f"\n[Global Exception]:\n{str(e)}"
|
| 237 |
yield "❌ Execution Exception", get_debug_info(session_id), error_log, disable_btn, disable_btn, disable_btn, disable_btn
|
| 238 |
|
| 239 |
-
|
| 240 |
def run_final_generation(task_type, session_id, api_key, api_base_url, progress=gr.Progress()):
|
| 241 |
papers_dir, output_dir, zip_path = get_user_dirs(session_id)
|
| 242 |
|
|
@@ -307,7 +344,6 @@ def run_final_generation(task_type, session_id, api_key, api_base_url, progress=
|
|
| 307 |
error_log = full_log + f"\n[Global Exception]:\n{str(e)}"
|
| 308 |
yield "❌ Global exception", get_debug_info(session_id), error_log, gr.update(visible=False)
|
| 309 |
|
| 310 |
-
|
| 311 |
# ==========================================
|
| 312 |
# --- 🚀 UI Configuration & Advanced CSS ---
|
| 313 |
# ==========================================
|
|
@@ -498,6 +534,7 @@ with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
|
|
| 498 |
gr.Markdown("One-click parsing of academic PDFs, DAG structuring, and multi-modal asset generation.", elem_id="subtitle")
|
| 499 |
|
| 500 |
with gr.Row():
|
|
|
|
| 501 |
with gr.Column(scale=1):
|
| 502 |
# 1. API Configuration
|
| 503 |
with gr.Group(elem_classes="gradio-group"):
|
|
@@ -506,42 +543,56 @@ with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
|
|
| 506 |
key_input = gr.Textbox(label="API Key", type="password", placeholder="sk-...", scale=1)
|
| 507 |
api_base_url_input = gr.Textbox(label="Base URL (Optional)", placeholder="https://api.example.com", scale=1)
|
| 508 |
key_btn = gr.Button("💾 Save API Configuration")
|
| 509 |
-
api_status = gr.Textbox(
|
|
|
|
|
|
|
| 510 |
|
| 511 |
# 2. Document Parsing
|
| 512 |
with gr.Group(elem_classes="gradio-group"):
|
| 513 |
gr.Markdown("### 📄 2. Document Parsing")
|
| 514 |
-
pdf_input = gr.File(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 515 |
parse_btn = gr.Button("🚀 Start Mineru & DAG Extraction", elem_classes="primary-action-btn", interactive=False)
|
| 516 |
-
parse_status = gr.Textbox(
|
|
|
|
|
|
|
| 517 |
|
| 518 |
# 3. Asset Generation
|
| 519 |
with gr.Group(elem_classes="gradio-group"):
|
| 520 |
gr.Markdown("### 🎯 3. Asset Generation")
|
|
|
|
| 521 |
with gr.Row(elem_classes="action-row"):
|
| 522 |
gen_ppt_btn = gr.Button("📊 Gen PPT", elem_classes="action-btn", interactive=False)
|
| 523 |
gen_poster_btn = gr.Button("🖼️ Gen Poster", elem_classes="action-btn", interactive=False)
|
| 524 |
gen_pr_btn = gr.Button("📰 Gen PR", elem_classes="action-btn", interactive=False)
|
| 525 |
gen_all_btn = gr.Button("✨ Generate All Assets (ALL)", elem_classes="primary-action-btn", interactive=False)
|
| 526 |
|
|
|
|
| 527 |
with gr.Column(scale=1):
|
| 528 |
# 4. Results & Downloads
|
| 529 |
with gr.Group(elem_classes="gradio-group"):
|
| 530 |
gr.Markdown("### 📦 Generation Results & Download")
|
| 531 |
-
gen_status = gr.Textbox(
|
|
|
|
|
|
|
| 532 |
download_file = gr.File(label="📥 Get Final Zip Archive", interactive=False, visible=False)
|
| 533 |
|
| 534 |
-
# 5. Debugging
|
| 535 |
with gr.Group(elem_classes="gradio-group"):
|
| 536 |
gr.Markdown("### 🛠️ Developer Monitoring (Debug Only)")
|
| 537 |
with gr.Tabs():
|
| 538 |
with gr.Tab("📜 Terminal Stream"):
|
| 539 |
-
cmd_logs = gr.Textbox(
|
|
|
|
|
|
|
| 540 |
with gr.Tab("🔍 System Snapshot"):
|
| 541 |
refresh_btn = gr.Button("🔄 Refresh Directory Tree")
|
| 542 |
debug_view = gr.HTML()
|
| 543 |
|
| 544 |
-
# ================= LOGIC BINDINGS =================
|
| 545 |
|
| 546 |
# [新增] 专门的页面初始化函数:当用户打开网页时,生成 UUID 并返回给 State
|
| 547 |
def init_app_for_user():
|
|
@@ -553,7 +604,7 @@ with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
|
|
| 553 |
# 在页面加载的瞬间,生成专属 ID 存入状态,并渲染空的监控视图
|
| 554 |
demo.load(fn=init_app_for_user, inputs=None, outputs=[session_id_state, debug_view])
|
| 555 |
|
| 556 |
-
# =================
|
| 557 |
|
| 558 |
key_btn.click(
|
| 559 |
fn=save_api_settings,
|
|
@@ -599,4 +650,4 @@ with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
|
|
| 599 |
refresh_btn.click(fn=get_debug_info, inputs=[session_id_state], outputs=debug_view)
|
| 600 |
|
| 601 |
if __name__ == "__main__":
|
| 602 |
-
demo.
|
|
|
|
| 15 |
# 自动安装 Playwright 浏览器(如果不存在)
|
| 16 |
try:
|
| 17 |
import playwright
|
| 18 |
+
# 检查是否已经安装了浏览器,没有则下载
|
| 19 |
subprocess.run(["playwright", "install", "chromium"], check=True)
|
| 20 |
except Exception as e:
|
| 21 |
print(f"Playwright setup failed: {e}")
|
|
|
|
| 42 |
# --- 🎨 Custom Purple Theme Definition ---
|
| 43 |
# ==========================================
|
| 44 |
colors.purple = colors.Color(
|
| 45 |
+
name="purple",
|
| 46 |
+
c50="#FAF5FF",
|
| 47 |
+
c100="#F3E8FF",
|
| 48 |
+
c200="#E9D5FF",
|
| 49 |
+
c300="#DAB2FF",
|
| 50 |
+
c400="#C084FC",
|
| 51 |
+
c500="#A855F7",
|
| 52 |
+
c600="#9333EA",
|
| 53 |
+
c700="#7E22CE",
|
| 54 |
+
c800="#6B21A8",
|
| 55 |
+
c900="#581C87",
|
| 56 |
+
c950="#3B0764",
|
| 57 |
)
|
| 58 |
|
| 59 |
class PurpleTheme(Soft):
|
| 60 |
+
def __init__(
|
| 61 |
+
self,
|
| 62 |
+
*,
|
| 63 |
+
primary_hue: colors.Color | str = colors.gray,
|
| 64 |
+
secondary_hue: colors.Color | str = colors.purple,
|
| 65 |
+
neutral_hue: colors.Color | str = colors.slate,
|
| 66 |
+
text_size: sizes.Size | str = sizes.text_lg,
|
| 67 |
+
font: fonts.Font | str | Iterable[fonts.Font | str] = (
|
| 68 |
+
fonts.GoogleFont("Outfit"), "Arial", "sans-serif",
|
| 69 |
+
),
|
| 70 |
+
font_mono: fonts.Font | str | Iterable[fonts.Font | str] = (
|
| 71 |
+
fonts.GoogleFont("IBM Plex Mono"), "ui-monospace", "monospace",
|
| 72 |
+
),
|
| 73 |
+
):
|
| 74 |
super().__init__(
|
| 75 |
+
primary_hue=primary_hue,
|
| 76 |
+
secondary_hue=secondary_hue,
|
| 77 |
+
neutral_hue=neutral_hue,
|
| 78 |
+
text_size=text_size,
|
| 79 |
+
font=font,
|
| 80 |
+
font_mono=font_mono,
|
| 81 |
)
|
| 82 |
super().set(
|
| 83 |
background_fill_primary="*primary_50",
|
|
|
|
| 85 |
body_background_fill="linear-gradient(135deg, *primary_200, *primary_100)",
|
| 86 |
body_background_fill_dark="linear-gradient(135deg, *primary_900, *primary_800)",
|
| 87 |
button_primary_text_color="white",
|
| 88 |
+
button_primary_text_color_hover="white",
|
| 89 |
button_primary_background_fill="linear-gradient(90deg, *secondary_500, *secondary_600)",
|
| 90 |
button_primary_background_fill_hover="linear-gradient(90deg, *secondary_600, *secondary_700)",
|
| 91 |
+
button_primary_background_fill_dark="linear-gradient(90deg, *secondary_600, *secondary_700)",
|
| 92 |
+
button_primary_background_fill_hover_dark="linear-gradient(90deg, *secondary_500, *secondary_600)",
|
| 93 |
button_secondary_text_color="black",
|
| 94 |
+
button_secondary_text_color_hover="white",
|
| 95 |
button_secondary_background_fill="linear-gradient(90deg, *primary_300, *primary_300)",
|
| 96 |
+
button_secondary_background_fill_hover="linear-gradient(90deg, *primary_400, *primary_400)",
|
| 97 |
+
button_secondary_background_fill_dark="linear-gradient(90deg, *primary_500, *primary_600)",
|
| 98 |
+
button_secondary_background_fill_hover_dark="linear-gradient(90deg, *primary_500, *primary_500)",
|
| 99 |
slider_color="*secondary_500",
|
| 100 |
+
slider_color_dark="*secondary_600",
|
| 101 |
+
block_title_text_weight="600",
|
| 102 |
block_border_width="3px",
|
| 103 |
block_shadow="*shadow_drop_lg",
|
| 104 |
button_primary_shadow="*shadow_drop_lg",
|
| 105 |
+
button_large_padding="11px",
|
| 106 |
+
color_accent_soft="*primary_100",
|
| 107 |
+
block_label_background_fill="*primary_200",
|
| 108 |
)
|
| 109 |
|
| 110 |
purple_theme = PurpleTheme()
|
|
|
|
| 274 |
error_log = full_log + f"\n[Global Exception]:\n{str(e)}"
|
| 275 |
yield "❌ Execution Exception", get_debug_info(session_id), error_log, disable_btn, disable_btn, disable_btn, disable_btn
|
| 276 |
|
|
|
|
| 277 |
def run_final_generation(task_type, session_id, api_key, api_base_url, progress=gr.Progress()):
|
| 278 |
papers_dir, output_dir, zip_path = get_user_dirs(session_id)
|
| 279 |
|
|
|
|
| 344 |
error_log = full_log + f"\n[Global Exception]:\n{str(e)}"
|
| 345 |
yield "❌ Global exception", get_debug_info(session_id), error_log, gr.update(visible=False)
|
| 346 |
|
|
|
|
| 347 |
# ==========================================
|
| 348 |
# --- 🚀 UI Configuration & Advanced CSS ---
|
| 349 |
# ==========================================
|
|
|
|
| 534 |
gr.Markdown("One-click parsing of academic PDFs, DAG structuring, and multi-modal asset generation.", elem_id="subtitle")
|
| 535 |
|
| 536 |
with gr.Row():
|
| 537 |
+
# ================= LEFT COLUMN: SETTINGS & ACTIONS =================
|
| 538 |
with gr.Column(scale=1):
|
| 539 |
# 1. API Configuration
|
| 540 |
with gr.Group(elem_classes="gradio-group"):
|
|
|
|
| 543 |
key_input = gr.Textbox(label="API Key", type="password", placeholder="sk-...", scale=1)
|
| 544 |
api_base_url_input = gr.Textbox(label="Base URL (Optional)", placeholder="https://api.example.com", scale=1)
|
| 545 |
key_btn = gr.Button("💾 Save API Configuration")
|
| 546 |
+
api_status = gr.Textbox(
|
| 547 |
+
show_label=False, placeholder="Waiting for API configuration...", lines=1, interactive=False, elem_classes="status-text"
|
| 548 |
+
)
|
| 549 |
|
| 550 |
# 2. Document Parsing
|
| 551 |
with gr.Group(elem_classes="gradio-group"):
|
| 552 |
gr.Markdown("### 📄 2. Document Parsing")
|
| 553 |
+
pdf_input = gr.File(
|
| 554 |
+
label="Upload Document",
|
| 555 |
+
file_types=[".pdf"],
|
| 556 |
+
elem_id="pdf-upload-box"
|
| 557 |
+
)
|
| 558 |
parse_btn = gr.Button("🚀 Start Mineru & DAG Extraction", elem_classes="primary-action-btn", interactive=False)
|
| 559 |
+
parse_status = gr.Textbox(
|
| 560 |
+
show_label=False, placeholder="Waiting for document upload...", lines=1, interactive=False, elem_classes="status-text"
|
| 561 |
+
)
|
| 562 |
|
| 563 |
# 3. Asset Generation
|
| 564 |
with gr.Group(elem_classes="gradio-group"):
|
| 565 |
gr.Markdown("### 🎯 3. Asset Generation")
|
| 566 |
+
gr.Markdown("Generate final formats based on DAG structure:")
|
| 567 |
with gr.Row(elem_classes="action-row"):
|
| 568 |
gen_ppt_btn = gr.Button("📊 Gen PPT", elem_classes="action-btn", interactive=False)
|
| 569 |
gen_poster_btn = gr.Button("🖼️ Gen Poster", elem_classes="action-btn", interactive=False)
|
| 570 |
gen_pr_btn = gr.Button("📰 Gen PR", elem_classes="action-btn", interactive=False)
|
| 571 |
gen_all_btn = gr.Button("✨ Generate All Assets (ALL)", elem_classes="primary-action-btn", interactive=False)
|
| 572 |
|
| 573 |
+
# ================= RIGHT COLUMN: OUTPUTS & LOGS =================
|
| 574 |
with gr.Column(scale=1):
|
| 575 |
# 4. Results & Downloads
|
| 576 |
with gr.Group(elem_classes="gradio-group"):
|
| 577 |
gr.Markdown("### 📦 Generation Results & Download")
|
| 578 |
+
gen_status = gr.Textbox(
|
| 579 |
+
show_label=False, placeholder="No generation task currently...", lines=2, interactive=False, elem_classes="status-text"
|
| 580 |
+
)
|
| 581 |
download_file = gr.File(label="📥 Get Final Zip Archive", interactive=False, visible=False)
|
| 582 |
|
| 583 |
+
# 5. Debugging & Terminal
|
| 584 |
with gr.Group(elem_classes="gradio-group"):
|
| 585 |
gr.Markdown("### 🛠️ Developer Monitoring (Debug Only)")
|
| 586 |
with gr.Tabs():
|
| 587 |
with gr.Tab("📜 Terminal Stream"):
|
| 588 |
+
cmd_logs = gr.Textbox(
|
| 589 |
+
label="Stdout / Stderr", placeholder="Waiting for task to start...", lines=14, interactive=False, elem_classes="log-box"
|
| 590 |
+
)
|
| 591 |
with gr.Tab("🔍 System Snapshot"):
|
| 592 |
refresh_btn = gr.Button("🔄 Refresh Directory Tree")
|
| 593 |
debug_view = gr.HTML()
|
| 594 |
|
| 595 |
+
# ================= LOGIC BINDINGS =================
|
| 596 |
|
| 597 |
# [新增] 专门的页面初始化函数:当用户打开网页时,生成 UUID 并返回给 State
|
| 598 |
def init_app_for_user():
|
|
|
|
| 604 |
# 在页面加载的瞬间,生成专属 ID 存入状态,并渲染空的监控视图
|
| 605 |
demo.load(fn=init_app_for_user, inputs=None, outputs=[session_id_state, debug_view])
|
| 606 |
|
| 607 |
+
# ================= EVENT BINDINGS =================
|
| 608 |
|
| 609 |
key_btn.click(
|
| 610 |
fn=save_api_settings,
|
|
|
|
| 650 |
refresh_btn.click(fn=get_debug_info, inputs=[session_id_state], outputs=debug_view)
|
| 651 |
|
| 652 |
if __name__ == "__main__":
|
| 653 |
+
demo.launch()
|