图提取器API和MCP服务器
使用此基于FastAPI的服务从PDF文档中提取图表。图形提取器API和MCP服务器为PDFFigures 2.0提供了一个简单的HTTP接口,这是艾伦人工智能研究所开发的一个强大的图形提取系统。
此API包装器非常适合集成到各种应用程序和工作流中,尤其是用于Retrieval-AugedGeneration(RAG)应用程序。
MCP服务器,由 FastMCP,将PDF提取功能作为MCP工具公开。这允许与可以自动调用提取服务的AI代理和工作流无缝集成。
- 服务器承载
extract_figures_from_pdf工具,可以通过HTTP请求调用/mcp终点。此工具接收PDF URL,处理文档,并以结构化JSON格式返回提取的图形和表格。
默认的MCP服务器url: http://localhost:5001/mcp关于PDFFigures 2.0
这项API服务建立在PDFFigures 2.0之上,这是艾伦人工智能研究所的一个基于标量的项目。PDFFigles 2.0专门设计用于从计算机科学领域的学术文档中提取图形、标题、表格和章节标题。他们的学术论文《PDFFigures 2.0:从研究论文中挖掘数字》(Clark和Divvala,2016)描述了这项原创工作。你可以看报纸 这里 并参观 PDFFigures 2.0网站.
┌─────────────────┐ ┌──────────────────┐ ┌────────────────┐
│ Your App │ HTTP │ Figure Extractor │ JNI │ PDFFigures │
│ (Any Language) │──────► API & MCP Server│──────► 2.0 │
│ │ │ Python(FastAPI) │ │ (Scala/JVM) │
└─────────────────┘ └──────────────────┘ └────────────────┘特性
- PDF图形和表格提取
- 支持本地和远程PDF文件
- 提取的表格和图表统计
- Docker支持,易于部署
- PDF解析的可视化选项
FastMCP工具
该项目现在包括 FastMCP 该工具允许以编程方式调用PDF提取服务。这 extract_figures_from_pdf 该工具可用于从给定URL的PDF中提取数字。
用例
- *机器学习数据集创建*
从临床试验报告和研究论文中提取视觉数据,为医学图像分析和人工智能模型构建训练数据集,使研究人员能够有效地汇总数据,以训练医疗诊断中的机器学习算法。
- *临床研究数据挖掘*
自动从医学研究文章中提取和分类数据,捕获治疗效果图、患者结果图和实验结果图等关键可视化数据,以支持系统评价和荟萃分析。
- *学术文献综述与教育*
从学术出版物中快速编译全面的视觉库,使研究人员和教育工作者能够创建教学资源,比较研究方法,并跟踪跨科学学科的视觉趋势。
Docker部署
构建并启动提取服务器:
docker build -t pdffigures2 .
docker run -d -p 5001:5001 pdffigures2图片是 约286MB --通过Alpine基础进行优化, jlink 最小JRE和pip清理:
┌──────────┬───────┬────────┬───────────────┐
│ 指标 │ 原始 │ 优化后 │ 变化 │
├──────────┼───────┼────────┼───────────────┤
│ 基础镜像 │ slim │ alpine │ -70MB │
│ JRE │ apt │ jlink │ +42MB │
│ pip 包 │ 原始 │ 清理后 │ -24MB │
│ 系统包 │ apt │ apk │ -12MB │
├──────────┼───────┼────────┼───────────────┤
│ 镜像大小 │ 452MB │ 286MB │ -166MB (-37%) │
└──────────┴───────┴────────┴───────────────┘测试API
- 打开
http://localhost:5001/docs查看API文档。
- 使用
curl要测试从PDF URL中提取:
curl -X POST http://localhost:5001/api/extract \
-F "pdf_url=https://example.com/sample.pdf"代理技能(非MCP)
API客户端调用提取服务器并在本地下载渲染的图形。专为没有MCP支持的代理环境而设计。
# Copy config and point to the server
cp .env.example .env
# (edit .env if the server is remote)
# Run extraction against a local PDF
skills/pdffigures2/scripts/pdffigures2 paper.pdf -o ./extracted/脚本将PDF发布到 PDFFIGURES2_API_URL,下载每个渲染的图形,并将结构化的JSON摘要打印到stdout。看 skills/pdffigures2/SKILL.md 获取面向代理的完整文档。
用法
从PDF中提取图表
这 /api/extract 端点现在支持PDF文件上传和PDF URL。
使用API
您可以向发送POST请求 /api/extract 其中之一:
- A.
file(多部分/表单数据)包含PDF。 - A.
pdf_url(表单数据)包含PDF的URL。
API将返回一个JSON响应,其中包含提取的图形和表格,包括完整的 renderURL 路径。
JSON响应示例(imageText 为简洁起见截断):
[
{
"caption": "TABLE III CMAPSS DATASET ATTRIBUTES",
"captionBoundary": {
"x1": 113.12599182128906,
"x2": 225.1184844970703,
"y1": 116.80506896972656,
"y2": 130.57305908203125
},
"figType": "Table",
"imageText": [
"Required", "fan", "conversion", "speed", "rpm", "High-pressure", "turbines", "cool", "air", "flow",
"lbm/s", "Low-pressure", "turbines", "cool", "air", "flow", "lbm/s", "Bleed", "enthalpy", "-", "Required"
],
"name": "III",
"page": 5,
"regionBoundary": {
"x1": 46.8,
"x2": 291.12,
"y1": 140.88,
"y2": 385.91999999999996
},
"renderDpi": 300,
"renderURL": "http://localhost:5001/resources/4-TableIII-1.png"
},
{
"caption": "Fig. 3. Agentic AI implementation with Google ADK.",
"captionBoundary": {
"x1": 335.4129943847656,
"x2": 516.9002685546875,
"y1": 228.6050567626953,
"y2": 233.40704345703125
},
"figType": "Figure",
"imageText": [],
"name": "3",
"page": 5,
"regionBoundary": {
"x1": 302.88,
"x2": 549.12,
"y1": 86.88,
"y2": 216
},
"renderDpi": 300,
"renderURL": "http://localhost:5001/resources/4-Figure3-1.png"
},
{
"caption": "TABLE I COMPARISON BETWEEN AI AGENTS AND AGENTIC AI",
"captionBoundary": {
"x1": 204.9189910888672,
"x2": 390.3569641113281,
"y1": 54.10902404785156,
"y2": 67.87701416015625
},
"figType": "Table",
"imageText": [
"pert", "systems", "LLM-based", "agents,", "multi-agent", "coordination,", "intent-based", "workflows", "Task",
"Scope", "Focused", "on", "short-term,", "well-defined", "tasks", "Oriented", "toward", "long-term,", "dynamic,",
],
"name": "I",
"page": 2,
"regionBoundary": {
"x1": 51.839999999999996,
"x2": 543.12,
"y1": 77.75999999999999,
"y2": 217.92
},
"renderDpi": 300,
"renderURL": "http://localhost:5001/resources/4-TableI-1.png"
},
{
"caption": "Fig. 1. Traditional AI Agent vs. Agentic AI",
"captionBoundary": {
"x1": 224.30499267578125,
"x2": 370.9708251953125,
"y1": 448.1660461425781,
"y2": 452.968017578125
},
"figType": "Figure",
"imageText": [],
"name": "1",
"page": 2,
"regionBoundary": {
"x1": 45.839999999999996,
"x2": 549.12,
"y1": 230.88,
"y2": 436.08
},
"renderDpi": 300,
"renderURL": "http://localhost:5001/resources/4-Figure1-1.png"
},
{
"caption": "TABLE IV SUMMARY OF ENGINE MAINTENANCE ACTIONS",
"captionBoundary": {
"x1": 215.99301147460938,
"x2": 379.2913513183594,
"y1": 54.10902404785156,
"y2": 67.87701416015625
},
"figType": "Table",
"imageText": [
"#", "Engines", "RUL", "Range", "Recommended", "Action", "Priority", "Cost", "(USD)", "Labor", "Hours", "Assigned",
"Staff", "Scheduled", "Time", "15", "82–124", "MONITOR", "low", "0", "0", "[jr", "mechanic]", "Within", "7", "days"
],
"name": "IV",
"page": 7,
"regionBoundary": {
"x1": 48.96,
"x2": 549.12,
"y1": 77.75999999999999,
"y2": 135.12
},
"renderDpi": 300,
"renderURL": "http://localhost:5001/resources/4-TableIV-1.png"
},
{
"caption": "TABLE II KEY COMPONENTS OF INTENTION PROCESSING",
"captionBoundary": {
"x1": 345.09295654296875,
"x2": 507.22100830078125,
"y1": 417.8482666015625,
"y2": 431.6162414550781
},
"figType": "Table",
"imageText": [
"Targets", "Specify", "the", "resources", "or", "entities", "to", "which", "the", "intent", "applies.", "Can", "be",
"defined", "statically", "(explicit", "list)", "or", "dynamically", "(using", "filters", "or", "criteria).", "Context"
],
"name": "II",
"page": 3,
"regionBoundary": {
"x1": 302.88,
"x2": 549.12,
"y1": 441.84,
"y2": 677.04
},
"renderDpi": 300,
"renderURL": "http://localhost:5001/resources/4-TableII-1.png"
},
{
"caption": "Fig. 2. Proposed framework for Industry 5.0 applying intent-based and Agentic AI.",
"captionBoundary": {
"x1": 159.51600646972656,
"x2": 435.7596435546875,
"y1": 288.3310241699219,
"y2": 293.13299560546875
},
"figType": "Figure",
"imageText": [],
"name": "2",
"page": 4,
"regionBoundary": {
"x1": 45.839999999999996,
"x2": 549.12,
"y1": 49.68,
"y2": 276
},
"renderDpi": 300,
"renderURL": "http://localhost:5001/resources/4-Figure2-1.png"
}
]开发人员设置
如果你想修改代码或在没有Docker的情况下在本地运行,请克隆存储库:
git clone https://github.com/vlln/pdffigures-mcp-server.git
cd pdffigures-mcp-server使用figure_extractor.py进行测试
figure_extractor.py 是一个CLI工具,用于针对正在运行的API服务器测试提取。它向API发送本地PDF,并下载提取的数字:
# Start the server first (via Docker or uvicorn), then:
python figure_extractor.py
--output_dir ./output选项:
--output_dir--保存下载图形的目录(默认:./output)--url-自定义API终结点(默认值:http://localhost:5001/api/extract)
应用结构
project/
├── Dockerfile # Multi-stage Alpine image (server + jlink JRE + pdffigures2 JAR)
├── .dockerignore
├── .env.example # Example config for the Agent Skill
├── app/ # FastAPI web service code
│ ├── __init__.py
│ ├── app.py # API endpoints and MCP Server
│ ├── service.py # Runs pdffigures2 JAR via subprocess
│ └── utils.py # File I/O helpers
├── skills/ # Agent Skills (non-MCP alternative)
│ └── pdffigures2/ # API client wrapper for pdffigures2
├── figure_extractor.py # CLI tool for testing extraction
└── README.md致谢
这个项目是 黄实验室/图形提取器我们感谢原作者的工作。
许可证
此项目根据Apache许可证2.0获得许可。
