Enhance OCR output using LLMs for better accuracy and formatting.
The LLM-Aided OCR project enhances the quality of scanned documents by correcting OCR errors and formatting text into Markdown. It's perfect for anyone dealing with scanned PDFs, such as researchers or content creators, who need accurate and well-structured text. By using this tool, you can save time and improve the readability of your documents without the need for expensive software.
As remote work increases, the demand for accurate document processing tools has surged. This project fills the gap left by traditional OCR tools by integrating advanced LLMs for error correction, making it a powerful solution for professionals needing high-quality text outputs.
You will process a scanned PDF document, enhance its OCR output, and save it as a well-formatted Markdown file.
You need Git, Python 3.12+, and Tesseract OCR installed on your machine.
python --version && tesseract --versionbrew install tesseractsudo apt-get install tesseract-ocrwinget install TesseractCreate a .env file in the project directory to store your API keys and configuration settings.
# Environment configuration for LLM-Aided OCR
USE_LOCAL_LLM=False
API_PROVIDER=OPENAI
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_keyFirst, ensure you have Python 3.12 and Tesseract installed. Then, clone the repository and set up a virtual environment.
git clone https://github.com/Dicklesworthstone/llm_aided_ocr
cd llm_aided_ocr
pyenv local 3.12
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtCreate a `.env` file to configure your API keys and set up the necessary environment variables. Also, ensure you have a PDF file to process.
echo -e 'USE_LOCAL_LLM=False
API_PROVIDER=OPENAI
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key' > .env
cp 160301289-Warren-Buffett-Katharine-Graham-Letter.pdf ./Run the command to process the PDF file and generate the Markdown output.
python llm-aided-ocr-cli.py 160301289-Warren-Buffett-Katharine-Graham-Letter.pdfCheck the output directory for the generated Markdown file and review the content for accuracy and formatting.
cat 160301289-Warren-Buffett-Katharine-Graham-Letter_llm_corrected.mdYou run the tool on a scanned historical document. The tool processes the PDF, corrects OCR errors, and formats the text into Markdown. You can then easily edit and reference this text in your research.
python llm-aided-ocr-cli.py 160301289-Warren-Buffett-Katharine-Graham-Letter.pdfYou upload a scanned report and run the tool. It enhances the OCR output, ensuring the text is clean and well-formatted for publication. This saves you hours of manual editing.
python llm-aided-ocr-cli.py scanned_report.pdfYou process a legal document using the tool, which corrects any OCR mistakes and formats the text into Markdown. This allows for easier sharing and collaboration on legal texts.
python llm-aided-ocr-cli.py legal_document.pdfMarketers can digitize brochures and flyers, converting them into editable formats for campaigns. This streamlines content creation and ensures accuracy.
Legal professionals can convert physical contracts into digital formats, making them easier to share and edit. This improves collaboration and reduces errors.
Data analysts can quickly digitize and analyze scanned reports, saving time on data entry. This allows for faster insights and decision-making.
Educators can digitize textbooks and handouts, making them accessible for online learning. This promotes inclusivity and resource availability.
Publishers can convert scanned manuscripts into editable formats, streamlining the editing process. This reduces the time spent on manual corrections.
Ensure you have Python 3.12 and Tesseract installed on your system. These are essential for running the project.
sudo apt-get install tesseract-ocrGet the project files by cloning the repository from GitHub. This gives you access to all necessary scripts.
git clone https://github.com/Dicklesworthstone/llm_aided_ocrCreate a virtual environment to manage dependencies without affecting your global Python installation.
python -m venv venv
source venv/bin/activateInstall all required Python packages listed in the requirements.txt file to ensure the project runs smoothly.
pip install -r requirements.txtExecute the command to process your PDF file, which will enhance the OCR output and format it into Markdown.
python llm-aided-ocr-cli.py your_document.pdfgit clone https://github.com/Dicklesworthstone/llm_aided_ocr
cd llm_aided_ocr
pyenv local 3.12
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Fix: Install Tesseract using your package manager (e.g., 'sudo apt-get install tesseract-ocr'). Fix: Run 'pip install pdf2image' to install the missing package. Fix: Ensure your .env file contains valid API keys and is properly formatted. Enter your email once to unlock OS prerequisites, .env config template, 4-phase hands-on tutorial, all real-world use cases, troubleshooting fixes & every Tool Lab prompt free.