Laramie2 commited on
Commit
45c98bb
·
verified ·
1 Parent(s): c44f1a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -42
app.py CHANGED
@@ -207,69 +207,96 @@ def run_final_generation(task_type="all"):
207
  error_log = full_log + f"\n[全局异常] Exception occurred:\n{str(e)}"
208
  return "❌ 最终生成发生全局异常", get_debug_info(), error_log, None
209
 
210
- # --- UI ---
211
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
212
- gr.Markdown("# 📑 Mineru PDF 解析调试器")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
  with gr.Row():
215
- with gr.Column(scale=1):
 
 
 
 
 
 
 
 
 
 
216
  with gr.Group():
217
- gr.Markdown("### 1. 配置 & 上传")
218
- key_input = gr.Textbox(label="API Key", type="password", placeholder="请输入您的 API Key")
219
- # 👇 这里新增了 Base URL 的输入框
220
- api_base_url_input = gr.Textbox(label="API Base URL (可选)", placeholder="例如: https://api.example.com/")
221
- key_btn = gr.Button("保存配置") # 稍微改了下名字更贴切
222
- gr.Markdown("---")
223
- pdf_input = gr.File(label="选择 PDF", file_types=[".pdf"])
224
- pdf_btn = gr.Button("保存 PDF")
225
 
226
- with gr.Group():
227
- gr.Markdown("### 2. 执行解析")
228
- parse_btn = gr.Button("🚀 Run Mineru & DAG Gen", variant="primary")
229
- parse_status = gr.Textbox(label="运行状态")
 
230
 
 
231
  with gr.Group():
232
- gr.Markdown("### 3. 最终生成")
233
- gr.Markdown("请选择要生成的内容类型:")
234
  with gr.Row():
235
- gen_ppt_btn = gr.Button("📊 生成 PPT")
236
- gen_poster_btn = gr.Button("🖼️ 生成 Poster")
237
- gen_pr_btn = gr.Button("📰 生成 PR")
238
- gen_all_btn = gr.Button("🔨 生成全部 (ALL)", variant="primary")
239
-
240
- gen_status = gr.Textbox(label="生成状态")
241
- download_file = gr.File(label="下载压缩后的结果", interactive=False)
242
 
243
- with gr.Column(scale=1):
244
- gr.Markdown("### 🔍 实时系统监控")
245
- debug_view = gr.Textbox(label="文件系统快照", value=get_debug_info(), lines=8, interactive=False)
246
-
247
- gr.Markdown("### 📜 终端输出日志")
248
- cmd_logs = gr.Textbox(
249
- label="Command Output (Stdout/Stderr)",
250
- placeholder="等待任务开始...",
251
- lines=20,
252
- interactive=False
253
- )
254
- refresh_btn = gr.Button("🔄 刷新状态")
 
 
 
 
 
 
 
 
 
 
255
 
256
  # ================= 逻辑绑定 =================
257
- # 👇 这里绑定了两个输入框
258
- key_btn.click(save_api_settings, inputs=[key_input, api_base_url_input], outputs=[parse_status, debug_view])
259
- pdf_btn.click(save_pdf, inputs=pdf_input, outputs=[parse_status, debug_view])
260
 
261
  parse_btn.click(
262
  fn=run_mineru_parsing_and_dag_gen,
263
  outputs=[parse_status, debug_view, cmd_logs]
264
  )
265
 
266
- # 最终生成逻辑绑定
267
  gen_ppt_btn.click(fn=lambda: run_final_generation("ppt"), outputs=[gen_status, debug_view, cmd_logs, download_file])
268
  gen_poster_btn.click(fn=lambda: run_final_generation("poster"), outputs=[gen_status, debug_view, cmd_logs, download_file])
269
  gen_pr_btn.click(fn=lambda: run_final_generation("pr"), outputs=[gen_status, debug_view, cmd_logs, download_file])
270
  gen_all_btn.click(fn=lambda: run_final_generation("all"), outputs=[gen_status, debug_view, cmd_logs, download_file])
271
 
272
- refresh_btn.click(get_debug_info, outputs=debug_view)
273
 
274
  if __name__ == "__main__":
275
  demo.launch()
 
207
  error_log = full_log + f"\n[全局异常] Exception occurred:\n{str(e)}"
208
  return "❌ 最终生成发生全局异常", get_debug_info(), error_log, None
209
 
