Laramie2 commited on
Commit
0b7a4cb
·
verified ·
1 Parent(s): a21e552

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -21
app.py CHANGED
@@ -236,6 +236,13 @@ custom_css = """
236
  background-color: #1e1e1e !important;
237
  color: #4AF626 !important;
238
  }
 
 
 
 
 
 
 
239
  """
240
 
241
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), css=custom_css) as demo:
@@ -251,39 +258,54 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), css=custom_css) as de
251
  with gr.Row():
252
  key_input = gr.Textbox(label="API Key", type="password", placeholder="sk-...", scale=1)
253
  api_base_url_input = gr.Textbox(label="Base URL (可选)", placeholder="https://api.example.com", scale=1)
254
- key_btn = gr.Button("💾 保存 API 配置") # 统一尺寸
255
 
256
  # 2. 核心上传与解析
257
  with gr.Group():
258
  gr.Markdown("### 📄 2. 文档解析")
 
259
  pdf_input = gr.File(label="拖拽或点击上传 PDF", file_types=[".pdf"])
260
 
261
- with gr.Row():
262
- # 去掉 size="sm",使其与右侧 primary 按钮等高对齐
263
- pdf_btn = gr.Button("📥 1. 加载文件")
264
- parse_btn = gr.Button("🚀 2. 执行 Mineru & DAG 抽取", variant="primary")
265
 
266
- parse_status = gr.Textbox(label="解析进度", lines=1, interactive=False)
 
 
 
 
 
 
 
267
 
268
  # 3. 最终产物生成
269
  with gr.Group():
270
  gr.Markdown("### 🎯 3. 产物生成")
271
  gr.Markdown("基于 DAG 结构生成最终所需格式:")
 
 
 
 
 
272
  with gr.Row():
273
- # 去掉 size="sm",让这三个按钮等高且填满当前行
274
- gen_ppt_btn = gr.Button("📊 PPT")
275
- gen_poster_btn = gr.Button("🖼️ Poster")
276
- gen_pr_btn = gr.Button("📰 PR 文章")
277
- # 下方的 ALL 按钮也是默认尺寸,整体模块视觉统一
278
- gen_all_btn = gr.Button("✨ 一键生成全部 (ALL)", variant="primary")
279
 
280
  # ================= 右侧:状态与日志监控区 =================
281
  with gr.Column(scale=5):
282
  with gr.Tabs():
283
  # Tab 1: 结果与下载
284
  with gr.Tab("📦 生成结果 & 下载"):
285
- gen_status = gr.Textbox(label="当前生成状态", lines=4, interactive=False)
286
- download_file = gr.File(label="📥 获取最终压缩包", interactive=False)
 
 
 
 
 
 
 
 
287
 
288
  # Tab 2: 实时终端
289
  with gr.Tab("📜 终端流 (Terminal)"):
@@ -292,28 +314,38 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), css=custom_css) as de
292
  placeholder="等待任务开始...",
293
  lines=22,
294
  interactive=False,
295
- elem_classes="log-box" # 应用自定义 CSS
296
  )
297
 
298
  # Tab 3: 文件系统快照
299
  with gr.Tab("🔍 系统快照 (Debug)"):
300
- refresh_btn = gr.Button("🔄 刷新目录树") # 统一尺寸
301
  debug_view = gr.Textbox(label="Workspace Files", lines=20, interactive=False, value=get_debug_info())
302
 
303
  # ================= 逻辑绑定 =================
304
 
305
  key_btn.click(fn=save_api_settings, inputs=[key_input, api_base_url_input], outputs=[parse_status, debug_view])
306
- pdf_btn.click(fn=save_pdf, inputs=pdf_input, outputs=[parse_status, debug_view])
 
 
 
307
 
308
  parse_btn.click(
309
  fn=run_mineru_parsing_and_dag_gen,
310
  outputs=[parse_status, debug_view, cmd_logs]
311
  )
312
 
313
- gen_ppt_btn.click(fn=lambda: run_final_generation("ppt"), outputs=[gen_status, debug_view, cmd_logs, download_file])
314
- gen_poster_btn.click(fn=lambda: run_final_generation("poster"), outputs=[gen_status, debug_view, cmd_logs, download_file])
315
- gen_pr_btn.click(fn=lambda: run_final_generation("pr"), outputs=[gen_status, debug_view, cmd_logs, download_file])
316
- gen_all_btn.click(fn=lambda: run_final_generation("all"), outputs=[gen_status, debug_view, cmd_logs, download_file])
 
 
 
 
 
 
 
317
 
318
  refresh_btn.click(fn=get_debug_info, outputs=debug_view)
319
 
 
236
  background-color: #1e1e1e !important;
237
  color: #4AF626 !important;
238
  }
