[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-CatchTheTornado--text-extract-api":3,"tool-CatchTheTornado--text-extract-api":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",149489,2,"2026-04-10T11:32:46",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":67,"readme_en":68,"readme_zh":69,"quickstart_zh":70,"use_case_zh":71,"hero_image_url":72,"owner_login":73,"owner_name":74,"owner_avatar_url":75,"owner_bio":76,"owner_company":77,"owner_location":77,"owner_email":78,"owner_twitter":77,"owner_website":79,"owner_url":80,"languages":81,"stars":98,"forks":99,"last_commit_at":100,"license":101,"difficulty_score":93,"env_os":102,"env_gpu":103,"env_ram":104,"env_deps":105,"category_tags":119,"github_topics":120,"view_count":32,"oss_zip_url":77,"oss_zip_packed_at":77,"status":17,"created_at":130,"updated_at":131,"faqs":132,"releases":162},6363,"CatchTheTornado\u002Ftext-extract-api","text-extract-api","Document (PDF, Word, PPTX ...) extraction and parse API using state of the art modern OCRs + Ollama supported models. Anonymize documents. Remove PII. Convert any document or picture to structured JSON or Markdown","text-extract-api 是一款强大的开源文档处理工具，旨在将 PDF、Word、PPTX 等各类文档或图片，高精度地转换为结构化的 Markdown 文本或 JSON 数据。它不仅能精准提取表格、数字和数学公式，还能利用大语言模型（如 Llama 3）自动修正 OCR 识别中的拼写错误，并支持一键移除文档中的个人敏感信息（PII），实现数据匿名化。\n\n该工具主要解决了传统 OCR 技术在复杂版面还原、内容结构化以及隐私保护方面的痛点，让非结构化文档变得易于机器读取和分析。其最大的技术亮点在于完全本地化部署：基于 Docker Compose 集成 PyTorch OCR 引擎与 Ollama 大模型，所有数据处理均在用户自己的服务器或开发环境中完成，无需上传云端，充分保障数据安全。此外，它还内置了 Celery 分布式任务队列和 Redis 缓存机制，确保高效稳定的批量处理能力。\n\ntext-extract-api 非常适合需要处理大量文档数据的开发者、研究人员及企业技术团队使用。无论是构建知识库、自动化财务发票处理，还是进行医疗报告分析，它都能提供灵活且私密的解决方案。通过","text-extract-api 是一款强大的开源文档处理工具，旨在将 PDF、Word、PPTX 等各类文档或图片，高精度地转换为结构化的 Markdown 文本或 JSON 数据。它不仅能精准提取表格、数字和数学公式，还能利用大语言模型（如 Llama 3）自动修正 OCR 识别中的拼写错误，并支持一键移除文档中的个人敏感信息（PII），实现数据匿名化。\n\n该工具主要解决了传统 OCR 技术在复杂版面还原、内容结构化以及隐私保护方面的痛点，让非结构化文档变得易于机器读取和分析。其最大的技术亮点在于完全本地化部署：基于 Docker Compose 集成 PyTorch OCR 引擎与 Ollama 大模型，所有数据处理均在用户自己的服务器或开发环境中完成，无需上传云端，充分保障数据安全。此外，它还内置了 Celery 分布式任务队列和 Redis 缓存机制，确保高效稳定的批量处理能力。\n\ntext-extract-api 非常适合需要处理大量文档数据的开发者、研究人员及企业技术团队使用。无论是构建知识库、自动化财务发票处理，还是进行医疗报告分析，它都能提供灵活且私密的解决方案。通过简单的命令行接口或 API 调用，用户即可轻松将其集成到现有的工作流中。","# text-extract-api\n\nConvert any image, PDF or Office document to Markdown *text* or JSON structured document with super-high accuracy, including tabular data, numbers or math formulas.\n\nThe API is built with FastAPI and uses Celery for asynchronous task processing. Redis is used for caching OCR results.\n\n![hero doc extract](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FCatchTheTornado_text-extract-api_readme_c42a336c15e2.webp)\n\n## Features:\n- **No Cloud\u002Fexternal dependencies** all you need: PyTorch based OCR (EasyOCR) + Ollama are shipped and configured via `docker-compose` no data is sent outside your dev\u002Fserver environment,\n- **PDF\u002FOffice to Markdown** conversion with very high accuracy using different OCR strategies including [llama3.2-vision](https:\u002F\u002Fai.meta.com\u002Fblog\u002Fllama-3-2-connect-2024-vision-edge-mobile-devices\u002F), [easyOCR](https:\u002F\u002Fgithub.com\u002FJaidedAI\u002FEasyOCR), [minicpm-v](https:\u002F\u002Fgithub.com\u002FOpenBMB\u002FMiniCPM-o?tab=readme-ov-file#minicpm-v-26), remote URL strategies including [marker-pdf](https:\u002F\u002Fgithub.com\u002FVikParuchuri\u002Fmarker)\n- **PDF\u002FOffice to JSON** conversion using Ollama supported models (eg. LLama 3.1)\n- **LLM Improving OCR results** LLama is pretty good with fixing spelling and text issues in the OCR text\n- **Removing PII** This tool can be used for removing Personally Identifiable Information out of document - see `examples`\n- **Distributed queue processing** using [Celery](https:\u002F\u002Fdocs.celeryq.dev\u002Fen\u002Fstable\u002Fgetting-started\u002Fintroduction.html)\n- **Caching** using Redis - the OCR results can be easily cached prior to LLM processing,\n- **Storage Strategies** switchable storage strategies (Google Drive, Local File System ...)\n- **CLI tool** for sending tasks and processing results \n\n## Screenshots\n\nConverting MRI report to Markdown + JSON.\n\n```bash \npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-mri.pdf --prompt_file examples\u002Fexample-mri-2-json-prompt.txt\n```\n\nBefore running the example see [getting started](#getting-started)\n\n![Converting MRI report to Markdown](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FCatchTheTornado_text-extract-api_readme_08119ffbe35c.png)\n\nConverting Invoice to JSON and remove PII\n\n```bash \npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-invoice.pdf --prompt_file examples\u002Fexample-invoice-remove-pii.txt \n```\n\nBefore running the example see [getting started](#getting-started)\n\n![Converting Invoice to JSON](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FCatchTheTornado_text-extract-api_readme_4d1dff2bd7e9.png)\n\n## Getting started\n\nYou might want to run the app directly on your machine for development purposes OR to use for example Apple GPUs (which are not supported by Docker at the moment).\n\n### Prerequisites\n\nTo have it up and running please execute the following steps:\n\n[Download and install Ollama](https:\u002F\u002Follama.com\u002Fdownload)\n[Download and install Docker](https:\u002F\u002Fwww.docker.com\u002Fproducts\u002Fdocker-desktop\u002F)\n\n\n> ### Setting Up Ollama on a Remote Host\n> \n> To connect to an external Ollama instance, set the environment variable: `OLLAMA_HOST=http:\u002F\u002Faddress:port`, e.g.:\n> ```bash\n> OLLAMA_HOST=http(s):\u002F\u002F127.0.0.1:5000\n> ```\n> \n> If you want to disable the local Ollama model, use env `DISABLE_LOCAL_OLLAMA=1`, e.g.\n> ```bash\n> DISABLE_LOCAL_OLLAMA=1 make install\n> ```\n> **Note**: When local Ollama is disabled, ensure the required model is downloaded on the external instance.  \n> \n> Currently, the `DISABLE_LOCAL_OLLAMA` variable cannot be used to disable Ollama in Docker. As a workaround, remove the `ollama` service from `docker-compose.yml` or `docker-compose.gpu.yml`.  \n>\n> Support for using the variable in Docker environments will be added in a future release.\n\n\n### Clone the Repository\n\nFirst, clone the repository and change current directory to it:\n\n```sh\ngit clone https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api.git\ncd text-extract-api\n```\n\n### Setup with `Makefile`\n\nBe default application create [virtual python env](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fvenv.html): `.venv`. You can disable this functionality on local setup by adding `DISABLE_VENV=1` before running script:\n\n```bash\nDISABLE_VENV=1 make install \n```\n\n```bash\nDISABLE_VENV=1 make run \n```\n\n### Manual setup\n\nConfigure environment variables:\n\n```bash\ncp .env.localhost.example .env.localhost\n```\n\nYou might want to just use the defaults - should be fine. After ENV variables are set, just execute:\n\n```bash\npython3 -m venv .venv\nsource .venv\u002Fbin\u002Factivate\npip install -e .\nchmod +x run.sh\nrun.sh\n```\n\nThis command will install all the dependencies - including Redis (via Docker, so it is not entirely docker free method of running `text-extract-api` anyways :)\n\n(MAC) - Dependencies\n```\nbrew update && brew install libmagic poppler pkg-config ghostscript ffmpeg automake autoconf\n```\n\n(Mac) - You need to startup the celery worker\n```\nsource .venv\u002Fbin\u002Factivate && celery -A text_extract_api.celery_app worker --loglevel=info --pool=solo\n```\n\nThen you're good to go with running some CLI commands like:\n\n```bash\npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-mri.pdf --ocr_cache --prompt_file=examples\u002Fexample-mri-remove-pii.txt\n```\n\n### Scaling the parallell processing\n\nTo have multiple tasks running at once - for concurrent processing please run the following command to start single worker process:\n\n```bash\ncelery -A text_extract_api.tasks worker --loglevel=info --pool=solo & # to scale by concurrent processing please run this line as many times as many concurrent processess you want to have running\n```\n\n\n## Join us on Discord\n\nIn case of any questions, help requests or just feedback - please [join us on Discord](https:\u002F\u002Fdiscord.gg\u002FNJzu47Ye3a)!\n\n\n## Text extract strategies\n\n### `easyocr`\n\nEasy OCR is available on Apache based license. It's general purpose OCR with support for more than 30 languages, probably with the best performance for English.\n\nEnabled by default. Please do use the `strategy=easyocr` CLI and URL parameters to use it.\n\n\n### `minicpm-v` \n\nMiniCPM-V is an Apache based licensed OCR strategy.\n\nThe usage of MiniCPM-o\u002FV model weights must strictly follow [MiniCPM Model License.md](https:\u002F\u002Fgithub.com\u002FOpenBMB\u002FMiniCPM\u002Fblob\u002Fmain\u002FMiniCPM%20Model%20License.md).\n\nThe models and weights of MiniCPM are completely free for academic research. After filling out a [\"questionnaire\"](https:\u002F\u002Fmodelbest.feishu.cn\u002Fshare\u002Fbase\u002Fform\u002FshrcnpV5ZT9EJ6xYjh3Kx0J6v8g) for registration, are also available for free commercial use.\n\nEnabled by default. Please do use the `strategy=minicpm_v` CLI and URL parameters to use it.\n\n| ⚠️ **Remember to pull the model in Ollama first**       |\n|---------------------------------------------------------|\n| You need to pull the model in Ollama - use the command: |\n| `python client\u002Fcli.py llm_pull --model minicpm-v`       |\n| Or, if you have Ollama locally: `ollama pull minicpm-v` |\n\n\n\n### `llama_vision` \n\nLLama 3.2 Vision Strategy is licensed on [Meta Community License Agreement](https:\u002F\u002Follama.com\u002Flibrary\u002Fllama3.2-vision\u002Fblobs\u002F0b4284c1f870). Works great for many languages, although due to the number of parameters (90b) this model is probably **the slowest** one.\n\nEnabled by default. Please do use the `strategy=llama_vision` CLI and URL parameters to use it. It's by the way the default strategy\n\n\n### `remote`\n\nSome OCR's - like [Marker, state of the art PDF OCR](https:\u002F\u002Fgithub.com\u002FVikParuchuri\u002Fmarker) - works really great for more than 50 languages, including great accuracy for Polish and other languages - let's say that are \"diffult\" to read for standard OCR.\n\nThe `marker-pdf` is however licensed on GPL3 license and **therefore it's not included** by default in this application (as we're bound to MIT). \n\nThe weights for the models are licensed cc-by-nc-sa-4.0, but I will waive that for any organization under $5M USD in gross revenue in the most recent 12-month period AND under $5M in lifetime VC\u002Fangel funding raised. You also must not be competitive with the Datalab API. If you want to remove the GPL license requirements (dual-license) and\u002For use the weights commercially over the revenue limit, check out the options here.\n\nTo have it up and running you can execute the following steps:\n\n```bash\nmkdir marker-distribution # this should be outside of the `text-extract-api` folder!\ncd marker-distribution\npip install marker-pdf\npip install -U uvicorn fastapi python-multipart\nmarker_server --port 8002\n```\n\nSet the Remote API Url:\n\n**Note: *** you might run `marker_server` on different port or server - then just make sure you export a proper env setting beffore starting off `text-extract-api` server:\n\n```bash\nexport REMOTE_API_URL=http:\u002F\u002Flocalhost:8002\u002Fmarker\u002Fupload\n```\n\n**Note: *** the URL might be also set via `\u002Fconfig\u002Fstrategies.yaml` file\n\nRun the `text-extract-api`:\n\n```bash\nmake run\n```\n\nPlease do use the `strategy=remote` CLI and URL parameters to use it. For example:\n\n```bash\ncurl -X POST -H \"Content-Type: multipart\u002Fform-data\" -F \"file=@examples\u002Fexample-mri.pdf\" -F \"strategy=remote\" -F \"ocr_cache=true\" -F \"prompt=\" -F \"model=\" \"http:\u002F\u002Flocalhost:8000\u002Focr\u002Fupload\" \n```\n\nWe are connecting to remote OCR via it's API to not share the same license (GPL3) by having it all linked on the source code level.\n\n## Getting started with Docker\n\n### Prerequisites\n\n- Docker\n- Docker Compose\n\n### Clone the Repository\n\n```sh\ngit clone https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api.git\ncd text-extract-api\n```\n\n### Using `Makefile`\nYou can use the `make install` and `make run` commands to set up the Docker environment for `text-extract-api`. You can find the manual steps required to do so described below.\n\n\n### Manual setup\n\nCreate `.env` file in the root directory and set the necessary environment variables. You can use the `.env.example` file as a template:\n\n```bash\n# defaults for docker instances\ncp .env.example .env\n```\n\nor \n\n```bash\n# defaults for local run\ncp .env.example.localhost .env\n```\n\nThen modify the variables inside the file:\n\n```bash\n#APP_ENV=production # sets the app into prod mode, otherwise dev mode with auto-reload on code changes\nREDIS_CACHE_URL=redis:\u002F\u002Flocalhost:6379\u002F1\nSTORAGE_PROFILE_PATH=.\u002Fstorage_profiles\nLLAMA_VISION_PROMPT=\"You are OCR. Convert image to markdown.\"\n\n# CLI settings\nOCR_URL=http:\u002F\u002Flocalhost:8000\u002Focr\u002Fupload\nOCR_UPLOAD_URL=http:\u002F\u002Flocalhost:8000\u002Focr\u002Fupload\nOCR_REQUEST_URL=http:\u002F\u002Flocalhost:8000\u002Focr\u002Frequest\nRESULT_URL=http:\u002F\u002Flocalhost:8000\u002Focr\u002Fresult\u002F\nCLEAR_CACHE_URL=http:\u002F\u002Flocalhost:8000\u002Focr\u002Fclear_cache\nLLM_PULL_API_URL=http:\u002F\u002Flocalhost:8000\u002Fllm_pull\nLLM_GENERATE_API_URL=http:\u002F\u002Flocalhost:8000\u002Fllm_generate\n\nCELERY_BROKER_URL=redis:\u002F\u002Flocalhost:6379\u002F0\nCELERY_RESULT_BACKEND=redis:\u002F\u002Flocalhost:6379\u002F0\nOLLAMA_HOST=http:\u002F\u002Flocalhost:11434\nAPP_ENV=development  # Default to development mode\n```\n\n\n**Note:** In order to properly save the output files, you might need to modify `storage_profiles\u002Fdefault.yaml` to change the default storage path according to the volumes path defined in the `docker-compose.yml`\n\n### Build and Run the Docker Containers\n\nBuild and run the Docker containers using Docker Compose:\n\n```bash\ndocker-compose up --build\n```\n\n... for GPU support run:\n\n```bash\ndocker-compose -f docker-compose.gpu.yml -p text-extract-api-gpu up --build\n```\n\n**Note:** While on Mac - Docker does not support Apple GPUs. In this case you might want to run the application natively without the Docker Compose please check [how to run it natively with GPU support](#getting-started)\n\n\nThis will start the following services:\n - **FastAPI App**: Runs the FastAPI application.\n - **Celery Worker**: Processes asynchronous OCR tasks.\n - **Redis**: Caches OCR results.\n - **Ollama**: Runs the Ollama model.\n\n## Cloud - paid edition\n\nIf the on-prem is too much hassle [ask us about the hosted\u002Fcloud edition](mailto:info@catchthetornado.com?subject=text-extract-api%20but%20hosted) of text-extract-api, we can setup it you, billed just for the usage.\n\n## CLI tool\n\n**Note**: While on Mac, you may need to create a virtual Python environment first:\n\n```bash\npython3 -m venv .venv\nsource .venv\u002Fbin\u002Factivate\n# now you've got access to `python` and `pip` within your virutal env.\npip install -e . # install main project requirements\n```\n\n\nThe project includes a CLI for interacting with the API. To make it work, first run:\n\n```bash\ncd client\npip install -e .\n```\n\n\n### Pull the LLama3.1 and LLama3.2-vision models\n\nYou might want to test out [different models supported by LLama](https:\u002F\u002Follama.com\u002Flibrary)\n\n```bash\npython client\u002Fcli.py llm_pull --model llama3.1\npython client\u002Fcli.py llm_pull --model llama3.2-vision\n```\n\nThese models are required for most features supported by `text-extract-api`.\n\n\n### Upload a File for OCR (converting to Markdown)\n\n```bash\npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-mri.pdf --ocr_cache\n```\n\nor alternatively\n\n```bash\npython client\u002Fcli.py ocr_request --file examples\u002Fexample-mri.pdf --ocr_cache\n```\n\nThe difference is just that the first call uses `ocr\u002Fupload` - multipart form data upload, and the second one is a request to `ocr\u002Frequest` sending the file via base64 encoded JSON property - probable a better suit for smaller files.\n\n\n### Upload a File for OCR (processing by LLM)\n\n**Important note:** To use LLM you must first run the **llm_pull** to get the specific model required by your requests.\n\nFor example, you must run:\n\n```bash\npython client\u002Fcli.py llm_pull --model llama3.1\npython client\u002Fcli.py llm_pull --model llama3.2-vision\n```\n\nand only after to run this specific prompt query:\n\n```bash\npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-mri.pdf --ocr_cache --prompt_file=examples\u002Fexample-mri-remove-pii.txt --language en\n```\n\n**Note:** The language argument is used for the OCR strategy to load the model weights for the selected language. You can specify multiple languages as a list: `en,de,pl` etc.\n\nThe `ocr` command can store the results using the `storage_profiles`:\n  - **storage_profile**: Used to save the result - the `default` profile (`.\u002Fstorage_profiles\u002Fdefault.yaml`) is used by default; if empty file is not saved\n  - **storage_filename**: Outputting filename - relative path of the `root_path` set in the storage profile - by default a relative path to `\u002Fstorage` folder; can use placeholders for dynamic formatting: `{file_name}`, `{file_extension}`, `{Y}`, `{mm}`, `{dd}` - for date formatting, `{HH}`, `{MM}`, `{SS}` - for time formatting\n\n\n### Upload a File for OCR (processing by LLM), store result on disk\n\n```bash\npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-mri.pdf --ocr_cache --prompt_file=examples\u002Fexample-mri-remove-pii.txt  --storage_filename \"invoices\u002F{Y}\u002F{file_name}-{Y}-{mm}-{dd}.md\"\n```\n\n### Get OCR Result by Task ID\n\n```bash\npython client\u002Fcli.py result --task_id {your_task_id_from_upload_step}\n```\n\n### List file results archived by `storage_profile`\n\n```bash\npython client\u002Fcli.py list_files \n```\n\nto use specific (in this case `google drive`) storage profile run:\n\n```bash\npython client\u002Fcli.py list_files  --storage_profile gdrive\n```\n\n### Load file result archived by `storage_profile`\n\n```bash\npython client\u002Fcli.py load_file --file_name \"invoices\u002F2024\u002Fexample-invoice-2024-10-31-16-33.md\"\n```\n\n### Delete file result archived by `storage_profile`\n\n```bash\npython client\u002Fcli.py delete_file --file_name \"invoices\u002F2024\u002Fexample-invoice-2024-10-31-16-33.md\" --storage_profile gdrive\n```\n\nor for default profile (local file system):\n\n```bash\npython client\u002Fcli.py delete_file --file_name \"invoices\u002F2024\u002Fexample-invoice-2024-10-31-16-33.md\" \n```\n\n### Clear OCR Cache\n\n```bash\npython client\u002Fcli.py clear_cache\n```\n\n### Test LLama\n\n```bash\npython llm_generate --prompt \"Your prompt here\"\n```\n\n## API Clients\n\nYou might want to use the dedicated API clients to use `text-extract-api`.\n\n### Typescript\n\nThere's a dedicated API client for Typescript - [text-extract-api-client](https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api-client) and the `npm` package by the same name:\n\n```bash\nnpm install text-extract-api-client\n```\n\nUsage:\n\n```js\nimport { ApiClient, OcrRequest } from 'text-extract-api-client';\nconst apiClient = new ApiClient('https:\u002F\u002Fapi.doctractor.com\u002F', 'doctractor', 'Aekie2ao');\nconst formData = new FormData();\nformData.append('file', fileInput.files[0]);\nformData.append('prompt', 'Convert file to JSON and return only JSON'); \u002F\u002F if not provided, no LLM transformation will gonna happen - just the OCR\nformData.append('strategy', 'llama_vision');\nformData.append('model', 'llama3.1');\nformData.append('ocr_cache', 'true');\n\napiClient.uploadFile(formData).then(response => {\n    console.log(response);\n});\n```\n\n## Endpoints\n\n### OCR Endpoint via File Upload \u002F multiform data\n- **URL**: \u002Focr\u002Fupload\n- **Method**: POST\n- **Parameters**:\n  - **file**: PDF, image or Office file to be processed.\n  - **strategy**: OCR strategy to use (`llama_vision`, `minicpm_v`, `remote` or `easyocr`). See the [available strategies](#text-extract-stratgies)\n  - **ocr_cache**: Whether to cache the OCR result (true or false).\n  - **prompt**: When provided, will be used for Ollama processing the OCR result\n  - **model**: When provided along with the prompt - this model will be used for LLM processing\n  - **storage_profile**: Used to save the result - the `default` profile (`.\u002Fstorage_profiles\u002Fdefault.yaml`) is used by default; if empty file is not saved\n  - **storage_filename**: Outputting filename - relative path of the `root_path` set in the storage profile - by default a relative path to `\u002Fstorage` folder; can use placeholders for dynamic formatting: `{file_name}`, `{file_extension}`, `{Y}`, `{mm}`, `{dd}` - for date formatting, `{HH}`, `{MM}`, `{SS}` - for time formatting\n  - **language**: One or many (`en` or `en,pl,de`) language codes for the OCR to load the language weights\n\nExample:\n\n```bash\ncurl -X POST -H \"Content-Type: multipart\u002Fform-data\" -F \"file=@examples\u002Fexample-mri.pdf\" -F \"strategy=easyocr\" -F \"ocr_cache=true\" -F \"prompt=\" -F \"model=\" \"http:\u002F\u002Flocalhost:8000\u002Focr\u002Fupload\" \n```\n\n### OCR Endpoint via JSON request\n- **URL**: \u002Focr\u002Frequest\n- **Method**: POST\n- **Parameters** (JSON body):\n  - **file**: Base64 encoded PDF file content.\n  - **strategy**: OCR strategy to use (`llama_vision`, `minicpm_v`, `remote` or `easyocr`). See the [available strategies](#text-extract-stratgies)\n  - **ocr_cache**: Whether to cache the OCR result (true or false).\n  - **prompt**: When provided, will be used for Ollama processing the OCR result.\n  - **model**: When provided along with the prompt - this model will be used for LLM processing.\n  - **storage_profile**: Used to save the result - the `default` profile (`\u002Fstorage_profiles\u002Fdefault.yaml`) is used by default; if empty file is not saved.\n  - **storage_filename**: Outputting filename - relative path of the `root_path` set in the storage profile - by default a relative path to `\u002Fstorage` folder; can use placeholders for dynamic formatting: `{file_name}`, `{file_extension}`, `{Y}`, `{mm}`, `{dd}` - for date formatting, `{HH}`, `{MM}`, `{SS}` - for time formatting.\n  - **language**: One or many (`en` or `en,pl,de`) language codes for the OCR to load the language weights\n\nExample:\n\n```bash\ncurl -X POST \"http:\u002F\u002Flocalhost:8000\u002Focr\u002Frequest\" -H \"Content-Type: application\u002Fjson\" -d '{\n  \"file\": \"\u003Cbase64-encoded-file-content>\",\n  \"strategy\": \"easyocr\",\n  \"ocr_cache\": true,\n  \"prompt\": \"\",\n  \"model\": \"llama3.1\",\n  \"storage_profile\": \"default\",\n  \"storage_filename\": \"example.md\"\n}'\n```\n\n### OCR Result Endpoint\n- **URL**: \u002Focr\u002Fresult\u002F{task_id}\n- **Method**: GET\n- **Parameters**:\n  - **task_id**: Task ID returned by the OCR endpoint.\n\nExample:\n\n```bash\ncurl -X GET \"http:\u002F\u002Flocalhost:8000\u002Focr\u002Fresult\u002F{task_id}\"\n```\n\n### Clear OCR Cache Endpoint\n - **URL**: \u002Focr\u002Fclear_cache\n - **Method**: POST\n\nExample:\n```bash\ncurl -X POST \"http:\u002F\u002Flocalhost:8000\u002Focr\u002Fclear_cache\"\n```\n\n\n### Ollama Pull Endpoint\n- **URL**: \u002Fllm\u002Fpull\n- **Method**: POST\n- **Parameters**:\n  - **model**: Pull the model you are to use first\n\nExample:\n\n```bash\ncurl -X POST \"http:\u002F\u002Flocalhost:8000\u002Fllm\u002Fpull\" -H \"Content-Type: application\u002Fjson\" -d '{\"model\": \"llama3.1\"}'\n```\n\n### Ollama Endpoint\n- **URL**: \u002Fllm\u002Fgenerate\n- **Method**: POST\n- **Parameters**:\n  - **prompt**: Prompt for the Ollama model.\n  - **model**: Model you like to query\n\nExample:\n\n```bash\ncurl -X POST \"http:\u002F\u002Flocalhost:8000\u002Fllm\u002Fgenerate\" -H \"Content-Type: application\u002Fjson\" -d '{\"prompt\": \"Your prompt here\", \"model\":\"llama3.1\"}'\n```\n\n### List storage files:\n \n- **URL:** \u002Fstorage\u002Flist\n- **Method:** GET\n- **Parameters**:\n  - **storage_profile**: Name of the storage profile to use for listing files (default: `default`).\n\n### Download storage file:\n \n- **URL:** \u002Fstorage\u002Fload\n- **Method:** GET\n- **Parameters**:\n  - **file_name**: File name to load from the storage\n  - **storage_profile**: Name of the storage profile to use for listing files (default: `default`).\n\n### Delete storage file:\n \n- **URL:** \u002Fstorage\u002Fdelete\n- **Method:** DELETE\n- **Parameters**:\n  - **file_name**: File name to load from the storage\n  - **storage_profile**: Name of the storage profile to use for listing files (default: `default`).\n\n\n## Storage profiles\n\nThe tool can automatically save the results using different storage strategies and storage profiles. Storage profiles are set in the `\u002Fstorage_profiles` by a yaml configuration files.\n\n### Local File System\n\n```yaml\nstrategy: local_filesystem\nsettings:\n  root_path: \u002Fstorage # The root path where the files will be stored - mount a proper folder in the docker file to match it\n  subfolder_names_format: \"\" # eg: by_months\u002F{Y}-{mm}\u002F\n  create_subfolders: true\n```\n\n### Google Drive\n\n```yaml\nstrategy: google_drive\nsettings:\n## how to enable GDrive API: https:\u002F\u002Fdevelopers.google.com\u002Fdrive\u002Fapi\u002Fquickstart\u002Fpython?hl=pl\n\n  service_account_file: \u002Fstorage\u002Fclient_secret_269403342997-290pbjjlb06nbof78sjaj7qrqeakp3t0.apps.googleusercontent.com.json\n  folder_id:\n```\n\nWhere the `service_account_file` is a `json` file with authorization credentials. Please read on how to enable Google Drive API and prepare this authorization file [here](https:\u002F\u002Fdevelopers.google.com\u002Fdrive\u002Fapi\u002Fquickstart\u002Fpython?hl=pl).\n\nNote: Service Account is different account that the one you're using for Google workspace (files will not be visible in the UI)\n\n### Amazon S3 - Cloud Object Storage\n\n```yaml\nstrategy: aws_s3\nsettings:\n  bucket_name: ${AWS_S3_BUCKET_NAME}\n  region: ${AWS_REGION}\n  access_key: ${AWS_ACCESS_KEY_ID}\n  secret_access_key: ${AWS_SECRET_ACCESS_KEY}\n```\n\n#### Requirements for AWS S3 Access Key\n\n1. **Access Key Ownership**  \n   The access key must belong to an IAM user or role with permissions for S3 operations.\n\n2. **IAM Policy Example**  \n   The IAM policy attached to the user or role must allow the necessary actions. Below is an example of a policy granting access to an S3 bucket:\n   ```json\n   {\n       \"Version\": \"2012-10-17\",\n       \"Statement\": [\n           {\n               \"Effect\": \"Allow\",\n               \"Action\": [\n                   \"s3:PutObject\",\n                   \"s3:GetObject\",\n                   \"s3:ListBucket\",\n                   \"s3:DeleteObject\"\n               ],\n               \"Resource\": [\n                   \"arn:aws:s3:::your-bucket-name\",\n                   \"arn:aws:s3:::your-bucket-name\u002F*\"\n               ]\n           }\n       ]\n   }\n   ```\n\nNext, populate the appropriate `.env` file (e.g., .env, .env.localhost) with the required AWS credentials:\n\n```bash\nAWS_ACCESS_KEY_ID=your-access-key-id\nAWS_SECRET_ACCESS_KEY=your-secret-access-key\nAWS_REGION=your-region\nAWS_S3_BUCKET_NAME=your-bucket-name\n```\n\n## License\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Contact\nIn case of any questions please contact us at: info@catchthetornado.com\n","# text-extract-api\n\n将任何图像、PDF 或 Office 文档以超高精度转换为 Markdown *文本* 或 JSON 结构化文档，包括表格数据、数字或数学公式。\n\n该 API 基于 FastAPI 构建，并使用 Celery 进行异步任务处理。Redis 用于缓存 OCR 结果。\n\n![hero doc extract](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FCatchTheTornado_text-extract-api_readme_c42a336c15e2.webp)\n\n## 特性：\n- **无云\u002F外部依赖**：您只需 PyTorch 基础的 OCR（EasyOCR）+ Ollama，通过 `docker-compose` 打包并配置好；所有数据均在您的开发\u002F服务器环境中处理，不会发送到外部。\n- **PDF\u002FOffice 转 Markdown**：采用多种 OCR 策略实现高精度转换，包括 [llama3.2-vision](https:\u002F\u002Fai.meta.com\u002Fblog\u002Fllama-3-2-connect-2024-vision-edge-mobile-devices\u002F)、[easyOCR](https:\u002F\u002Fgithub.com\u002FJaidedAI\u002FEasyOCR)、[minicpm-v](https:\u002F\u002Fgithub.com\u002FOpenBMB\u002FMiniCPM-o?tab=readme-ov-file#minicpm-v-26)，以及基于远程 URL 的策略，如 [marker-pdf](https:\u002F\u002Fgithub.com\u002FVikParuchuri\u002Fmarker)。\n- **PDF\u002FOffice 转 JSON**：利用 Ollama 支持的模型（例如 LLama 3.1）进行转换。\n- **LLM 改进 OCR 结果**：LLama 在修正 OCR 文本中的拼写和文本问题方面表现优异。\n- **去除 PII**：此工具可用于从文档中移除个人身份信息——请参阅 `examples`。\n- **分布式队列处理**：使用 [Celery](https:\u002F\u002Fdocs.celeryq.dev\u002Fen\u002Fstable\u002Fgetting-started\u002Fintroduction.html) 实现。\n- **缓存**：使用 Redis 缓存 OCR 结果，以便在 LLM 处理前快速访问。\n- **存储策略**：可切换的存储策略（Google Drive、本地文件系统等）。\n- **CLI 工具**：用于提交任务和处理结果。\n\n## 截图\n\n将 MRI 报告转换为 Markdown + JSON。\n\n```bash \npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-mri.pdf --prompt_file examples\u002Fexample-mri-2-json-prompt.txt\n```\n\n运行示例前，请先查看 [入门指南](#getting-started)。\n\n![将 MRI 报告转换为 Markdown](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FCatchTheTornado_text-extract-api_readme_08119ffbe35c.png)\n\n将发票转换为 JSON 并移除 PII：\n\n```bash \npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-invoice.pdf --prompt_file examples\u002Fexample-invoice-remove-pii.txt \n```\n\n运行示例前，请先查看 [入门指南](#getting-started)。\n\n![将发票转换为 JSON](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FCatchTheTornado_text-extract-api_readme_4d1dff2bd7e9.png)\n\n## 入门指南\n\n您可能希望直接在本地机器上运行该应用，用于开发目的，或者为了使用例如 Apple GPU（目前 Docker 尚不支持）。\n\n### 前置条件\n\n要使应用正常运行，请执行以下步骤：\n\n[下载并安装 Ollama](https:\u002F\u002Follama.com\u002Fdownload)\n[下载并安装 Docker](https:\u002F\u002Fwww.docker.com\u002Fproducts\u002Fdocker-desktop\u002F)\n\n\n> ### 在远程主机上设置 Ollama\n> \n> 若要连接到外部 Ollama 实例，请设置环境变量：`OLLAMA_HOST=http:\u002F\u002Faddress:port`，例如：\n> ```bash\n> OLLAMA_HOST=http(s):\u002F\u002F127.0.0.1:5000\n> ```\n> \n> 如果您想禁用本地 Ollama 模型，请使用环境变量 `DISABLE_LOCAL_OLLAMA=1`，例如：\n> ```bash\n> DISABLE_LOCAL_OLLAMA=1 make install\n> ```\n> **注意**：当本地 Ollama 被禁用时，请确保所需的模型已在外部实例上下载。  \n> \n> 目前，`DISABLE_LOCAL_OLLAMA` 变量无法用于在 Docker 中禁用 Ollama。作为替代方案，您可以从 `docker-compose.yml` 或 `docker-compose.gpu.yml` 中移除 `ollama` 服务。  \n>\n> 未来版本将支持在 Docker 环境中使用该变量。\n\n\n### 克隆仓库\n\n首先，克隆仓库并将当前目录切换到该目录：\n\n```sh\ngit clone https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api.git\ncd text-extract-api\n```\n\n### 使用 Makefile 设置\n\n默认情况下，应用程序会创建一个 [Python 虚拟环境](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fvenv.html)：`.venv`。您可以在本地设置中通过在运行脚本前添加 `DISABLE_VENV=1` 来禁用此功能：\n\n```bash\nDISABLE_VENV=1 make install \n```\n\n```bash\nDISABLE_VENV=1 make run \n```\n\n### 手动设置\n\n配置环境变量：\n\n```bash\ncp .env.localhost.example .env.localhost\n```\n\n您也可以直接使用默认值，通常足够了。设置完环境变量后，执行以下命令：\n\n```bash\npython3 -m venv .venv\nsource .venv\u002Fbin\u002Factivate\npip install -e .\nchmod +x run.sh\nrun.sh\n```\n\n此命令将安装所有依赖项——包括 Redis（通过 Docker），因此严格来说，这并不是完全无需 Docker 的运行方式 :)。\n\n(MAC) - 依赖项\n```\nbrew update && brew install libmagic poppler pkg-config ghostscript ffmpeg automake autoconf\n```\n\n(Mac) - 您需要启动 Celery 工作进程：\n```\nsource .venv\u002Fbin\u002Factivate && celery -A text_extract_api.celery_app worker --loglevel=info --pool=solo\n```\n\n之后，您就可以运行一些 CLI 命令，例如：\n\n```bash\npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-mri.pdf --ocr_cache --prompt_file=examples\u002Fexample-mri-remove-pii.txt\n```\n\n### 扩展并行处理能力\n\n若需同时运行多个任务以实现并发处理，请运行以下命令启动单个工作进程：\n\n```bash\ncelery -A text_extract_api.tasks worker --loglevel=info --pool=solo & # 若要扩展并发处理能力，请根据所需并发进程的数量重复执行此命令\n```\n\n\n## 加入我们的 Discord 社区\n\n如有任何疑问、求助或反馈，请 [加入我们的 Discord 社区](https:\u002F\u002Fdiscord.gg\u002FNJzu47Ye3a)！\n\n\n## 文本提取策略\n\n### `easyocr`\n\nEasy OCR 采用 Apache 许可证。它是一款通用 OCR 工具，支持 30 多种语言，尤其在英语识别方面表现优异。\n\n默认启用。请使用 CLI 和 URL 参数中的 `strategy=easyocr` 来调用它。\n\n### `minicpm-v` \n\nMiniCPM-V 是一种基于 Apache 许可证的 OCR 策略。\n\n必须严格按照 [MiniCPM 模型许可证.md](https:\u002F\u002Fgithub.com\u002FOpenBMB\u002FMiniCPM\u002Fblob\u002Fmain\u002FMiniCPM%20Model%20License.md) 使用 MiniCPM-o\u002FV 模型权重。\n\nMiniCPM 的模型和权重对学术研究完全免费。填写 [“问卷”](https:\u002F\u002Fmodelbest.feishu.cn\u002Fshare\u002Fbase\u002Fform\u002FshrcnpV5ZT9EJ6xYjh3Kx0J6v8g) 完成注册后，也可免费用于商业用途。\n\n默认启用。请使用 CLI 和 URL 参数中的 `strategy=minicpm_v` 来调用它。\n\n| ⚠️ **请务必先在 Ollama 中拉取模型**       |\n|---------------------------------------------------------|\n| 您需要在 Ollama 中拉取模型——使用以下命令： |\n| `python client\u002Fcli.py llm_pull --model minicpm-v`       |\n| 或者，如果您本地有 Ollama：`ollama pull minicpm-v` |\n\n### `llama_vision`\n\nLLama 3.2 Vision 策略根据 [Meta 社区许可协议](https:\u002F\u002Follama.com\u002Flibrary\u002Fllama3.2-vision\u002Fblobs\u002F0b4284c1f870) 授权。该模型支持多种语言，表现优异，但由于参数量高达 900 亿，因此可能是**最慢**的模型。\n\n默认已启用。请使用 `strategy=llama_vision` CLI 和 URL 参数来调用此模型。顺便一提，它也是默认策略。\n\n### `remote`\n\n一些 OCR 工具，例如 [Marker，最先进的 PDF OCR](https:\u002F\u002Fgithub.com\u002FVikParuchuri\u002Fmarker)，在超过 50 种语言上表现非常出色，包括对波兰语及其他通常较难识别的语言也有很高的准确度。\n\n然而，`marker-pdf` 采用 GPL3 许可证授权，**因此默认情况下并未包含在本应用中**（因为我们受 MIT 许可证约束）。\n\n这些模型的权重采用 CC-BY-NC-SA-4.0 许可证，但我将为以下组织免除该许可要求：最近 12 个月内总收入低于 500 万美元，且累计风险投资\u002F天使轮融资总额也低于 500 万美元。此外，您还不得与 Datalab API 形成竞争关系。如果您希望解除 GPL 许可证的要求（采用双重许可）或在收入超过上述限制的情况下商业使用这些权重，请查看此处的选项。\n\n要将其运行起来，您可以执行以下步骤：\n\n```bash\nmkdir marker-distribution # 此目录应位于 `text-extract-api` 文件夹之外！\ncd marker-distribution\npip install marker-pdf\npip install -U uvicorn fastapi python-multipart\nmarker_server --port 8002\n```\n\n设置远程 API 地址：\n\n**注意：*** 您可能在不同的端口或服务器上运行 `marker_server`，此时只需在启动 `text-extract-api` 服务器之前正确设置环境变量即可：\n\n```bash\nexport REMOTE_API_URL=http:\u002F\u002Flocalhost:8002\u002Fmarker\u002Fupload\n```\n\n**注意：*** 也可以通过 `\u002Fconfig\u002Fstrategies.yaml` 文件设置该 URL。\n\n运行 `text-extract-api`：\n\n```bash\nmake run\n```\n\n请使用 `strategy=remote` CLI 和 URL 参数来调用此功能。例如：\n\n```bash\ncurl -X POST -H \"Content-Type: multipart\u002Fform-data\" -F \"file=@examples\u002Fexample-mri.pdf\" -F \"strategy=remote\" -F \"ocr_cache=true\" -F \"prompt=\" -F \"model=\" \"http:\u002F\u002Flocalhost:8000\u002Focr\u002Fupload\"\n```\n\n我们通过远程 OCR 的 API 进行连接，以避免因源代码层面的直接集成而共享相同的 GPL3 许可证。\n\n## 使用 Docker 入门\n\n### 前置条件\n\n- Docker\n- Docker Compose\n\n### 克隆仓库\n\n```sh\ngit clone https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api.git\ncd text-extract-api\n```\n\n### 使用 Makefile\n\n您可以使用 `make install` 和 `make run` 命令来设置 `text-extract-api` 的 Docker 环境。下面列出了手动完成相同操作所需的步骤。\n\n### 手动设置\n\n在根目录下创建 `.env` 文件，并设置必要的环境变量。您可以以 `.env.example` 文件作为模板：\n\n```bash\n# Docker 实例的默认配置\ncp .env.example .env\n```\n\n或者\n\n```bash\n# 本地运行的默认配置\ncp .env.example.localhost .env\n```\n\n然后修改文件中的变量：\n\n```bash\n#APP_ENV=production # 将应用设置为生产模式，否则为开发模式并支持代码更改时自动重新加载\nREDIS_CACHE_URL=redis:\u002F\u002Flocalhost:6379\u002F1\nSTORAGE_PROFILE_PATH=.\u002Fstorage_profiles\nLLAMA_VISION_PROMPT=\"你是一名 OCR，将图像转换为 Markdown 格式。\"\n\n# CLI 设置\nOCR_URL=http:\u002F\u002Flocalhost:8000\u002Focr\u002Fupload\nOCR_UPLOAD_URL=http:\u002F\u002Flocalhost:8000\u002Focr\u002Fupload\nOCR_REQUEST_URL=http:\u002F\u002Flocalhost:8000\u002Focr\u002Frequest\nRESULT_URL=http:\u002F\u002Flocalhost:8000\u002Focr\u002Fresult\u002F\nCLEAR_CACHE_URL=http:\u002F\u002Flocalhost:8000\u002Focr\u002Fclear_cache\nLLM_PULL_API_URL=http:\u002F\u002Flocalhost:8000\u002Fllm_pull\nLLM_GENERATE_API_URL=http:\u002F\u002Flocalhost:8000\u002Fllm_generate\n\nCELERY_BROKER_URL=redis:\u002F\u002Flocalhost:6379\u002F0\nCELERY_RESULT_BACKEND=redis:\u002F\u002Flocalhost:6379\u002F0\nOLLAMA_HOST=http:\u002F\u002Flocalhost:11434\nAPP_ENV=development  # 默认为开发模式\n```\n\n\n**注意：** 为了正确保存输出文件，您可能需要修改 `storage_profiles\u002Fdefault.yaml`，将默认存储路径调整为与 `docker-compose.yml` 中定义的卷路径一致。\n\n### 构建并运行 Docker 容器\n\n使用 Docker Compose 构建并运行容器：\n\n```bash\ndocker-compose up --build\n```\n\n若需 GPU 支持，请运行：\n\n```bash\ndocker-compose -f docker-compose.gpu.yml -p text-extract-api-gpu up --build\n```\n\n**注意：** 在 Mac 上，Docker 不支持 Apple 的 GPU。在这种情况下，您可以尝试不使用 Docker Compose 而直接运行应用程序，请参阅[如何在本地运行并支持 GPU](#getting-started)。\n\n这将启动以下服务：\n- **FastAPI 应用程序**：运行 FastAPI 应用。\n- **Celery 工作进程**：处理异步 OCR 任务。\n- **Redis**：缓存 OCR 结果。\n- **Ollama**：运行 Ollama 模型。\n\n## 云端付费版\n\n如果本地部署过于繁琐，[请联系我们获取托管\u002F云版本](mailto:info@catchthetornado.com?subject=text-extract-api%20but%20hosted) 的 text-extract-api，我们可以为您搭建并按使用量计费。\n\n## CLI 工具\n\n**注意：** 在 Mac 上，您可能需要先创建一个虚拟 Python 环境：\n\n```bash\npython3 -m venv .venv\nsource .venv\u002Fbin\u002Factivate\n# 现在您可以在虚拟环境中使用 `python` 和 `pip`。\npip install -e . # 安装主项目所需依赖\n```\n\n\n该项目包含一个用于与 API 交互的 CLI。要使其正常工作，请先执行以下命令：\n\n```bash\ncd client\npip install -e .\n```\n\n\n### 下载 LLama3.1 和 LLama3.2-vision 模型\n\n您可以尝试测试 [LLama 支持的各种模型](https:\u002F\u002Follama.com\u002Flibrary)。\n\n```bash\npython client\u002Fcli.py llm_pull --model llama3.1\npython client\u002Fcli.py llm_pull --model llama3.2-vision\n```\n\n这些模型是 `text-extract-api` 支持大多数功能所必需的。\n\n### 上传文件进行 OCR（转换为 Markdown）\n\n```bash\npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-mri.pdf --ocr_cache\n```\n\n或者也可以使用：\n\n```bash\npython client\u002Fcli.py ocr_request --file examples\u002Fexample-mri.pdf --ocr_cache\n```\n\n两者的区别在于，前者使用 `ocr\u002Fupload` 接口，以多部分表单数据形式上传文件；而后者则通过发送 Base64 编码的 JSON 数据来请求 `ocr\u002Frequest` 接口，这种方式可能更适合较小的文件。\n\n### 上传文件进行 OCR 处理（由 LLM 处理）\n\n**重要提示：** 若要使用 LLM，您必须先运行 **llm_pull** 命令，以获取您的请求所需的特定模型。\n\n例如，您需要运行以下命令：\n\n```bash\npython client\u002Fcli.py llm_pull --model llama3.1\npython client\u002Fcli.py llm_pull --model llama3.2-vision\n```\n\n然后才能运行此特定的提示查询：\n\n```bash\npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-mri.pdf --ocr_cache --prompt_file=examples\u002Fexample-mri-remove-pii.txt --language en\n```\n\n**注意：** `language` 参数用于 OCR 策略，以加载所选语言的模型权重。您可以指定多个语言，用逗号分隔：`en,de,pl` 等。\n\n`ocr` 命令可以使用 `storage_profiles` 存储结果：\n  - **storage_profile**：用于保存结果；默认使用 `default` 配置文件（`.\u002Fstorage_profiles\u002Fdefault.yaml`），如果为空则不保存文件。\n  - **storage_filename**：输出文件名——基于存储配置文件中设置的 `root_path` 的相对路径，默认为 `\u002Fstorage` 文件夹下的相对路径；支持动态格式化占位符：`{file_name}`、`{file_extension}`、`{Y}`、`{mm}`、`{dd}`——用于日期格式化，`{HH}`、`{MM}`、`{SS}`——用于时间格式化。\n\n### 上传文件进行 OCR 处理（由 LLM 处理），并将结果存储到磁盘\n\n```bash\npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-mri.pdf --ocr_cache --prompt_file=examples\u002Fexample-mri-remove-pii.txt  --storage_filename \"invoices\u002F{Y}\u002F{file_name}-{Y}-{mm}-{dd}.md\"\n```\n\n### 根据任务 ID 获取 OCR 结果\n\n```bash\npython client\u002Fcli.py result --task_id {your_task_id_from_upload_step}\n```\n\n### 列出按 `storage_profile` 归档的文件结果\n\n```bash\npython client\u002Fcli.py list_files \n```\n\n若要使用特定的存储配置文件（例如 Google Drive），请运行：\n\n```bash\npython client\u002Fcli.py list_files  --storage_profile gdrive\n```\n\n### 加载按 `storage_profile` 归档的文件结果\n\n```bash\npython client\u002Fcli.py load_file --file_name \"invoices\u002F2024\u002Fexample-invoice-2024-10-31-16-33.md\"\n```\n\n### 删除按 `storage_profile` 归档的文件结果\n\n```bash\npython client\u002Fcli.py delete_file --file_name \"invoices\u002F2024\u002Fexample-invoice-2024-10-31-16-33.md\" --storage_profile gdrive\n```\n\n或对于默认配置文件（本地文件系统）：\n\n```bash\npython client\u002Fcli.py delete_file --file_name \"invoices\u002F2024\u002Fexample-invoice-2024-10-31-16-33.md\" \n```\n\n### 清除 OCR 缓存\n\n```bash\npython client\u002Fcli.py clear_cache\n```\n\n### 测试 LLama\n\n```bash\npython llm_generate --prompt \"Your prompt here\"\n```\n\n## API 客户端\n\n您可能希望使用专用的 API 客户端来使用 `text-extract-api`。\n\n### Typescript\n\n有一个专门针对 Typescript 的 API 客户端——[text-extract-api-client](https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api-client)，以及同名的 npm 包：\n\n```bash\nnpm install text-extract-api-client\n```\n\n使用方法：\n\n```js\nimport { ApiClient, OcrRequest } from 'text-extract-api-client';\nconst apiClient = new ApiClient('https:\u002F\u002Fapi.doctractor.com\u002F', 'doctractor', 'Aekie2ao');\nconst formData = new FormData();\nformData.append('file', fileInput.files[0]);\nformData.append('prompt', '将文件转换为 JSON 并仅返回 JSON'); \u002F\u002F 如果未提供，则不会进行 LLM 转换，仅执行 OCR\nformData.append('strategy', 'llama_vision');\nformData.append('model', 'llama3.1');\nformData.append('ocr_cache', 'true');\n\napiClient.uploadFile(formData).then(response => {\n    console.log(response);\n});\n```\n\n## 端点\n\n### 通过文件上传的 OCR 端点 \u002F 多部分数据\n- **URL**: \u002Focr\u002Fupload\n- **方法**: POST\n- **参数**:\n  - **file**: 待处理的 PDF、图像或 Office 文件。\n  - **strategy**: 要使用的 OCR 策略（`llama_vision`、`minicpm_v`、`remote` 或 `easyocr`）。请参阅 [可用策略](#text-extract-stratgies)。\n  - **ocr_cache**: 是否缓存 OCR 结果（`true` 或 `false`）。\n  - **prompt**: 如果提供，则用于 Ollama 处理 OCR 结果。\n  - **model**: 与 prompt 一起提供时，该模型将用于 LLM 处理。\n  - **storage_profile**: 用于保存结果；默认使用 `default` 配置文件（`.\u002Fstorage_profiles\u002Fdefault.yaml`），如果为空则不保存文件。\n  - **storage_filename**: 输出文件名——基于存储配置文件中设置的 `root_path` 的相对路径，默认为 `\u002Fstorage` 文件夹下的相对路径；支持动态格式化占位符：`{file_name}`、`{file_extension}`、`{Y}`、`{mm}`、`{dd}`——用于日期格式化，`{HH}`、`{MM}`、`{SS}`——用于时间格式化。\n  - **language**: OCR 用于加载语言权重的一个或多个语言代码（如 `en` 或 `en,pl,de`）。\n\n示例：\n\n```bash\ncurl -X POST -H \"Content-Type: multipart\u002Fform-data\" -F \"file=@examples\u002Fexample-mri.pdf\" -F \"strategy=easyocr\" -F \"ocr_cache=true\" -F \"prompt=\" -F \"model=\" \"http:\u002F\u002Flocalhost:8000\u002Focr\u002Fupload\" \n```\n\n### 通过 JSON 请求的 OCR 端点\n- **URL**: \u002Focr\u002Frequest\n- **方法**: POST\n- **参数**（JSON 主体）：\n  - **file**: Base64 编码的 PDF 文件内容。\n  - **strategy**: 要使用的 OCR 策略（`llama_vision`、`minicpm_v`、`remote` 或 `easyocr`）。请参阅 [可用策略](#text-extract-stratgies)。\n  - **ocr_cache**: 是否缓存 OCR 结果（`true` 或 `false`）。\n  - **prompt**: 如果提供，则用于 Ollama 处理 OCR 结果。\n  - **model**: 与 prompt 一起提供时，该模型将用于 LLM 处理。\n  - **storage_profile**: 用于保存结果；默认使用 `default` 配置文件（`\u002Fstorage_profiles\u002Fdefault.yaml`），如果为空则不保存文件。\n  - **storage_filename**: 输出文件名——基于存储配置文件中设置的 `root_path` 的相对路径，默认为 `\u002Fstorage` 文件夹下的相对路径；支持动态格式化占位符：`{file_name}`、`{file_extension}`、`{Y}`、`{mm}`、`{dd}`——用于日期格式化，`{HH}`、`{MM}`、`{SS}`——用于时间格式化。\n  - **language**: OCR 用于加载语言权重的一个或多个语言代码（如 `en` 或 `en,pl,de`）。\n\n示例：\n\n```bash\ncurl -X POST \"http:\u002F\u002Flocalhost:8000\u002Focr\u002Frequest\" -H \"Content-Type: application\u002Fjson\" -d '{\n  \"file\": \"\u003Cbase64-encoded-file-content>\",\n  \"strategy\": \"easyocr\",\n  \"ocr_cache\": true,\n  \"prompt\": \"\",\n  \"model\": \"llama3.1\",\n  \"storage_profile\": \"default\",\n  \"storage_filename\": \"example.md\"\n}'\n```\n\n### OCR 结果端点\n- **URL**: \u002Focr\u002Fresult\u002F{task_id}\n- **方法**: GET\n- **参数**：\n  - **task_id**: OCR 端点返回的任务 ID。\n\n示例：\n\n```bash\ncurl -X GET \"http:\u002F\u002Flocalhost:8000\u002Focr\u002Fresult\u002F{task_id}\"\n```\n\n### 清除 OCR 缓存端点\n- **URL**: \u002Focr\u002Fclear_cache\n- **方法**: POST\n\n示例：\n```bash\ncurl -X POST \"http:\u002F\u002Flocalhost:8000\u002Focr\u002Fclear_cache\"\n```\n\n### Ollama 终端点\n- **URL**: \u002Fllm\u002Fgenerate\n- **方法**: POST\n- **参数**:\n  - **prompt**: 用于 Ollama 模型的提示。\n  - **model**: 要查询的模型名称。\n\n示例：\n\n```bash\ncurl -X POST \"http:\u002F\u002Flocalhost:8000\u002Fllm\u002Fgenerate\" -H \"Content-Type: application\u002Fjson\" -d '{\"prompt\": \"您的提示在此\", \"model\":\"llama3.1\"}'\n```\n\n### 列出存储文件：\n\n- **URL**: \u002Fstorage\u002Flist\n- **方法**: GET\n- **参数**:\n  - **storage_profile**: 用于列出文件的存储配置文件名称（默认值为 `default`）。\n\n### 下载存储文件：\n\n- **URL**: \u002Fstorage\u002Fload\n- **方法**: GET\n- **参数**:\n  - **file_name**: 要从存储中加载的文件名。\n  - **storage_profile**: 用于列出文件的存储配置文件名称（默认值为 `default`）。\n\n### 删除存储文件：\n\n- **URL**: \u002Fstorage\u002Fdelete\n- **方法**: DELETE\n- **参数**:\n  - **file_name**: 要从存储中删除的文件名。\n  - **storage_profile**: 用于列出文件的存储配置文件名称（默认值为 `default`）。\n\n## 存储配置文件\n\n该工具可以使用不同的存储策略和存储配置文件自动保存结果。存储配置文件通过 YAML 配置文件在 `\u002Fstorage_profiles` 中进行设置。\n\n### 本地文件系统\n\n```yaml\nstrategy: local_filesystem\nsettings:\n  root_path: \u002Fstorage # 文件将被存储的根路径 - 在 Docker 文件中挂载一个合适的文件夹以匹配此路径\n  subfolder_names_format: \"\" # 例如：by_months\u002F{Y}-{mm}\u002F\n  create_subfolders: true\n```\n\n### Google Drive\n\n```yaml\nstrategy: google_drive\nsettings:\n## 如何启用 GDrive API：https:\u002F\u002Fdevelopers.google.com\u002Fdrive\u002Fapi\u002Fquickstart\u002Fpython?hl=pl\n\n  service_account_file: \u002Fstorage\u002Fclient_secret_269403342997-290pbjjlb06nbof78sjaj7qrqeakp3t0.apps.googleusercontent.com.json\n  folder_id:\n```\n\n其中，`service_account_file` 是包含授权凭据的 JSON 文件。请参阅 [此处](https:\u002F\u002Fdevelopers.google.com\u002Fdrive\u002Fapi\u002Fquickstart\u002Fpython?hl=pl) 了解如何启用 Google Drive API 并准备此授权文件。\n\n注意：服务账户与您用于 Google Workspace 的账户不同（文件不会在 UI 中可见）。\n\n### Amazon S3 - 云对象存储\n\n```yaml\nstrategy: aws_s3\nsettings:\n  bucket_name: ${AWS_S3_BUCKET_NAME}\n  region: ${AWS_REGION}\n  access_key: ${AWS_ACCESS_KEY_ID}\n  secret_access_key: ${AWS_SECRET_ACCESS_KEY}\n```\n\n#### AWS S3 访问密钥的要求\n\n1. **访问密钥的所有权**  \n   访问密钥必须属于具有 S3 操作权限的 IAM 用户或角色。\n\n2. **IAM 策略示例**  \n   附加到用户或角色的 IAM 策略必须允许必要的操作。以下是一个授予 S3 存储桶访问权限的策略示例：\n   ```json\n   {\n       \"Version\": \"2012-10-17\",\n       \"Statement\": [\n           {\n               \"Effect\": \"Allow\",\n               \"Action\": [\n                   \"s3:PutObject\",\n                   \"s3:GetObject\",\n                   \"s3:ListBucket\",\n                   \"s3:DeleteObject\"\n               ],\n               \"Resource\": [\n                   \"arn:aws:s3:::your-bucket-name\",\n                   \"arn:aws:s3:::your-bucket-name\u002F*\"\n               ]\n           }\n       ]\n   }\n   ```\n\n接下来，请在相应的 `.env` 文件（例如 .env、.env.localhost）中填写所需的 AWS 凭证：\n\n```bash\nAWS_ACCESS_KEY_ID=您的访问密钥 ID\nAWS_SECRET_ACCESS_KEY=您的秘密访问密钥\nAWS_REGION=您的区域\nAWS_S3_BUCKET_NAME=您的存储桶名称\n```\n\n## 许可证\n本项目采用 MIT 许可证授权。详情请参阅 [LICENSE](LICENSE) 文件。\n\n## 联系方式\n如有任何问题，请联系我们：info@catchthetornado.com","# text-extract-api 快速上手指南\n\n`text-extract-api` 是一个基于 FastAPI 和 Celery 构建的开源工具，能够将图片、PDF 或 Office 文档高精度地转换为 Markdown 文本或结构化 JSON 数据。它支持表格、数字和数学公式的提取，并利用本地运行的 Ollama (LLM) 优化 OCR 结果及去除敏感信息 (PII)，所有数据处理均在本地完成，无需上传云端。\n\n## 环境准备\n\n### 系统要求\n- **操作系统**: Linux, macOS, Windows (需 WSL2)\n- **硬件**: \n  - 常规运行：标准 CPU\n  - 高性能\u002F加速：推荐 NVIDIA GPU 或 Apple Silicon (M1\u002FM2\u002FM3)\n- **内存**: 建议 8GB 以上（运行大模型如 Llama 3.2 Vision 需更多内存）\n\n### 前置依赖\n在开始之前，请确保安装以下软件：\n\n1. **Docker & Docker Compose** (推荐方式)\n   - [Docker 官网下载](https:\u002F\u002Fwww.docker.com\u002Fproducts\u002Fdocker-desktop\u002F)\n   \n2. **Ollama** (用于运行本地大模型)\n   - [Ollama 官网下载](https:\u002F\u002Follama.com\u002Fdownload)\n   - *国内用户提示*: 如果下载模型缓慢，可配置 `OLLAMA_HOST` 指向国内部署的 Ollama 服务，或使用代理加速。\n\n3. **基础开发工具** (仅针对非 Docker 原生运行模式，macOS 用户必装)\n   ```bash\n   brew update && brew install libmagic poppler pkg-config ghostscript ffmpeg automake autoconf\n   ```\n\n## 安装步骤\n\n本项目推荐使用 **Docker** 进行部署，以最快速度启动所有依赖服务（包括 Redis, Celery, Ollama）。\n\n### 方法一：使用 Docker Compose (推荐)\n\n1. **克隆仓库**\n   ```sh\n   git clone https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api.git\n   cd text-extract-api\n   ```\n\n2. **配置环境变量**\n   复制示例配置文件：\n   ```bash\n   cp .env.example .env\n   ```\n   *注：通常默认配置即可直接使用。如需连接外部 Ollama，请在 `.env` 中设置 `OLLAMA_HOST=http:\u002F\u002Fyour-ip:11434`。*\n\n3. **启动服务**\n   - **普通启动** (CPU 模式):\n     ```bash\n     docker-compose up --build\n     ```\n   - **GPU 加速启动** (需 NVIDIA GPU):\n     ```bash\n     docker-compose -f docker-compose.gpu.yml -p text-extract-api-gpu up --build\n     ```\n   *注意：macOS 用户由于 Docker 不支持调用 Apple GPU，建议使用下方的“方法二”进行原生安装以获得最佳性能。*\n\n### 方法二：本地原生安装 (适合 macOS 或开发者调试)\n\n1. **克隆仓库**\n   ```sh\n   git clone https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api.git\n   cd text-extract-api\n   ```\n\n2. **创建虚拟环境并安装依赖**\n   ```bash\n   python3 -m venv .venv\n   source .venv\u002Fbin\u002Factivate\n   pip install -e .\n   ```\n\n3. **启动 Redis**\n   该工具依赖 Redis 进行缓存，请确保本地已安装并运行 Redis，或通过 Docker 单独启动：\n   ```bash\n   docker run -d -p 6379:6379 redis\n   ```\n\n4. **启动 Celery Worker** (macOS 必需步骤)\n   ```bash\n   source .venv\u002Fbin\u002Factivate && celery -A text_extract_api.celery_app worker --loglevel=info --pool=solo\n   ```\n   *建议在另一个终端窗口运行此命令，保持后台运行。*\n\n5. **启动主应用**\n   ```bash\n   chmod +x run.sh\n   .\u002Frun.sh\n   ```\n\n6. **拉取必要的 AI 模型**\n   在使用前，需通过 Ollama 拉取默认策略所需的模型（例如 MiniCPM-V 或 Llama）：\n   ```bash\n   ollama pull minicpm-v\n   # 或者\n   ollama pull llama3.2-vision\n   ```\n\n## 基本使用\n\n安装完成后，你可以使用自带的 CLI 工具或 HTTP API 进行文档转换。\n\n### 1. 使用 CLI 工具转换 PDF 为 Markdown\n\n将示例中的 MRI 报告转换为 Markdown 格式：\n\n```bash\npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-mri.pdf --ocr_cache\n```\n\n### 2. 使用 CLI 工具转换发票为 JSON 并去除敏感信息 (PII)\n\n利用 LLM 能力提取结构化数据并自动抹去个人隐私信息：\n\n```bash\npython client\u002Fcli.py ocr_upload --file examples\u002Fexample-invoice.pdf --prompt_file examples\u002Fexample-invoice-remove-pii.txt\n```\n\n### 3. 指定 OCR 策略\n\n你可以通过 `--strategy` 参数选择不同的识别引擎：\n\n- **EasyOCR** (默认，速度快，适合英文):\n  ```bash\n  python client\u002Fcli.py ocr_upload --file example.pdf --strategy=easyocr\n  ```\n- **MiniCPM-V** (适合多语言，需先 `ollama pull minicpm-v`):\n  ```bash\n  python client\u002Fcli.py ocr_upload --file example.pdf --strategy=minicpm_v\n  ```\n- **Llama 3.2 Vision** (精度最高但速度较慢，需先 `ollama pull llama3.2-vision`):\n  ```bash\n  python client\u002Fcli.py ocr_upload --file example.pdf --strategy=llama_vision\n  ```\n\n### 4. 直接调用 HTTP API\n\n如果你更喜欢直接发送 HTTP 请求：\n\n```bash\ncurl -X POST -H \"Content-Type: multipart\u002Fform-data\" \\\n  -F \"file=@examples\u002Fexample-mri.pdf\" \\\n  -F \"strategy=llama_vision\" \\\n  -F \"ocr_cache=true\" \\\n  http:\u002F\u002Flocalhost:8000\u002Focr\u002Fupload\n```\n\n服务默认运行在 `http:\u002F\u002Flocalhost:8000`。转换任务提交后，可通过返回的任务 ID 查询结果。","某医疗数据研究团队需要批量处理数千份历史纸质病历的扫描 PDF，将其转化为可分析的结构化数据，同时必须严格去除患者姓名、身份证号等隐私信息以符合合规要求。\n\n### 没有 text-extract-api 时\n- **人工成本高昂**：依赖人工逐页录入或校对 OCR 结果，面对手写体医生处方和复杂医学公式时错误率极高，耗时数周。\n- **隐私泄露风险**：缺乏自动化的敏感信息（PII）清洗机制，研究人员需手动排查每份文档，极易因疏忽导致患者隐私泄露。\n- **数据格式混乱**：提取出的文本多为非结构化字符串，表格行列错位严重，后续导入数据库或进行统计分析前需编写大量复杂的清洗代码。\n- **云端合规顾虑**：使用公共云 OCR 服务意味着将敏感医疗数据上传至第三方服务器，违反医院内部的数据不出域安全政策。\n\n### 使用 text-extract-api 后\n- **自动化高精度提取**：利用集成的 Llama3.2-Vision 和 EasyOCR 模型，自动识别并修正手写体及数学公式，将病历精准转换为 Markdown 或 JSON，效率提升数十倍。\n- **内置隐私脱敏**：调用 Ollama 支持的本地大模型自动识别并移除姓名、证件号等 PII 信息，从源头确保数据合规，无需人工二次审查。\n- **结构化直接可用**：直接输出带有完整表格结构和层级关系的 JSON 数据，研究团队可立即将其载入分析管道，省去了繁琐的后处理步骤。\n- **本地私有化部署**：基于 Docker 和 Ollama 在本地服务器运行，所有数据处理均在内部网络完成，彻底杜绝了数据外传的安全隐患。\n\ntext-extract-api 通过“本地化智能 OCR+LLM 纠错脱敏”的一站式方案，让敏感文档的数字化处理既高效精准又安全合规。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FCatchTheTornado_text-extract-api_c42a336c.webp","CatchTheTornado","Catch The Tornado","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FCatchTheTornado_2c356de9.jpg","eCommerce Startup Studio",null,"info@catchthetornado.com","https:\u002F\u002Fcttndo.com","https:\u002F\u002Fgithub.com\u002FCatchTheTornado",[82,86,90,94],{"name":83,"color":84,"percentage":85},"Python","#3572A5",87.6,{"name":87,"color":88,"percentage":89},"Makefile","#427819",5.5,{"name":91,"color":92,"percentage":93},"Shell","#89e051",4,{"name":95,"color":96,"percentage":97},"Dockerfile","#384d54",2.9,3081,268,"2026-04-09T07:54:05","MIT","Linux, macOS","非必需。支持 NVIDIA GPU (通过 docker-compose.gpu.yml)，Mac Apple Silicon 需原生运行 (Docker 不支持)。具体显存和 CUDA 版本未说明，但运行 Llama 3.2 Vision (90B) 等大模型通常需要高显存。","未说明 (建议 16GB+ 以运行大型视觉模型)",{"notes":106,"python":107,"dependencies":108},"1. 核心依赖 Ollama 运行本地大模型 (如 Llama 3.2, MiniCPM-V)，需预先安装 Ollama 并拉取对应模型。2. 必须安装 Docker 和 Docker Compose 以运行 Redis 和部分服务；若需完全原生运行或在使用 Mac Apple GPU 时，可跳过 Docker 但需手动启动 Celery Worker。3. macOS 用户需通过 Homebrew 安装 libmagic, poppler, ghostscript 等系统库。4. 支持多种 OCR 策略：默认包含 EasyOCR, MiniCPM-V, Llama Vision；Marker-PDF 因 GPL 许可需单独部署远程服务。5. 首次运行需下载较大的 AI 模型文件。","3.x (通过 venv 管理，具体小版本未说明)",[109,110,111,112,113,114,115,116,117,118],"FastAPI","Celery","Redis","PyTorch","EasyOCR","Ollama","Llama 3.2 Vision","MiniCPM-V","libmagic","poppler",[16,35,52,14,15],[121,122,123,124,125,126,127,128,129],"api","extract","json","llm","pdf","anonymization","ocr","ocr-python","pii","2026-03-27T02:49:30.150509","2026-04-11T03:24:34.650679",[133,138,143,148,153,158],{"id":134,"question_zh":135,"answer_zh":136,"source_url":137},28799,"为什么使用 Docker 启动服务时 GPU 没有被调用？","首先请检查 `docker-compose.gpu.yml` 的配置文件是否正确。其次，确保您的 Docker 引擎已正确安装并支持 GPU 功能（NVIDIA 驱动及 Container Toolkit）。您可以参考官方文档进行验证：https:\u002F\u002Fdocs.docker.com\u002Fdesktop\u002Ffeatures\u002Fgpu\u002F。如果单独运行 `ollama run` 能使用 GPU 但 Docker 不能，通常是因为 Docker 容器未正确挂载 GPU 资源或配置有误。","https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fissues\u002F58",{"id":139,"question_zh":140,"answer_zh":141,"source_url":142},28800,"运行时报错 'Cannot re-initialize CUDA in forked subprocess' 如何解决？","这是因为在使用多进程（multiprocessing）与 CUDA 时，默认的 'fork' 启动方法不兼容。您需要在代码中显式设置启动方法为 'spawn'。请在 `app\u002Fcelery_config.py` 或主程序入口添加以下代码：\n\nimport multiprocessing\nmultiprocessing.set_start_method(\"spawn\", force=True)\n\n这将强制使用 'spawn' 方法初始化进程，从而解决 CUDA 重新初始化的问题。","https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fissues\u002F6",{"id":144,"question_zh":145,"answer_zh":146,"source_url":147},28801,"处理大文件时 OCR 速度极慢甚至卡住，如何排查原因？","1. 尝试更改处理策略，在 CLI 参数中添加 `--strategy marker` 或在 Web 请求 URL 中添加 `&strategy=marker`，这通常能显著提升性能。\n2. 检查服务器端或 Docker 控制台日志，确认是否只使用了单张 GPU（某些模型如 mllama 暂时不支持并行请求）。\n3. 观察日志中是否有 'mllama doesn't support parallel requests yet' 等警告，这表明瓶颈在于模型本身的并发限制而非硬件故障。","https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fissues\u002F75",{"id":149,"question_zh":150,"answer_zh":151,"source_url":152},28802,"如何让 LLM 严格遵循指定的 JSON 字段输出，避免产生幻觉或多余字段？","有两种主要方法：\n1. 在提示词（Prompt）中明确要求：例如添加 \"Return only JSON format\"（仅返回 JSON 格式）。\n2. 利用 Ollama API 的原生支持：在调用时传递 `format` 参数设置为 `json`。项目维护者建议可以在 API 和 CLI 中增加 `output_format` 代理参数，以便在使用 prompt 时直接指定输出格式为 JSON，从而强制模型遵守结构。","https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fissues\u002F33",{"id":154,"question_zh":155,"answer_zh":156,"source_url":157},28803,"我想使用本地已运行的 Ollama 实例，而不是 Docker Compose 启动的实例，该如何配置？","如果您已经在本地主机（localhost:11434）运行了 Ollama，可以通过修改环境变量或配置文件，将服务的 Ollama 连接地址指向本地实例，而不是 Docker 内部的服务名。通常需要设置 `OLLAMA_HOST` 环境变量为 `http:\u002F\u002Fhost.docker.internal:11434`（在 Docker 容器中访问宿主机）或者直接指向本地 IP，具体取决于您的部署方式，以避免重复启动 Ollama 容器并提高资源效率。","https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fissues\u002F23",{"id":159,"question_zh":160,"answer_zh":161,"source_url":142},28804,"如何处理包含表格的 PDF 文件提取？","在使用 CLI 工具时，可以通过 `--prompt_file` 参数指定专门的提示词文件来处理复杂结构。例如，运行命令：`python client\u002Fcli.py ocr --file test.pdf --prompt_file .\u002Fexamples\u002Fparse-table.txt`。确保您的提示词文件中包含了针对表格解析的具体指令，以引导 LLM 正确识别和提取表格数据。",[163,168,173],{"id":164,"version":165,"summary_zh":166,"released_at":167},197654,"v0.3.0","## 变更内容\n* 修复 - 重复的 unify、Docker 中缺少 libglib，以及由 @choinek 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F97 中实现的终止 Cellery 进程 PID 操作\n* [功能] @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F103 中添加了 Minicpm-v 支持\n* 功能\u002F98 通用文本对象 - @choinek 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F105 中实现\n* 功能\u002F107 不再强制要求模型 - @choinek 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F108 中实现\n* [功能] #92 远程策略 + `marker-pdf` 示例 - @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F106 中实现\n* 杂项：在 Makefile 中将 clean-cache 重命名为 clear-cache - @nick-lai 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F111 中实现\n* 修复轻微拼写问题 - @janoberst 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F110 中实现\n* 功能\u002F54 添加 Docling 支持 - @btrojan-official 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F115 中实现\n* 功能\u002F54 添加 Docling 支持 - @choinek 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F113 中实现\n\n## 新贡献者\n* @nick-lai 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F111 中完成了首次贡献\n* @janoberst 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F110 中完成了首次贡献\n* @btrojan-official 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F115 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fcompare\u002Fv0.2.0...v0.3.0","2025-04-29T01:58:02",{"id":169,"version":170,"summary_zh":171,"released_at":172},197655,"v0.2.0","## 变更内容\n\n1. 由于许可限制移除了 Marker，使我们能够将许可证更改为 MIT 许可；Marker 将被迁移到一个外部代码库。\n2. 添加了 EasyOCR 支持。\n3. 许可证更新为 MIT，以符合我们的目标。\n\n---\n\n目前我们支持：\n- PDF 文件\n- 图像文件\n- EasyOCR\n- LLama 3.2-Vision OCR\n- 所有 Ollama 支持的模型用于第二阶段的文本提取\n- S3 存储、Google Drive 存储以及本地文件系统存储\n\n更多功能即将加入，请关注我们在 GitHub 上的项目！\n\n---\n提交记录：\n* feat: 添加 EasyOCR，移除 Tesseract 和 Marker，许可证更改为 MIT，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F91 中完成。\n* 更新 README.md，由 @justinlevi 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F90 中完成。\n\n## 新贡献者\n* @justinlevi 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F90 中完成了首次贡献。\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fcompare\u002Fv0.1.0...v0.2.0","2025-01-18T07:33:07",{"id":174,"version":175,"summary_zh":176,"released_at":177},197656,"v0.1.0","## 变更内容\n\n这是初始版本。目前我们全面支持：\n- PDF 文件\n- 图像文件\n- Marker OCR\n- LLama 3.2-Vision OCR\n- 所有 Ollama 支持的模型用于第二阶段文本提取\n- S3 存储、Google Drive 存储、本地文件系统存储\n\n更多功能将很快加入——请关注我们在 GitHub 上的动态！\n\n\n完整变更日志：\n\n* 修复 README.md 中的拼写错误，由 @martwozniak 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F7 中完成\n* 修复 #6 的 CUDA 相关问题——进程启动问题，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F9 中完成\n* 修复 #11、#12 和 #13 的问题，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F17 中完成\n* 【文档】介绍如何在不使用 Docker 的情况下本地运行应用，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F25 中完成\n* 功能：#8 存储策略——本地文件系统 + Google Drive，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F10 中完成\n* 【功能】#30 —— 新的 `\u002Focr\u002Frequest` 端点提案及文档，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F31 中完成\n* 更新 README.md，移除克隆 .env 代码块中的多余 `\"`，由 @hahouari 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F34 中完成\n* 演示访问权限，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F35 中完成\n* 【功能】在线演示链接，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F36 中完成\n* 演示链接 + API 客户端链接，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F38 中完成\n* 【功能】#15 添加 S3 存储策略，由 @choinek 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F39 中完成\n* 进行中：【功能】llama3.2_vision 更新，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F40 中完成\n* 【修复】缓存相关问题，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F42 中完成\n* 在 Dockerfile 中添加缺失的 Poppler 依赖，由 @PasaOpasen 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F45 中完成\n* 【修复】disable_ocr_cache 修复，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F47 中完成\n* 修复 (#46)——调整 Ollama 处理图像的方式，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F48 中完成\n* 项目重命名，由 @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F53 中完成\n* 更新 docker-compose.gpu.yml，由 @tengerye 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F69 中完成\n* #59 和 #63 多格式支持、重新组织及转换器功能，由 @choinek 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F76 中完成\n\n## 新贡献者\n* @martwozniak 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F7 中完成了首次贡献\n* @pkarw 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F9 中完成了首次贡献\n* @hahouari 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F34 中完成了首次贡献\n* @choinek 在 https:\u002F\u002Fgithub.com\u002FCatchTheTornado\u002Ftext-extract-api\u002Fpull\u002F39 中完成了首次贡献\n* @PasaOpasen 完成了他们的","2025-01-15T08:35:10"]