# parse-service - 多模态解析服务 基于 FastAPI 的多模态文件解析服务,支持 PDF/Office/图片/音视频。 --- ## 一、快速开始 ### 1.1 安装依赖 ```bash cd parse-service # 安装 Python 依赖 pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple # 安装系统依赖 (需要 sudo) # macOS: brew install ffmpeg antiword # Ubuntu/Debian: apt-get install ffmpeg antiword ``` ### 1.2 本地测试解析(不启动服务) 先用 Python 直接测试解析: ```bash # 使用 duomotai/examples 下的示例文件 python test_local.py # 或指定文件 python test_local.py ../duomotai/examples/xxx.pdf ``` ### 1.3 启动 FastAPI 服务 ```bash # 方式 1: 直接用 Python 启动 python main.py # 方式 2: 用 uvicorn 启动 uvicorn main:app --host 0.0.0.0 --port 8000 --reload ``` 服务启动后访问: - API 文档: http://localhost:8000/docs - 健康检查: http://localhost:8000/health ### 1.4 测试 API ```bash # 1. 健康检查 curl http://localhost:8000/health # 2. 上传文件解析 curl -X POST -F "file=@../duomotai/examples/xxx.pdf" \ http://localhost:8000/api/v1/parse # 3. 本地路径解析(给 Flink 调用) curl -X POST "http://localhost:8000/api/v1/parse/path?file_path=/absolute/path/to/file.pdf" ``` --- ## 二、Docker 部署 ### 2.1 构建镜像 ```bash cd parse-service docker build -t parse-service:latest . ``` ### 2.2 启动容器 ```bash docker run -d \ --name parse-service \ -p 8000:8000 \ -v /path/to/data:/data \ parse-service:latest ``` --- ## 三、API 文档 ### 3.1 健康检查 **接口**: `GET /health` **响应示例**: ```json { "status": "healthy", "service": "parse-service", "models": { "qwen_vl": "connected", "qwen_asr": "connected", "mineru": "connected" } } ``` ### 3.2 上传文件解析 **接口**: `POST /api/v1/parse` **请求**: multipart/form-data - `file`: 文件 **响应示例**: ```json { "code": 200, "message": "success", "data": { "task_id": "uuid", "file_type": "pdf", "content": "# 解析后的 Markdown 内容...", "metadata": { "page_count": 10, "file_size": 1024000 }, "tables": [], "parse_time_ms": 1523 } } ``` ### 3.3 本地路径解析(Flink 调用) **接口**: `POST /api/v1/parse/path` **参数**: - `file_path`: 文件绝对路径 **响应**: 同上 --- ## 四、支持的文件类型 | 类型 | 格式 | 解析引擎 | |------|------|---------| | PDF | 原生/扫描件 | PyMuPDF / MinerU | | Word | docx/doc | python-docx / antiword | | Excel | xlsx | openpyxl | | PowerPoint | pptx | python-pptx | | 图片 | png/jpg/tiff | MinerU (OCR) | | 音频 | wav/mp3 | Qwen3-ASR | | 视频 | mp4/avi | FFmpeg + Qwen3-ASR + Qwen3-VL | --- ## 五、配置 ### 环境变量 | 变量 | 默认值 | 说明 | |------|--------|------| | UPLOAD_DIR | /tmp/parse-service/uploads | 上传文件临时目录 | | MINERU_API_URL | http://10.192.72.13:7284 | MinerU API 地址 | | QWEN_VL_URL | http://10.192.72.13:7280 | Qwen3-VL API 地址 | | QWEN_ASR_URL | http://10.192.72.13:7283 | Qwen3-ASR API 地址 |