snym04 commited on
Commit
e3dc6c5
·
verified ·
1 Parent(s): 8444eea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -70,7 +70,7 @@ def save_api_key(api_key):
70
 
71
  def run_mineru_parsing():
72
  """执行 PDF 解析逻辑"""
73
- # 1. 判断是否上传了 PDF (检查 papers 文件夹是否为空)
74
  if not os.path.exists(PAPERS_DIR) or not any(f.endswith('.pdf') for f in os.listdir(PAPERS_DIR)):
75
  return "❌ 未发现已上传的 PDF 文件,请先执行步骤 2。", get_debug_info()
76
 
@@ -79,25 +79,25 @@ def run_mineru_parsing():
79
  env = os.environ.copy()
80
  env["MINERU_FORMULA_ENABLE"] = "false"
81
  env["MINERU_TABLE_ENABLE"] = "false"
 
 
82
 
83
  # 3. 执行 Mineru 命令
84
- # 使用 list 形式传递参数更安全
85
  command = ["mineru", "-p", "papers", "-o", "mineru_outputs"]
86
 
87
- # 提示开始执行
88
  print(f"Executing: {' '.join(command)}", file=sys.stderr, flush=True)
89
 
90
- # 执行并等待结束
91
  result = subprocess.run(command, env=env, capture_output=True, text=True)
92
 
93
  if result.returncode == 0:
94
  return "✅ PDF解析完成", get_debug_info()
95
  else:
 
96
  return f"❌ 解析过程中出错: {result.stderr}", get_debug_info()
97
 
98
  except Exception as e:
99
  return f"❌ 执行命令时发生异常: {str(e)}", get_debug_info()
100
-
101
  # --- 构建单页 UI ---
102
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
103
  gr.Markdown("# 📑 PDF 助手管理后台")
 
70
 
71
  def run_mineru_parsing():
72
  """执行 PDF 解析逻辑"""
73
+ # 1. 判断是否上传了 PDF
74
  if not os.path.exists(PAPERS_DIR) or not any(f.endswith('.pdf') for f in os.listdir(PAPERS_DIR)):
75
  return "❌ 未发现已上传的 PDF 文件,请先执行步骤 2。", get_debug_info()
76
 
 
79
  env = os.environ.copy()
80
  env["MINERU_FORMULA_ENABLE"] = "false"
81
  env["MINERU_TABLE_ENABLE"] = "false"
82
+ # 强制指定为 cpu 模式,防止 mineru 内部检测 torch/cuda 时报错
83
+ env["MINERU_DEVICE_MODE"] = "cpu"
84
 
85
  # 3. 执行 Mineru 命令
 
86
  command = ["mineru", "-p", "papers", "-o", "mineru_outputs"]
87
 
 
88
  print(f"Executing: {' '.join(command)}", file=sys.stderr, flush=True)
89
 
90
+ # 使用 subprocess 执行
91
  result = subprocess.run(command, env=env, capture_output=True, text=True)
92
 
93
  if result.returncode == 0:
94
  return "✅ PDF解析完成", get_debug_info()
95
  else:
96
+ # 如果报错,返回具体的错误信息供调试
97
  return f"❌ 解析过程中出错: {result.stderr}", get_debug_info()
98
 
99
  except Exception as e:
100
  return f"❌ 执行命令时发生异常: {str(e)}", get_debug_info()
 
101
  # --- 构建单页 UI ---
102
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
103
  gr.Markdown("# 📑 PDF 助手管理后台")