GhosTHaise/test-lighton-ocr-1b

An end-to-end OCR AI model with ~1 billion parameters that directly transforms document images (PDFs/scans) into structured, readable text, without relying on a traditional multi-step OCR pipeline.

0

stars

13

commits

Python

primary language

Jan 31, 2026

updated

README

Test lighton-ocr-1b model πŸš€

A lightweight, local OCR pipeline designed to convert PDF documents into structured JSON data. This project leverages the LightOn-OCR-1B model running on Ollama for high-accuracy text extraction without data leaving your machine.

🌟 Key Features

  • 100% Local Inference: Powered by Ollama, ensuring total data privacy.
  • Optimized Model: Uses maternion/LightOnOCR-2, a vision-language model specialized in document text recognition.
  • Modern Python Tooling: Powered by uv for lightning-fast dependency management and execution.

πŸ› οΈ Prerequisites

  1. Ollama must be installed and running.
  2. Pull the LightOnOCR model:
ollama pull maternion/LightOnOCR-2

  1. uv installed on your system:
# Install uv via curl
curl -LsSf https://astral.sh/uv/install.sh | sh

πŸš€ Quick Start

Using uv, you don't need to manually manage virtual environments or install dependencies one by one.

  1. Clone the repository:
git clone <your-repo-url>
cd test-lighton-ocr-1b

  1. Run the script:
uv run main.py
uv run pdf.py

Note: uv will automatically handle dependencies (ollama, pypdfium2, requests, pillow) defined in the script or pyproject.toml.

πŸ“ How it Works

The pipeline follows these steps:

  1. Fetch: Downloads the target PDF directly from a URL (e.g., an arXiv research paper).
  2. Render: Converts PDF pages into high-resolution images (200 DPI) using pypdfium2.
  3. Process: Sends the image bytes to the LightOnOCR-2 vision model via Ollama's Chat API.
  4. Structure: Aggregates the OCR results into a single, structured JSON object containing data for every page.

πŸ“Š Sample Output

[
    {
        "page": 1,
        "content": "Full text extracted from page 1..."
    },
    {
        "page": 2,
        "content": "Full text extracted from page 2..."
    }
]

⚠️ Important Notes

  • Vision Resources: While LightOn-OCR-1B is highly efficient, ensure your system has sufficient VRAM/RAM for smooth image processing.
  • Prompt Engineering: The current prompt requests JSON format. Depending on the model's output, you might occasionally need to strip Markdown code blocks (e.g., json ... ) from the response.

Contributors

GhosTHaise

13 commits

GhosTHaise/test-lighton-ocr-1b

An end-to-end OCR AI model with ~1 billion parameters that directly transforms document images (PDFs/scans) into structured, readable text, without relying on a traditional multi-step OCR pipeline.

0

stars

13

commits

Python

primary language

Jan 31, 2026

updated

README

Test lighton-ocr-1b model πŸš€

A lightweight, local OCR pipeline designed to convert PDF documents into structured JSON data. This project leverages the LightOn-OCR-1B model running on Ollama for high-accuracy text extraction without data leaving your machine.

🌟 Key Features

  • 100% Local Inference: Powered by Ollama, ensuring total data privacy.
  • Optimized Model: Uses maternion/LightOnOCR-2, a vision-language model specialized in document text recognition.
  • Modern Python Tooling: Powered by uv for lightning-fast dependency management and execution.

πŸ› οΈ Prerequisites

  1. Ollama must be installed and running.
  2. Pull the LightOnOCR model:
ollama pull maternion/LightOnOCR-2

  1. uv installed on your system:
# Install uv via curl
curl -LsSf https://astral.sh/uv/install.sh | sh

πŸš€ Quick Start

Using uv, you don't need to manually manage virtual environments or install dependencies one by one.

  1. Clone the repository:
git clone <your-repo-url>
cd test-lighton-ocr-1b

  1. Run the script:
uv run main.py
uv run pdf.py

Note: uv will automatically handle dependencies (ollama, pypdfium2, requests, pillow) defined in the script or pyproject.toml.

πŸ“ How it Works

The pipeline follows these steps:

  1. Fetch: Downloads the target PDF directly from a URL (e.g., an arXiv research paper).
  2. Render: Converts PDF pages into high-resolution images (200 DPI) using pypdfium2.
  3. Process: Sends the image bytes to the LightOnOCR-2 vision model via Ollama's Chat API.
  4. Structure: Aggregates the OCR results into a single, structured JSON object containing data for every page.

πŸ“Š Sample Output

[
    {
        "page": 1,
        "content": "Full text extracted from page 1..."
    },
    {
        "page": 2,
        "content": "Full text extracted from page 2..."
    }
]

⚠️ Important Notes

  • Vision Resources: While LightOn-OCR-1B is highly efficient, ensure your system has sufficient VRAM/RAM for smooth image processing.
  • Prompt Engineering: The current prompt requests JSON format. Depending on the model's output, you might occasionally need to strip Markdown code blocks (e.g., json ... ) from the response.

Contributors

GhosTHaise

13 commits

Languages

Python

100.0%