This repository contains a powerful Optical Character Recognition (OCR) pipeline built with Python and the Google Gemini 1.5 Flash model. It's designed to process PDF documents, extract detailed text, and prepare it for applications like Retrieval Augmented Generation (RAG), focusing on high fidelity and structural preservation.
Note: I just vibecoded this using Gemini 2.5 Pro
The project is organized for clarity and efficient processing:
your_ocr_project/
├── .env # Stores your Google API key (ignored by Git for security)
├── main.py # The main script to run the OCR pipeline
├── ocr_utils.py # Contains core OCR functions and model interactions
71F2
├── pdf_docs/ # Place your input PDF documents here
└── output/ # Where the final extracted text files will be saved (ignored by Git)
Follow these steps to set up and run the OCR pipeline on your machine:
You'll need a few Python libraries and the poppler-utils system package to convert PDFs into images.
First, install poppler-utils:
sudo apt-get update
sudo apt-get install poppler-utilsNext, install the required Python libraries:
pip install google-generativeai pypdf pdf2image Pillow python-dotenvTo use the Gemini 2.0 Flash model, you need an API key:
- Visit Google AI Studio.
- Create a new API key.
Create a file named .env in the root directory of your project (i.e., your_ocr_project/.env). Add your API key to this file:
GOOGLE_API_KEY="YOUR_API_KEY"
Replace YOUR_API_KEY with the actual key you obtained.
Put all the PDF documents you want to process into the pdf_docs/ folder.
Navigate to the project's root directory in your terminal and execute the main script:
python main.pyThe script will process each PDF, print progress messages, and save the extracted text files directly into the output/ folder. Temporary image files generated during processing will be automatically cleaned up.