# Ollama-OCR: Advanced OCR with Vision Language Models via Ollama

This repository profile is provided by osrepos.com, an open source repository discovery platform.

Source: osrepos.com
Repository profile: https://osrepos.com/repo/imanoop7-ollama-ocr
Generated for open source discovery and AI-assisted research.

Ollama-OCR is a robust Python package and Streamlit application for Optical Character Recognition. It leverages state-of-the-art vision language models, accessible through Ollama, to accurately extract text from both images and PDF documents. The tool offers extensive features including support for multiple models, various output formats, and batch processing capabilities.

GitHub: https://github.com/imanoop7/Ollama-OCR
OSRepos URL: https://osrepos.com/repo/imanoop7-ollama-ocr

## Summary

Ollama-OCR is a robust Python package and Streamlit application for Optical Character Recognition. It leverages state-of-the-art vision language models, accessible through Ollama, to accurately extract text from both images and PDF documents. The tool offers extensive features including support for multiple models, various output formats, and batch processing capabilities.

## Topics

- OCR
- Ollama
- Python
- Machine Learning
- Vision Models
- AI
- Streamlit
- Document Processing

## Repository Information

Last analyzed by OSRepos: Sun Oct 12 2025 07:10:52 GMT+0100 (Western European Summer Time)
Detail views: 67
GitHub clicks: 4

## Safety Notice

OSRepos shares public repositories for knowledge and discovery only. Review source code, dependencies, licenses, and security implications before running or installing anything.

## Content

## Introduction

Ollama-OCR is a powerful and versatile Python package designed for Optical Character Recognition (OCR). It leverages state-of-the-art vision language models, made accessible through Ollama, to accurately extract text from both images and PDF documents. With over 2000 stars and 200 forks on GitHub, this project demonstrates significant community interest and utility. It is available as a Python library for programmatic use and also features a user-friendly Streamlit web application.

[Explore Ollama-OCR on GitHub](https://github.com/imanoop7/Ollama-OCR){:target="_blank"}

## Installation

To get started with Ollama-OCR, you first need to install Ollama and pull the desired vision models.

### Prerequisites

1.  **Install Ollama**: Follow the instructions on the [Ollama website](https://ollama.com){:target="_blank"}.
2.  **Pull Required Models**: Use the `ollama pull` command for models like `llama3.2-vision:11b`, `granite3.2-vision`, `moondream`, or `minicpm-v`.

bash
ollama pull llama3.2-vision:11b
ollama pull granite3.2-vision
ollama pull moondream
ollama pull minicpm-v


### Package Installation

Install the Ollama-OCR Python package using pip:

bash
pip install ollama-ocr


## Examples

Ollama-OCR provides flexible options for processing single files or batches, and also includes a Streamlit application for a graphical interface.

### Single File Processing

Process an individual image or PDF file with a specified model and output format:

python
from ollama_ocr import OCRProcessor

# Initialize OCR processor
ocr = OCRProcessor(model_name='llama3.2-vision:11b', base_url="http://host.docker.internal:11434/api/generate")
# You can pass your custom Ollama API URL

# Process an image or PDF
result = ocr.process_image(
    image_path="path/to/your/image.png", # or "path/to/your/file.pdf"
    format_type="markdown",  # Options: markdown, text, json, structured, key_value, table
    custom_prompt="Extract all text, focusing on dates and names.", # Optional custom prompt
    language="English" # Specify the language of the text
)
print(result)


### Batch File Processing

Efficiently process multiple images or PDFs in parallel from a directory:

python
from ollama_ocr import OCRProcessor

# Initialize OCR processor with parallel workers
ocr = OCRProcessor(model_name='llama3.2-vision:11b', max_workers=4)

# Process multiple files with progress tracking
batch_results = ocr.process_batch(
    input_path="path/to/images/folder",  # Directory or list of image paths
    format_type="markdown",
    recursive=True,  # Search subdirectories
    preprocess=True,  # Enable image preprocessing
    custom_prompt="Extract all text, focusing on dates and names.", # Optional custom prompt
    language="English" # Specify the language of the text
)
# Access results
for file_path, text in batch_results['results'].items():
    print(f"\nFile: {file_path}")
    print(f"Extracted Text: {text}")

# View statistics
print("\nProcessing Statistics:")
print(f"Total images: {batch_results['statistics']['total']}")
print(f"Successfully processed: {batch_results['statistics']['successful']}")
print(f"Failed: {batch_results['statistics']['failed']}")


### Streamlit Web Application

For a user-friendly experience, the project includes a Streamlit web application that supports batch processing, drag-and-drop uploads, and real-time results.

1.  Clone the repository:
    bash
git clone https://github.com/imanoop7/Ollama-OCR.git
cd Ollama-OCR
    
2.  Install dependencies:
    bash
pip install -r requirements.txt
    
3.  Navigate to the `src/ollama_ocr` directory:
    bash
cd src/ollama_ocr
    
4.  Run the Streamlit app:
    bash
streamlit run app.py
    

## Why Use Ollama-OCR?

Ollama-OCR stands out due to its comprehensive feature set and flexibility:

*   **Extensive Model Support**: Integrate with various powerful vision language models like LLaVA, Llama 3.2 Vision, Granite3.2-vision, Moondream, and Minicpm-v.
*   **Versatile Output Formats**: Obtain extracted text in Markdown, Plain Text, JSON, Structured, Key-Value Pairs, or Table formats, catering to diverse application needs.
*   **Batch Processing**: Efficiently handle multiple documents with parallel processing and progress tracking.
*   **Custom Prompts**: Tailor text extraction with custom instructions to focus on specific information.
*   **PDF and Image Support**: Process a wide range of document types.
*   **User-Friendly Streamlit App**: A responsive web interface simplifies usage for non-developers, offering drag-and-drop functionality and real-time results.
*   **Language Selection**: Improve OCR accuracy by specifying the language of the text.

## Links

*   **GitHub Repository**: [imanoop7/Ollama-OCR](https://github.com/imanoop7/Ollama-OCR){:target="_blank"}
*   **Ollama Official Website**: [ollama.com](https://ollama.com){:target="_blank"}
*   **LLaVA Model**: [ollama.com/library/llava](https://ollama.com/library/llava){:target="_blank"}
*   **Granite3.2-vision Model**: [ollama.com/library/granite3.2-vision](https://ollama.com/library/granite3.2-vision){:target="_blank"}
*   **Moondream Model**: [ollama.com/library/moondream](https://ollama.com/library/moondream){:target="_blank"}
*   **Minicpm-v Model**: [ollama.com/library/minicpm-v](https://ollama.com/library/minicpm-v){:target="_blank"}
*   **Example Notebooks**: [Ollama-OCR Example Notebooks](https://github.com/imanoop7/Ollama-OCR/tree/main/example_notebooks){:target="_blank"}