Spaces:
Sleeping
Sleeping
Update app.py
Browse files69 unmodified lines707172737475762 unmodified lines79808182838485868788899091929394959697989910010110210369 unmodified linesdef run_mineru_parsing():"""执行 PDF 解析逻辑"""# 1. 判断是否上传了 PDF (检查 papers 文件夹是否为空)if not os.path.exists(PAPERS_DIR) or not any(f.endswith('.pdf') for f in os.listdir(PAPERS_DIR)):return "❌ 未发现已上传的 PDF 文件,请先执行步骤 2。", get_debug_info()2 unmodified linesenv = os.environ.copy()env["MINERU_FORMULA_ENABLE"] = "false"env["MINERU_TABLE_ENABLE"] = "false"# 3. 执行 Mineru 命令# 使用 list 形式传递参数更安全command = ["mineru", "-p", "papers", "-o", "mineru_outputs"]# 提示开始执行print(f"Executing: {' '.join(command)}", file=sys.stderr, flush=True)# 执行并等待结束result = subprocess.run(command, env=env, capture_output=True, text=True)if result.returncode == 0:return "✅ PDF解析完成", get_debug_info()else:return f"❌ 解析过程中出错: {result.stderr}", get_debug_info()except Exception as e:return f"❌ 执行命令时发生异常: {str(e)}", get_debug_info()# --- 构建单页 UI ---with gr.Blocks(theme=gr.themes.Soft()) as demo:gr.Markdown("# 📑 PDF 助手管理后台")69 unmodified lines707172737475762 unmodified lines79808182838485868788899091929394959697989910010110210369 unmodified linesdef run_mineru_parsing():"""执行 PDF 解析逻辑"""# 1. 判断是否上传了 PDFif not os.path.exists(PAPERS_DIR) or not any(f.endswith('.pdf') for f in os.listdir(PAPERS_DIR)):return "❌ 未发现已上传的 PDF 文件,请先执行步骤 2。", get_debug_info()2 unmodified linesenv = os.environ.copy()env["MINERU_FORMULA_ENABLE"] = "false"env["MINERU_TABLE_ENABLE"] = "false"# 强制指定为 cpu 模式,防止 mineru 内部检测 torch/cuda 时报错env["MINERU_DEVICE_MODE"] = "cpu"# 3. 执行 Mineru 命令command = ["mineru", "-p", "papers", "-o", "mineru_outputs"]print(f"Executing: {' '.join(command)}", file=sys.stderr, flush=True)# 使用 subprocess 执行result = subprocess.run(command, env=env, capture_output=True, text=True)if result.returncode == 0:return "✅ PDF解析完成", get_debug_info()else:# 如果报错,返回具体的错误信息供调试return f"❌ 解析过程中出错: {result.stderr}", get_debug_info()except Exception as e:return f"❌ 执行命令时发生异常: {str(e)}", get_debug_info()# --- 构建单页 UI ---with gr.Blocks(theme=gr.themes.Soft()) as demo:gr.Markdown("# 📑 PDF 助手管理后台")
app.py+5-5