文档转换服务开源项目教程

文档转换服务开源项目教程

docling-api Easily deployable and scalable backend server that efficiently converts various document formats (pdf, docx, pptx, html, images, etc) into Markdown. With support for both CPU and GPU processing, it is Ideal for large-scale workflows, it offers text/table extraction, OCR, and batch processing with sync/async endpoints. docling-api 项目地址: https://gitcode.com/gh_mirrors/do/docling-api

1. 项目介绍

本项目是基于 Docling(IBM 的先进文档解析器)构建的一个强大的文档转换服务。它能够将多种格式的文档(如 PDF、DOCX、PPTX、CSV、HTML、图片等)转换为 Markdown 格式。项目使用 FastAPI、Celery 和 Redis 技术栈,支持 CPU 和 GPU 处理模式,适用于大规模工作流的文档处理。

2. 项目快速启动

环境准备

  • Python 3.8 或更高版本
  • Poetry(Python 包管理工具)
  • Redis 服务器(用于任务队列)
安装 Poetry

如果尚未安装 Poetry,可以使用以下命令安装:

curl -sSL https://install.python-poetry.org | python3 -
克隆和设置项目
git clone https://github.com/drmingler/docling-api.git
cd docling-api
poetry install
配置环境

在项目根目录创建一个 .env 文件:

REDIS_HOST=redis://localhost:6379/0
ENV=development
启动 Redis 服务器

根据操作系统启动 Redis:

  • 对于 MacOS:
    brew install redis
    brew services start redis
    
  • 对于 Ubuntu/Debian:
    sudo apt-get install redis-server
    sudo service redis-server start
    
启动应用组件
  • 启动 FastAPI 服务器:

    poetry run uvicorn main:app --reload --port 8080
    
  • 启动 Celery 工作进程(在新终端中):

    poetry run celery -A worker.celery_config worker --pool=solo -n worker_primary --loglevel=info
    
  • 启动 Flower 监控面板(可选,在新终端中):

    poetry run celery -A worker.celery_config flower --port=5555
    
验证安装
  • 检查 API 服务器是否运行:

    curl http://localhost:8080/docs
    
  • 测试 Celery 工作进程:

    curl -X POST \
      "http://localhost:8080/documents/convert" \
      -H "accept: application/json" \
      -H "Content-Type: multipart/form-data" \
      -F "document=@/path/to/test.pdf"
    
  • 访问监控面板: 打开浏览器并访问 http://localhost:5555 查看 Flower 监控面板。

3. 应用案例和最佳实践

同步转换文档

curl -X POST \
  "http://localhost:8080/documents/convert" \
  -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "document=@/path/to/document.pdf" \
  -F "extract_tables_as_images=true" \
  -F "image_resolution_scale=4"

异步转换文档

提交文档进行转换
curl -X POST \
  "http://localhost:8080/conversion-jobs" \
  -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "document=@/path/to/document.pdf"
检查转换状态
curl -X GET \
  "http://localhost:8080/conversion-jobs/{job_id}" \
  -H "accept: application/json"

批量处理

curl -X POST \
  "http://localhost:8080/batch-conversion-jobs" \
  -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "documents=@/path/to/document1.pdf" \
  -F "documents=@/path/to/document2.pdf"

4. 典型生态项目

  • 文档管理平台:集成此服务,实现文档格式转换功能。
  • 内容管理系统:使用该服务转换上传的文档,以便统一管理和显示。
  • 教育平台:将教学资料转换为 Markdown,便于学生查看和教师编辑。

docling-api Easily deployable and scalable backend server that efficiently converts various document formats (pdf, docx, pptx, html, images, etc) into Markdown. With support for both CPU and GPU processing, it is Ideal for large-scale workflows, it offers text/table extraction, OCR, and batch processing with sync/async endpoints. docling-api 项目地址: https://gitcode.com/gh_mirrors/do/docling-api

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乌容柳Zelene

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值