239
+ /* 可选:进一步弱化状态框的边框感,使其更像文字标签 */
240
+ .status-text textarea {
241
+ background-color: transparent !important;
242
+ border: none !important;
243
+ box-shadow: none !important;
244
+ font-weight: bold;
245
+ }
246
  """
247
 
248
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), css=custom_css) as demo:
 
258
  with gr.Row():
259
  key_input = gr.Textbox(label="API Key", type="password", placeholder="sk-...", scale=1)
260
  api_base_url_input = gr.Textbox(label="Base URL (可选)", placeholder="https://api.example.com", scale=1)
261
+ key_btn = gr.Button("💾 保存 API 配置")
262
 
263
  # 2. 核心上传与解析
264
  with gr.Group():
265
  gr.Markdown("### 📄 2. 文档解析")
266
+ # 去掉了原来的“加载文件”按钮,改为拖拽自动上传
267
  pdf_input = gr.File(label="拖拽或点击上传 PDF", file_types=[".pdf"])
268
 
269
+ # 让解析按钮独占一行,并放大尺寸,成为视觉焦点
270
+ parse_btn = gr.Button("🚀 开始执行 Mineru & DAG 抽取", variant="primary", size="lg")
 
 
271
 
272
+ # 弱化状态框视觉(去掉了 Label)
273
+ parse_status = gr.Textbox(
274
+ show_label=False,
275
+ placeholder="等待上传文档...",
276
+ lines=1,
277
+ interactive=False,
278
+ elem_classes="status-text"
279
+ )
280
 
281
  # 3. 最终产物生成
282
  with gr.Group():
283
  gr.Markdown("### 🎯 3. 产物生成")
284
  gr.Markdown("基于 DAG 结构生成最终所需格式:")
285
+
286
+ # 采用 2x2 网格布局,结构更紧凑平衡
287
+ with gr.Row():
288
+ gen_ppt_btn = gr.Button("📊 单独生成 PPT")
289
+ gen_poster_btn = gr.Button("🖼️ 单独生成 Poster")
290
  with gr.Row():
291
+ gen_pr_btn = gr.Button("📰 单独生成 PR 文章")
292
+ gen_all_btn = gr.Button(" 一键生成全部 (ALL)", variant="primary")
 
 
 
 
293
 
294
  # ================= 右侧:状态与日志监控区 =================
295
  with gr.Column(scale=5):
296
  with gr.Tabs():
297
  # Tab 1: 结果与下载
298
  with gr.Tab("📦 生成结果 & 下载"):
299
+ # 弱化状态框视觉
300
+ gen_status = gr.Textbox(
301
+ show_label=False,
302
+ placeholder="当前暂无生成任务...",
303
+ lines=4,
304
+ interactive=False,
305
+ elem_classes="status-text"
306
+ )
307
+ # 默认隐藏下载框 (visible=False),生成成功后再动态展示
308
+ download_file = gr.File(label="📥 获取最终压缩包", interactive=False, visible=False)
309
 
310
  # Tab 2: 实时终端
311
  with gr.Tab("📜 终端流 (Terminal)"):
 
314
  placeholder="等待任务开始...",
315
  lines=22,
316
  interactive=False,
317
+ elem_classes="log-box"
318
  )
319
 
320
  # Tab 3: 文件系统快照
321
  with gr.Tab("🔍 系统快照 (Debug)"):
322
+ refresh_btn = gr.Button("🔄 刷新目录树")
323
  debug_view = gr.Textbox(label="Workspace Files", lines=20, interactive=False, value=get_debug_info())
324
 
325
  # ================= 逻辑绑定 =================
326
 
327
  key_btn.click(fn=save_api_settings, inputs=[key_input, api_base_url_input], outputs=[parse_status, debug_view])
328
+
329
+ # 🎯 优化:绑定上传和清除事件,实现自动化
330
+ pdf_input.upload(fn=save_pdf, inputs=pdf_input, outputs=[parse_status, debug_view])
331
+ pdf_input.clear(fn=lambda: ("ℹ️ 已清空文件", get_debug_info()), outputs=[parse_status, debug_view])
332
 
333
  parse_btn.click(
334
  fn=run_mineru_parsing_and_dag_gen,
335
  outputs=[parse_status, debug_view, cmd_logs]
336
  )
337
 
338
+ # 🎯 优化:增加包装函数,用于动态控制下载组件的显示与隐藏
339
+ def trigger_gen(task):
340
+ status, debug, logs, file_path = run_final_generation(task)
341
+ # 如果 file_path 存在,显示下载组件并赋值;否则保持隐藏
342
+ file_update = gr.update(value=file_path, visible=True) if file_path else gr.update(visible=False)
343
+ return status, debug, logs, file_update
344
+
345
+ gen_ppt_btn.click(fn=lambda: trigger_gen("ppt"), outputs=[gen_status, debug_view, cmd_logs, download_file])
346
+ gen_poster_btn.click(fn=lambda: trigger_gen("poster"), outputs=[gen_status, debug_view, cmd_logs, download_file])
347
+ gen_pr_btn.click(fn=lambda: trigger_gen("pr"), outputs=[gen_status, debug_view, cmd_logs, download_file])
348
+ gen_all_btn.click(fn=lambda: trigger_gen("all"), outputs=[gen_status, debug_view, cmd_logs, download_file])
349
 
350
  refresh_btn.click(fn=get_debug_info, outputs=debug_view)
351