[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-Dicklesworthstone--llm_aided_ocr":3,"tool-Dicklesworthstone--llm_aided_ocr":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 真正成长为懂上",146793,2,"2026-04-08T23:32:35",[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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108111,"2026-04-08T11:23:26",[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},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":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":10,"last_commit_at":59,"category_tags":60,"status":17},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[35,15,13,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":76,"owner_email":76,"owner_twitter":77,"owner_website":78,"owner_url":79,"languages":80,"stars":89,"forks":90,"last_commit_at":91,"license":92,"difficulty_score":10,"env_os":93,"env_gpu":94,"env_ram":95,"env_deps":96,"category_tags":106,"github_topics":107,"view_count":32,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":114,"updated_at":115,"faqs":116,"releases":152},5744,"Dicklesworthstone\u002Fllm_aided_ocr","llm_aided_ocr","Enhances Tesseract OCR output using LLMs (local or API) for error correction, smart chunking, and markdown formatting of scanned PDFs","llm_aided_ocr 是一款旨在显著提升扫描文档识别质量的开源工具。它巧妙结合了经典的 Tesseract OCR 引擎与大语言模型（LLM）的强大理解能力，专门解决传统光学字符识别中常见的错别字、格式混乱及上下文断裂问题，能将粗糙的识别结果转化为准确、结构清晰且易于阅读的 Markdown 文档。\n\n无论是需要处理大量历史档案的研究人员、希望自动化文档流程的开发者，还是需要将扫描 PDF 转换为可编辑文本的普通用户，都能从中受益。其核心亮点在于“智能纠错”与“灵活部署”：利用 LLM 对识别文本进行语义层面的修正和智能分块，有效去除页眉页脚干扰并合并重复内容；同时支持本地部署（如 llama.cpp）或调用云端 API（OpenAI、Anthropic），既保障了数据隐私，又提供了 GPU 加速等高性能选项。通过异步处理和详细的日志记录，llm_aided_ocr 让复杂的文档数字化过程变得高效且可控，是提升 OCR 输出品质的得力助手。","# LLM-Aided OCR Project\n\n## Introduction\n\nThe LLM-Aided OCR Project is an advanced system designed to significantly enhance the quality of Optical Character Recognition (OCR) output. By leveraging cutting-edge natural language processing techniques and large language models (LLMs), this project transforms raw OCR text into highly accurate, well-formatted, and readable documents.\n\n## Example Outputs\n\nTo see what the LLM-Aided OCR Project can do, check out these example outputs:\n\n- [Original PDF](https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fblob\u002Fmain\u002F160301289-Warren-Buffett-Katharine-Graham-Letter.pdf) \n- [Raw OCR Output](https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fblob\u002Fmain\u002F160301289-Warren-Buffett-Katharine-Graham-Letter__raw_ocr_output.txt)\n- [LLM-Corrected Markdown Output](https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fblob\u002Fmain\u002F160301289-Warren-Buffett-Katharine-Graham-Letter_llm_corrected.md)\n\n## Features\n\n- PDF to image conversion\n- OCR using Tesseract\n- Advanced error correction using LLMs (local or API-based)\n- Smart text chunking for efficient processing\n- Markdown formatting option\n- Header and page number suppression (optional)\n- Quality assessment of the final output\n- Support for both local LLMs and cloud-based API providers (OpenAI, Anthropic)\n- Asynchronous processing for improved performance\n- Detailed logging for process tracking and debugging\n- GPU acceleration for local LLM inference\n\n## Detailed Technical Overview\n\n### PDF Processing and OCR\n\n1. **PDF to Image Conversion**\n   - Function: `convert_pdf_to_images()`\n   - Uses `pdf2image` library to convert PDF pages into images\n   - Supports processing a subset of pages with `max_pages` and `skip_first_n_pages` parameters\n\n2. **OCR Processing**\n   - Function: `ocr_image()`\n   - Utilizes `pytesseract` for text extraction\n   - Includes image preprocessing with `preprocess_image()` function:\n     - Converts image to grayscale\n     - Applies binary thresholding using Otsu's method\n     - Performs dilation to enhance text clarity\n\n### Text Processing Pipeline\n\n1. **Chunk Creation**\n   - The `process_document()` function splits the full text into manageable chunks\n   - Uses sentence boundaries for natural splits\n   - Implements an overlap between chunks to maintain context\n\n2. **Error Correction and Formatting**\n   - Core function: `process_chunk()`\n   - Two-step process:\n     a. OCR Correction:\n        - Uses LLM to fix OCR-induced errors\n        - Maintains original structure and content\n     b. Markdown Formatting (optional):\n        - Converts text to proper markdown format\n        - Handles headings, lists, emphasis, and more\n\n3. **Duplicate Content Removal**\n   - Implemented within the markdown formatting step\n   - Identifies and removes exact or near-exact repeated paragraphs\n   - Preserves unique content and ensures text flow\n\n4. **Header and Page Number Suppression (Optional)**\n   - Can be configured to remove or distinctly format headers, footers, and page numbers\n\n### LLM Integration\n\n1. **Flexible LLM Support**\n   - Supports both local LLMs and cloud-based API providers (OpenAI, Anthropic)\n   - Configurable through environment variables\n\n2. **Local LLM Handling**\n   - Function: `generate_completion_from_local_llm()`\n   - Uses `llama_cpp` library for local LLM inference\n   - Supports custom grammars for structured output\n\n3. **API-based LLM Handling**\n   - Functions: `generate_completion_from_claude()` and `generate_completion_from_openai()`\n   - Implements proper error handling and retry logic\n   - Manages token limits and adjusts request sizes dynamically\n\n4. **Asynchronous Processing**\n   - Uses `asyncio` for concurrent processing of chunks when using API-based LLMs\n   - Maintains order of processed chunks for coherent final output\n\n### Token Management\n\n1. **Token Estimation**\n   - Function: `estimate_tokens()`\n   - Uses model-specific tokenizers when available\n   - Falls back to `approximate_tokens()` for quick estimation\n\n2. **Dynamic Token Adjustment**\n   - Adjusts `max_tokens` parameter based on prompt length and model limits\n   - Implements `TOKEN_BUFFER` and `TOKEN_CUSHION` for safe token management\n\n### Quality Assessment\n\n1. **Output Quality Evaluation**\n   - Function: `assess_output_quality()`\n   - Compares original OCR text with processed output\n   - Uses LLM to provide a quality score and explanation\n\n### Logging and Error Handling\n\n- Comprehensive logging throughout the codebase\n- Detailed error messages and stack traces for debugging\n- Suppresses HTTP request logs to reduce noise\n\n## Configuration and Customization\n\nThe project uses a `.env` file for easy configuration. Key settings include:\n\n- LLM selection (local or API-based)\n- API provider selection\n- Model selection for different providers\n- Token limits and buffer sizes\n- Markdown formatting options\n\n## Output and File Handling\n\n1. **Raw OCR Output**: Saved as `{base_name}__raw_ocr_output.txt`\n2. **LLM Corrected Output**: Saved as `{base_name}_llm_corrected.md` or `.txt`\n\nThe script generates detailed logs of the entire process, including timing information and quality assessments.\n\n## Requirements\n\n- Python 3.12+\n- Tesseract OCR engine\n- PDF2Image library\n- PyTesseract\n- OpenAI API (optional)\n- Anthropic API (optional)\n- Local LLM support (optional, requires compatible GGUF model)\n\n## Installation\n\n1. Install Pyenv and Python 3.12 (if needed):\n\n```bash\n# Install Pyenv and python 3.12 if needed and then use it to create venv:\nif ! command -v pyenv &> \u002Fdev\u002Fnull; then\n    sudo apt-get update\n    sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev \\\n    libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \\\n    xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git\n\n    git clone https:\u002F\u002Fgithub.com\u002Fpyenv\u002Fpyenv.git ~\u002F.pyenv\n    echo 'export PYENV_ROOT=\"$HOME\u002F.pyenv\"' >> ~\u002F.zshrc\n    echo 'export PATH=\"$PYENV_ROOT\u002Fbin:$PATH\"' >> ~\u002F.zshrc\n    echo 'eval \"$(pyenv init --path)\"' >> ~\u002F.zshrc\n    source ~\u002F.zshrc\nfi\ncd ~\u002F.pyenv && git pull && cd -\npyenv install 3.12\n```\n\n2. Set up the project:\n\n```bash\n# Use pyenv to create virtual environment:\ngit clone https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr    \ncd llm_aided_ocr          \npyenv local 3.12\npython -m venv venv\nsource venv\u002Fbin\u002Factivate\npython -m pip install --upgrade pip\npython -m pip install wheel\npython -m pip install --upgrade setuptools wheel\npip install -r requirements.txt\n```\n\n3. Install Tesseract OCR engine (if not already installed):\n   - For Ubuntu: `sudo apt-get install tesseract-ocr`\n   - For macOS: `brew install tesseract`\n   - For Windows: Download and install from [GitHub](https:\u002F\u002Fgithub.com\u002FUB-Mannheim\u002Ftesseract\u002Fwiki)\n\n4. Set up your environment variables in a `.env` file:\n   ```\n   USE_LOCAL_LLM=False\n   API_PROVIDER=OPENAI\n   OPENAI_API_KEY=your_openai_api_key\n   ANTHROPIC_API_KEY=your_anthropic_api_key\n   ```\n\n## Usage\n\n1. Place your PDF file in the project directory.\n\n2. Update the `input_pdf_file_path` variable in the `main()` function with your PDF filename.\n\n3. Run the script:\n   ```\n   python llm_aided_ocr.py\n   ```\n\n4. The script will generate several output files, including the final post-processed text.\n\n## How It Works\n\nThe LLM-Aided OCR project employs a multi-step process to transform raw OCR output into high-quality, readable text:\n\n1. **PDF Conversion**: Converts input PDF into images using `pdf2image`.\n\n2. **OCR**: Applies Tesseract OCR to extract text from images.\n\n3. **Text Chunking**: Splits the raw OCR output into manageable chunks for processing.\n\n4. **Error Correction**: Each chunk undergoes LLM-based processing to correct OCR errors and improve readability.\n\n5. **Markdown Formatting** (Optional): Reformats the corrected text into clean, consistent Markdown.\n\n6. **Quality Assessment**: An LLM-based evaluation compares the final output quality to the original OCR text.\n\n## Code Optimization\n\n- **Concurrent Processing**: When using API-based models, chunks are processed concurrently to improve speed.\n- **Context Preservation**: Each chunk includes a small overlap with the previous chunk to maintain context.\n- **Adaptive Token Management**: The system dynamically adjusts the number of tokens used for LLM requests based on input size and model constraints.\n\n## Configuration\n\nThe project uses a `.env` file for configuration. Key settings include:\n\n- `USE_LOCAL_LLM`: Set to `True` to use a local LLM, `False` for API-based LLMs.\n- `API_PROVIDER`: Choose between \"OPENAI\" or \"CLAUDE\".\n- `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`: API keys for respective services.\n- `CLAUDE_MODEL_STRING`, `OPENAI_COMPLETION_MODEL`: Specify the model to use for each provider.\n- `LOCAL_LLM_CONTEXT_SIZE_IN_TOKENS`: Set the context size for local LLMs.\n\n## Output Files\n\nThe script generates several output files:\n\n1. `{base_name}__raw_ocr_output.txt`: Raw OCR output from Tesseract.\n2. `{base_name}_llm_corrected.md`: Final LLM-corrected and formatted text.\n\n## Limitations and Future Improvements\n\n- The system's performance is heavily dependent on the quality of the LLM used.\n- Processing very large documents can be time-consuming and may require significant computational resources.\n\n## Contributing\n\nContributions to this project are welcome! Please fork the repository and submit a pull request with your proposed changes.\n\n## License\n\nThis project is licensed under the MIT License (with OpenAI\u002FAnthropic Rider).\n\n---\n\nThanks for your interest in my open-source project! I hope you find it useful. You might also find my commercial web apps useful, and I would really appreciate it if you checked them out:\n\n**[YoutubeTranscriptOptimizer.com](https:\u002F\u002Fyoutubetranscriptoptimizer.com)** makes it really quick and easy to paste in a YouTube video URL and have it automatically generate not just a really accurate direct transcription, but also a super polished and beautifully formatted written document that can be used independently of the video.\n\nThe document basically sticks to the same material as discussed in the video, but it sounds much more like a real piece of writing and not just a transcript. It also lets you optionally generate quizzes based on the contents of the document, which can be either multiple choice or short-answer quizzes, and the multiple choice quizzes get turned into interactive HTML files that can be hosted and easily shared, where you can actually take the quiz and it will grade your answers and score the quiz for you.\n\n**[FixMyDocuments.com](https:\u002F\u002Ffixmydocuments.com\u002F)** lets you submit any kind of document— PDFs (including scanned PDFs that require OCR), MS Word and Powerpoint files, images, audio files (mp3, m4a, etc.) —and turn them into highly optimized versions in nice markdown formatting, from which HTML and PDF versions are automatically generated. Once converted, you can also edit them directly in the site using the built-in markdown editor, where it saves a running revision history and regenerates the PDF\u002FHTML versions.\n\nIn addition to just getting the optimized version of the document, you can also generate many other kinds of \"derived documents\" from the original: interactive multiple-choice quizzes that you can actually take and get graded on; slick looking presentation slides as PDF or HTML (using LaTeX and Reveal.js), an in-depth summary, a concept mind map (using Mermaid diagrams) and outline, custom lesson plans where you can select your target audience, a readability analysis and grade-level versions of your original document (good for simplifying concepts for students), Anki Flashcards that you can import directly into the Anki app or use on the site in a nice interface, and more.\n","# LLM 辅助 OCR 项目\n\n## 简介\n\nLLM 辅助 OCR 项目是一个先进的系统，旨在显著提升光学字符识别（OCR）输出的质量。通过利用尖端的自然语言处理技术和大型语言模型（LLMs），该项目可以将原始 OCR 文本转化为高度准确、格式良好且易于阅读的文档。\n\n## 示例输出\n\n要了解 LLM 辅助 OCR 项目能够实现的功能，请查看以下示例输出：\n\n- [原始 PDF](https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fblob\u002Fmain\u002F160301289-Warren-Buffett-Katharine-Graham-Letter.pdf) \n- [原始 OCR 输出](https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fblob\u002Fmain\u002F160301289-Warren-Buffett-Katharine-Graham-Letter__raw_ocr_output.txt)\n- [LLM 修正后的 Markdown 输出](https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fblob\u002Fmain\u002F160301289-Warren-Buffett-Katharine-Graham-Letter_llm_corrected.md)\n\n## 功能特性\n\n- PDF 转图像转换\n- 使用 Tesseract 进行 OCR\n- 利用本地或基于 API 的 LLM 进行高级错误纠正\n- 智能文本分块以提高处理效率\n- 支持 Markdown 格式化\n- 可选的页眉和页码抑制功能\n- 对最终输出进行质量评估\n- 同时支持本地 LLM 和云端 API 提供商（OpenAI、Anthropic）\n- 异步处理以提升性能\n- 详细的日志记录用于流程跟踪和调试\n- GPU 加速用于本地 LLM 推理\n\n## 详细技术概述\n\n### PDF 处理与 OCR\n\n1. **PDF 转图像转换**\n   - 函数：`convert_pdf_to_images()`\n   - 使用 `pdf2image` 库将 PDF 页面转换为图像\n   - 支持通过 `max_pages` 和 `skip_first_n_pages` 参数处理部分页面\n\n2. **OCR 处理**\n   - 函数：`ocr_image()`\n   - 使用 `pytesseract` 进行文本提取\n   - 包括使用 `preprocess_image()` 函数进行图像预处理：\n     - 将图像转换为灰度图\n     - 使用 Otsu 法进行二值化处理\n     - 执行膨胀操作以增强文本清晰度\n\n### 文本处理管道\n\n1. **文本分块**\n   - `process_document()` 函数将全文拆分为可管理的块\n   - 基于句子边界进行自然分割\n   - 在块之间设置重叠以保持上下文连贯性\n\n2. **错误纠正与格式化**\n   - 核心函数：`process_chunk()`\n   - 分两步进行：\n     a. OCR 纠正：\n        - 使用 LLM 修复 OCR 引入的错误\n        - 保留原始结构和内容\n     b. Markdown 格式化（可选）：\n        - 将文本转换为规范的 Markdown 格式\n        - 处理标题、列表、强调等内容\n\n3. **重复内容去除**\n   - 在 Markdown 格式化步骤中实现\n   - 识别并移除完全相同或几乎相同的段落\n   - 保留独特内容并确保文本流畅\n\n4. **页眉和页码抑制（可选）**\n   - 可配置为移除或明确标记页眉、页脚和页码\n\n### LLM 集成\n\n1. **灵活的 LLM 支持**\n   - 支持本地 LLM 和云端 API 提供商（OpenAI、Anthropic）\n   - 可通过环境变量进行配置\n\n2. **本地 LLM 处理**\n   - 函数：`generate_completion_from_local_llm()`\n   - 使用 `llama_cpp` 库进行本地 LLM 推理\n   - 支持自定义语法以生成结构化输出\n\n3. **基于 API 的 LLM 处理**\n   - 函数：`generate_completion_from_claude()` 和 `generate_completion_from_openai()`\n   - 实现了完善的错误处理和重试逻辑\n   - 管理令牌限制并动态调整请求大小\n\n4. **异步处理**\n   - 使用 `asyncio` 在使用基于 API 的 LLM 时并行处理各个文本块\n   - 保持处理顺序以确保最终输出的连贯性\n\n### 令牌管理\n\n1. **令牌估算**\n   - 函数：`estimate_tokens()`\n   - 在可用的情况下使用特定于模型的分词器\n   - 如果不可用，则回退到 `approximate_tokens()` 进行快速估算\n\n2. **动态令牌调整**\n   - 根据提示长度和模型限制调整 `max_tokens` 参数\n   - 实施 `TOKEN_BUFFER` 和 `TOKEN_CUSHION` 以安全地管理令牌\n\n### 质量评估\n\n1. **输出质量评估**\n   - 函数：`assess_output_quality()`\n   - 比较原始 OCR 文本与处理后的输出\n   - 使用 LLM 提供质量评分和解释说明\n\n### 日志记录与错误处理\n\n- 整个代码库中包含全面的日志记录\n- 提供详细的错误信息和堆栈跟踪以方便调试\n- 抑制 HTTP 请求日志以减少噪音\n\n## 配置与定制\n\n该项目使用 `.env` 文件进行便捷配置。关键设置包括：\n\n- LLM 选择（本地或基于 API）\n- API 提供商选择\n- 不同提供商的模型选择\n- 令牌限制和缓冲区大小\n- Markdown 格式化选项\n\n## 输出与文件处理\n\n1. **原始 OCR 输出**：保存为 `{base_name}__raw_ocr_output.txt`\n2. **LLM 修正后的输出**：保存为 `{base_name}_llm_corrected.md` 或 `.txt`\n\n该脚本会生成整个处理过程的详细日志，包括时间信息和质量评估结果。\n\n## 系统要求\n\n- Python 3.12+\n- Tesseract OCR 引擎\n- PDF2Image 库\n- PyTesseract\n- OpenAI API（可选）\n- Anthropic API（可选）\n- 本地 LLM 支持（可选，需兼容 GGUF 模型）\n\n## 安装步骤\n\n1. 安装 Pyenv 和 Python 3.12（如需要）：\n\n```bash\n# 如果尚未安装 Pyenv 和 Python 3.12，则先安装并创建虚拟环境：\nif ! command -v pyenv &> \u002Fdev\u002Fnull; then\n    sudo apt-get update\n    sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev \\\n    libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \\\n    xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git\n\n    git clone https:\u002F\u002Fgithub.com\u002Fpyenv\u002Fpyenv.git ~\u002F.pyenv\n    echo 'export PYENV_ROOT=\"$HOME\u002F.pyenv\"' >> ~\u002F.zshrc\n    echo 'export PATH=\"$PYENV_ROOT\u002Fbin:$PATH\"' >> ~\u002F.zshrc\n    echo 'eval \"$(pyenv init --path)\"' >> ~\u002F.zshrc\n    source ~\u002F.zshrc\nfi\ncd ~\u002F.pyenv && git pull && cd -\npyenv install 3.12\n```\n\n2. 设置项目环境：\n\n```bash\n# 使用 Pyenv 创建虚拟环境：\ngit clone https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr    \ncd llm_aided_ocr          \npyenv local 3.12\npython -m venv venv\nsource venv\u002Fbin\u002Factivate\npython -m pip install --upgrade pip\npython -m pip install wheel\npython -m pip install --upgrade setuptools wheel\npip install -r requirements.txt\n```\n\n3. 安装 Tesseract OCR 引擎（如尚未安装）：\n   - Ubuntu：`sudo apt-get install tesseract-ocr`\n   - macOS：`brew install tesseract`\n   - Windows：从 [GitHub](https:\u002F\u002Fgithub.com\u002FUB-Mannheim\u002Ftesseract\u002Fwiki) 下载并安装\n\n4. 在 `.env` 文件中设置环境变量：\n   ```\n   USE_LOCAL_LLM=False\n   API_PROVIDER=OPENAI\n   OPENAI_API_KEY=your_openai_api_key\n   ANTHROPIC_API_KEY=your_anthropic_api_key\n   ```\n\n## 使用方法\n\n1. 将您的 PDF 文件放入项目目录中。\n\n2. 在 `main()` 函数中，将 `input_pdf_file_path` 变量更新为您 PDF 文件的文件名。\n\n3. 运行脚本：\n   ```\n   python llm_aided_ocr.py\n   ```\n\n4. 脚本将生成多个输出文件，其中包括最终后处理后的文本。\n\n## 工作原理\n\nLLM 辅助 OCR 项目采用多步骤流程，将原始 OCR 输出转换为高质量、可读性强的文本：\n\n1. **PDF 转换**：使用 `pdf2image` 将输入 PDF 转换为图像。\n\n2. **OCR**：应用 Tesseract OCR 从图像中提取文本。\n\n3. **文本分块**：将原始 OCR 输出拆分为易于处理的块。\n\n4. **错误修正**：每个文本块经过基于 LLM 的处理，以纠正 OCR 错误并提高可读性。\n\n5. **Markdown 格式化**（可选）：将修正后的文本重新格式化为整洁、一致的 Markdown 文档。\n\n6. **质量评估**：基于 LLM 的评估会将最终输出的质量与原始 OCR 文本进行比较。\n\n## 代码优化\n\n- **并发处理**：当使用基于 API 的模型时，文本块会并发处理，以提高速度。\n- **上下文保留**：每个文本块与前一个文本块有少量重叠，以保持上下文连贯性。\n- **自适应令牌管理**：系统会根据输入大小和模型限制，动态调整用于 LLM 请求的令牌数量。\n\n## 配置\n\n该项目使用 `.env` 文件进行配置。关键设置包括：\n\n- `USE_LOCAL_LLM`：设置为 `True` 使用本地 LLM，设置为 `False` 使用基于 API 的 LLM。\n- `API_PROVIDER`：选择 “OPENAI” 或 “CLAUDE”。\n- `OPENAI_API_KEY`、`ANTHROPIC_API_KEY`：分别为相应服务的 API 密钥。\n- `CLAUDE_MODEL_STRING`、`OPENAI_COMPLETION_MODEL`：指定各提供商使用的模型。\n- `LOCAL_LLM_CONTEXT_SIZE_IN_TOKENS`：设置本地 LLM 的上下文大小。\n\n## 输出文件\n\n脚本会生成多个输出文件：\n\n1. `{base_name}__raw_ocr_output.txt`：Tesseract 提取的原始 OCR 输出。\n2. `{base_name}_llm_corrected.md`：最终经 LLM 修正并格式化的文本。\n\n## 局限性及未来改进\n\n- 系统性能高度依赖于所使用的 LLM 质量。\n- 处理非常大的文档可能耗时较长，并需要大量计算资源。\n\n## 贡献\n\n欢迎为本项目贡献力量！请 fork 仓库，并提交包含您建议更改的 pull request。\n\n## 许可证\n\n本项目采用 MIT 许可证（附带 OpenAI\u002FAnthropi Rider 条款）。\n\n---\n\n感谢您对我的开源项目的关注！希望您觉得它有用。您可能也会对我的商业 Web 应用程序感兴趣，如果您能去看看就太好了：\n\n**[YoutubeTranscriptOptimizer.com](https:\u002F\u002Fyoutubetranscriptoptimizer.com)** 让您可以快速便捷地粘贴 YouTube 视频 URL，自动不仅生成非常准确的直接转录文本，还能生成一份经过精心打磨、格式美观的独立书面文档，无需依赖视频本身。\n\n该文档内容基本与视频讨论的内容一致，但读起来更像是真正的书面作品，而非简单的转录稿。此外，您还可以选择根据文档内容生成测验，包括选择题和简答题两种形式；其中选择题会被转换成交互式的 HTML 文件，可以轻松托管和分享，您可以在这些页面上直接作答，系统会自动批改并给出分数。\n\n**[FixMyDocuments.com](https:\u002F\u002Ffixmydocuments.com\u002F)** 允许您提交任何类型的文档——PDF（包括需要 OCR 的扫描版 PDF）、MS Word 和 PowerPoint 文件、图片、音频文件（mp3、m4a 等）——并将其转换为格式精美的 Markdown 文档，同时自动生成 HTML 和 PDF 版本。转换完成后，您还可以在网站内置的 Markdown 编辑器中直接编辑文档，系统会保存每次修改的历史记录，并重新生成 PDF\u002FHTML 版本。\n\n除了获得优化后的文档外，您还可以从原始文档中生成多种“衍生文档”：可实际参与并自动评分的互动选择题测验；使用 LaTeX 和 Reveal.js 制作的精美演示文稿（PDF 或 HTML 格式）；深度摘要、概念思维导图（使用 Mermaid 图表）和大纲；可根据目标受众定制的教学计划；可读性分析及对应年级水平的简化版本（适合向学生解释复杂概念）；可以直接导入 Anki 应用或在网站界面中使用的 Anki 抽认卡等更多功能。","# llm_aided_ocr 快速上手指南\n\nllm_aided_ocr 是一个利用大语言模型（LLM）增强光学字符识别（OCR）效果的开源工具。它能将原始的 OCR 识别文本转换为高精度、格式良好且易于阅读的 Markdown 文档，支持本地部署或调用云端 API（OpenAI\u002FAnthropic）。\n\n## 环境准备\n\n在开始之前，请确保您的系统满足以下要求：\n\n*   **操作系统**: Linux (Ubuntu\u002FDebian), macOS, 或 Windows\n*   **Python 版本**: Python 3.12 或更高版本\n*   **核心依赖**:\n    *   **Tesseract OCR 引擎**: 必须预先安装。\n        *   Ubuntu\u002FDebian: `sudo apt-get install tesseract-ocr`\n        *   macOS: `brew install tesseract`\n        *   Windows: 下载并安装 [UB-Mannheim Tesseract](https:\u002F\u002Fgithub.com\u002FUB-Mannheim\u002Ftesseract\u002Fwiki)\n    *   **Pyenv** (推荐): 用于管理 Python 版本（可选，但推荐用于隔离环境）。\n    *   **GPU** (可选): 如果使用本地 LLM 进行推理，建议配备 NVIDIA GPU 以加速。\n\n## 安装步骤\n\n### 1. 克隆项目并设置虚拟环境\n\n建议使用 `pyenv` 管理 Python 版本，或直接使用系统自带的 Python 3.12+。\n\n```bash\n# 克隆仓库\ngit clone https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr    \ncd llm_aided_ocr          \n\n# 如果使用 pyenv 指定 Python 3.12 (若未安装请先运行: pyenv install 3.12)\npyenv local 3.12\n\n# 创建并激活虚拟环境\npython -m venv venv\nsource venv\u002Fbin\u002Factivate  # Windows 用户请使用: venv\\Scripts\\activate\n\n# 升级包管理工具并安装依赖\npython -m pip install --upgrade pip wheel setuptools\npip install -r requirements.txt\n```\n\n> **国内加速提示**: 如果下载依赖较慢，可使用清华或阿里镜像源：\n> `pip install -r requirements.txt -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple`\n\n### 2. 配置环境变量\n\n在项目根目录创建 `.env` 文件，根据您的使用场景（本地模型或云端 API）填写配置。\n\n**示例配置（使用 OpenAI API）：**\n```env\nUSE_LOCAL_LLM=False\nAPI_PROVIDER=OPENAI\nOPENAI_API_KEY=sk-your_openai_api_key_here\n# ANTHROPIC_API_KEY=your_anthropic_api_key (如果使用 Claude 则填写此项)\n```\n\n**示例配置（使用本地 LLM）：**\n```env\nUSE_LOCAL_LLM=True\nAPI_PROVIDER=LOCAL\n# 需确保已下载兼容的 GGUF 模型并在代码中配置路径\n```\n\n## 基本使用\n\n### 1. 准备文件\n将您需要处理的 PDF 文件放入项目根目录。\n\n### 2. 修改脚本配置\n打开 `llm_aided_ocr.py` 文件，找到 `main()` 函数，修改 `input_pdf_file_path` 变量为您的 PDF 文件名。\n\n```python\n# 在 llm_aided_ocr.py 中修改此行\ninput_pdf_file_path = \"your_document.pdf\" \n```\n\n### 3. 运行脚本\n在终端执行以下命令启动处理流程：\n\n```bash\npython llm_aided_ocr.py\n```\n\n### 4. 查看结果\n脚本运行完成后，将在当前目录生成以下文件：\n*   `{文件名}__raw_ocr_output.txt`: Tesseract 输出的原始识别文本。\n*   `{文件名}_llm_corrected.md`: 经过 LLM 纠错、去重并格式化后的最终 Markdown 文档。\n*   日志文件：包含详细的处理时间、质量评估及调试信息。\n\n该工具会自动执行 PDF 转图片、OCR 识别、文本分块、LLM 纠错与格式化、以及最终的质量评估全流程。","某法律科技团队需要将数千页扫描版的历史合同档案数字化，以便导入知识库进行智能检索和分析。\n\n### 没有 llm_aided_ocr 时\n- **识别错误频发**：传统 Tesseract OCR 对模糊扫描件束手无策，常将\"1990\"误识为\"l99O\"，导致关键日期和金额数据不可用。\n- **格式完全丢失**：输出结果为纯文本流，原有的条款层级、列表缩进和加粗强调全部消失，人工还原结构耗时极长。\n- **页眉页脚干扰**：每一页的页码和公司抬头被重复识别进正文，严重打断段落连贯性，后续清洗工作量大且容易出错。\n- **长文档处理低效**：缺乏智能分块机制，处理大文件时容易超出模型上下文限制或导致内存溢出，无法批量自动化运行。\n\n### 使用 llm_aided_ocr 后\n- **语义级纠错**：llm_aided_ocr 调用大语言模型结合上下文自动修正识别错误，将\"l99O\"精准还原为\"1990\"，确保法律条款数据准确无误。\n- **自动 Markdown 排版**：工具智能识别文档结构，自动将杂乱文本转换为带有标题、列表和强调符号的标准 Markdown 格式，即拿即用。\n- **智能噪声过滤**：内置的页眉页脚抑制功能自动剔除重复的页码和抬头信息，输出内容流畅连贯，无需人工二次清洗。\n- **高效分块并行处理**：通过智能句子边界分块与异步处理机制，llm_aided_ocr 能稳定处理数百页的超长合同，显著提升批量转换效率。\n\nllm_aided_ocr 将原本需要数天人工校对的非结构化扫描文档，瞬间转化为高质量、可检索的结构化数据资产。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FDicklesworthstone_llm_aided_ocr_37ee8f76.png","Dicklesworthstone","Jeff Emanuel","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FDicklesworthstone_c96b6d22.jpg","Building in NY",null,"doodlestein","https:\u002F\u002Fwww.jeffreyemanuel.com\u002F","https:\u002F\u002Fgithub.com\u002FDicklesworthstone",[81,85],{"name":82,"color":83,"percentage":84},"Python","#3572A5",91.7,{"name":86,"color":87,"percentage":88},"Dockerfile","#384d54",8.3,2905,204,"2026-04-06T12:27:18","NOASSERTION","Linux, macOS, Windows","可选（仅用于本地 LLM 推理加速），未指定具体型号、显存大小或 CUDA 版本","未说明",{"notes":97,"python":98,"dependencies":99},"必须安装 Tesseract OCR 引擎。支持本地 LLM（需兼容的 GGUF 模型）或云端 API（OpenAI\u002FAnthropic）。本地运行时需配置 .env 文件，若使用本地模型建议具备 GPU 以提升性能。","3.12+",[100,101,102,103,104,105],"pdf2image","pytesseract","llama-cpp-python","asyncio","openai","anthropic",[15,35,14],[108,109,110,111,112,113],"ai-assist","llama2","llm","ocr","tesseract","ocr-correction","2026-03-27T02:49:30.150509","2026-04-09T10:06:15.446500",[117,122,127,132,137,142,147],{"id":118,"question_zh":119,"answer_zh":120,"source_url":121},26062,"如何处理下载 GGUF 模型文件而非旧版 GGML 文件的需求？","代码库默认可能指向旧的 GGML 格式，但当前推荐（如 TheBloke）使用 GGUF 格式。维护者建议用户克隆仓库到本地并自行修改代码以适应新格式。你可以使用 `huggingface-cli` 下载特定的 GGUF 文件，例如：`huggingface-cli download TheBloke\u002FLlama-2-13B-chat-GGUF llama-2-13b-chat.q4_K_M.gguf --local-dir`。如果需要集成到项目中，需手动调整下载逻辑或提交 PR。","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fissues\u002F5",{"id":123,"question_zh":124,"answer_zh":125,"source_url":126},26063,"遇到 'KeyError: slice(-1000, None, None)' 错误该如何解决？","该错误是由于 `generate_completion_from_local_llm()` 函数返回了字典（dict）而不是字符串（string），导致无法对结果进行切片操作。此问题已在 commit f5bb024 中修复。修复后，该函数现在一致地返回 `Optional[str]` 类型，确保 `processed_chunk[-1000:]` 等切片操作能正常执行。请更新代码至最新版本。","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fissues\u002F20",{"id":128,"question_zh":129,"answer_zh":130,"source_url":131},26064,"使用本地模型处理 PDF 速度太慢，如何提升处理速度？","本地模型通常是顺序处理数据块，因此速度较慢，即使使用多核 CPU 也难以显著改善。维护者强烈建议使用 API（如 OpenAI），因为 API 支持并行处理数据块，性能大幅提升。对于大多数文档，API 的成本极低（通常只需几美分）。如果必须使用免费方案，可尝试寻找其他免费 API 模型，但本地模型的速度瓶颈主要在于其串行处理机制。","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fissues\u002F12",{"id":133,"question_zh":134,"answer_zh":135,"source_url":136},26065,"遇到 'Token indices sequence length is longer than...' 提示输入过长怎么办？","当输入的 token 序列长度超过模型指定的最大长度（例如 2816 > 2048）时会出现此警告。解决方案有两种：1. 推荐使用 API 以获得最佳效果和自动处理；2. 如果坚持使用本地模型，可以尝试减小数据块（chunk）的大小，或者调整 tokenizer 和模型加载函数以适配你的特定模型（如 Llama3.1）。","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fissues\u002F13",{"id":138,"question_zh":139,"answer_zh":140,"source_url":141},26066,"调用 AI 时出现 'Invalid max_tokens: integer below minimum value' 负值错误如何修复？","这是因为当 prompt 过长时，计算出的 `max_tokens` 可能变为负数。该问题已在 commit f5bb024 中修复。代码中增加了 `max(1, ...)` 包装器来确保 `max_tokens` 至少为 1。具体修改包括：\nOpenAI 部分：`adjusted_max_tokens = max(1, min(max_tokens, 4096 - prompt_tokens - TOKEN_BUFFER))`\n本地 LLM 部分：`adjusted_max_tokens = max(1, min(number_of_tokens_to_generate, LOCAL_LLM_CONTEXT_SIZE_IN_TOKENS - prompt_tokens - TOKEN_BUFFER))`\n请更新代码以应用此修复。","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fissues\u002F11",{"id":143,"question_zh":144,"answer_zh":145,"source_url":146},26067,"如何使用 DistilBERT、RoBERTa 等其他离线 LLM 替代默认的 Llama2？","可以使用其他离线模型，但需要修改代码。主要步骤包括：1. 更新 `download_models` 函数以下载你想要的模型；2. 如果使用的不是 Llama 系列模型，必须修改 `get_tokenizer` 函数以加载正确的 tokenizer。维护者指出，虽然可行，但这需要针对每个模型家族进行特定调整。相比之下，直接使用 OpenAI 或 Claude 等 API 能获得更好的开箱即用体验。","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fissues\u002F4",{"id":148,"question_zh":149,"answer_zh":150,"source_url":151},26068,"项目是否支持使用 GPT-3.5-turbo 或 GPT-4 等 API 代替本地模型？","是的，项目目前已重构以支持多种 API，包括 OpenAI（GPT-3.5-turbo, GPT-4 等）。这使得可以在任何硬件上运行 PDF 转文本任务，无需依赖本地大模型。如果你想添加对其他 API 的支持，可以参考当前代码库中 API 调用的结构进行 fork 和修改。","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fllm_aided_ocr\u002Fissues\u002F3",[]]