210
+
211
+ # ==========================================
212
+ # --- 🚀 全新美化的 UI (Hugging Face 优化版) ---
213
+ # ==========================================
214
+
215
+ # 自定义 CSS:让终端日志看起来像真正的 Terminal
216
+ custom_css = """
217
+ .log-box textarea {
218
+ font-family: 'Courier New', Consolas, monospace !important;
219
+ font-size: 13px !important;
220
+ background-color: #1e1e1e !important;
221
+ color: #4AF626 !important;
222
+ }
223
+ """
224
+
225
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), css=custom_css) as demo:
226
+ gr.Markdown("# 📑 PaperX / Mineru 智能解析平台")
227
+ gr.Markdown("将学术 PDF 一键解析、DAG 结构化并生成多模态产物。")
228
 
229
  with gr.Row():
230
+ # ================= 左侧:工作流控制区 =================
231
+ with gr.Column(scale=4):
232
+
233
+ # 1. 隐藏式全局配置
234
+ with gr.Accordion("⚙️ 1. 全局 API 配置", open=False):
235
+ with gr.Row():
236
+ key_input = gr.Textbox(label="API Key", type="password", placeholder="sk-...", scale=1)
237
+ api_base_url_input = gr.Textbox(label="Base URL (可选)", placeholder="https://api.example.com", scale=1)
238
+ key_btn = gr.Button("💾 保存 API 配置", size="sm")
239
+
240
+ # 2. 核心上传与解析
241
  with gr.Group():
242
+ gr.Markdown("### 📄 2. 文档解析")
243
+ pdf_input = gr.File(label="拖拽或点击上传 PDF", file_types=[".pdf"])
 
 
 
 
 
 
244
 
245
+ with gr.Row():
246
+ pdf_btn = gr.Button("📥 1. 加载文件", size="sm")
247
+ parse_btn = gr.Button("🚀 2. 执行 Mineru & DAG 抽取", variant="primary")
248
+
249
+ parse_status = gr.Textbox(label="解析进度", lines=1, interactive=False)
250
 
251
+ # 3. 最终产物生成
252
  with gr.Group():
253
+ gr.Markdown("### 🎯 3. 产物生成")
254
+ gr.Markdown("基于 DAG 结构生成最终所需格式:")
255
  with gr.Row():
256
+ gen_ppt_btn = gr.Button("📊 PPT", size="sm")
257
+ gen_poster_btn = gr.Button("🖼️ Poster", size="sm")
258
+ gen_pr_btn = gr.Button("📰 PR 文章", size="sm")
259
+ gen_all_btn = gr.Button(" 一键生成全部 (ALL)", variant="primary")
 
 
 
260
 
261
+ # ================= 右侧:状态与日志监控区 =================
262
+ with gr.Column(scale=5):
263
+ with gr.Tabs():
264
+ # Tab 1: 结果与下载
265
+ with gr.Tab("📦 生成结果 & 下载"):
266
+ gen_status = gr.Textbox(label="当前生成状态", lines=4, interactive=False)
267
+ download_file = gr.File(label="📥 获取最终压缩包", interactive=False)
268
+
269
+ # Tab 2: 实时终端
270
+ with gr.Tab("📜 终端流 (Terminal)"):
271
+ cmd_logs = gr.Textbox(
272
+ label="Stdout / Stderr",
273
+ placeholder="等待任务开始...",
274
+ lines=22,
275
+ interactive=False,
276
+ elem_classes="log-box" # 应用自定义 CSS
277
+ )
278
+
279
+ # Tab 3: 文件系统快照
280
+ with gr.Tab("🔍 系统快照 (Debug)"):
281
+ refresh_btn = gr.Button("🔄 刷新目录树", size="sm")
282
+ debug_view = gr.Textbox(label="Workspace Files", lines=20, interactive=False, value=get_debug_info())
283
 
284
  # ================= 逻辑绑定 =================
285
+
286
+ key_btn.click(fn=save_api_settings, inputs=[key_input, api_base_url_input], outputs=[parse_status, debug_view])
287
+ pdf_btn.click(fn=save_pdf, inputs=pdf_input, outputs=[parse_status, debug_view])
288
 
289
  parse_btn.click(
290
  fn=run_mineru_parsing_and_dag_gen,
291
  outputs=[parse_status, debug_view, cmd_logs]
292
  )
293
 
 
294
  gen_ppt_btn.click(fn=lambda: run_final_generation("ppt"), outputs=[gen_status, debug_view, cmd_logs, download_file])
295
  gen_poster_btn.click(fn=lambda: run_final_generation("poster"), outputs=[gen_status, debug_view, cmd_logs, download_file])
296
  gen_pr_btn.click(fn=lambda: run_final_generation("pr"), outputs=[gen_status, debug_view, cmd_logs, download_file])
297
  gen_all_btn.click(fn=lambda: run_final_generation("all"), outputs=[gen_status, debug_view, cmd_logs, download_file])
298
 
299
+ refresh_btn.click(fn=get_debug_info, outputs=debug_view)
300
 
301
  if __name__ == "__main__":
302
  demo.launch()