par-ocr


Namepar-ocr JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryUse AI vision to OCR PDF and image files to markdown.
upload_time2025-01-26 23:17:10
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseMIT License Copyright (c) 2024 Paul Robello Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords ai markdown ocr pdf
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PAR AI OCR

[![PyPI](https://img.shields.io/pypi/v/par_ocr)](https://pypi.org/project/par_ocr/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/par_ocr.svg)](https://pypi.org/project/par_ocr/)  
![Runs on Linux | MacOS | Windows](https://img.shields.io/badge/runs%20on-Linux%20%7C%20MacOS%20%7C%20Windows-blue)
![Arch x86-63 | ARM | AppleSilicon](https://img.shields.io/badge/arch-x86--64%20%7C%20ARM%20%7C%20AppleSilicon-blue)  
![PyPI - License](https://img.shields.io/pypi/l/par_ocr)

PAR AI OCR is a command-line tool that uses artificial intelligence to perform Optical Character Recognition (OCR) on PDF files and images. 
It extracts text from the input files and generates markdown output.

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://buymeacoffee.com/probello3)

## Screenshots
![PAR Scrape Screenshot](https://raw.githubusercontent.com/paulrobello/par_ocr/main/Screenshot.png)

## Features
- Extracts text for PDFs and images to Markdown while preserving as much formatting as possible.
- Works with most providers and vision models (quality will vary depending on provider and model used)
- Uses my [PAR AI Core](https://github.com/paulrobello/par_ai_core)


## Known Issues
- Providers other than OpenAI and Anthropic are hit-and-miss depending on provider / model / data being extracted.

## Prerequisites

### Install poppler (Used for PDF processing)

#### Linux
```bash
apt install poppler-utils
```

#### Mac
```bash
brew install poppler
```

#### Windows
```bash
scoop install poppler
```

### uv is recommended

#### Linux and Mac
```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

#### Windows
```bash
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
```


## Installation

### Installation From Source
Clone the repository and install the package:

```bash
git clone https://github.com/paulrobello/par_ocr.git
cd par_ocr
uv sync
```

### From PiPy

```bash
uv tool install par_ocr
```

## Usage

Basic usage from source:

```bash
uv run par_ocr
```


Basic usage if installed:

```bash
par_ocr
```

### Command Line Parameters

- `--ai-provider`, `-a`: AI provider to use for processing [Ollama|LlamaCpp|OpenAI|Groq|XAI|Anthropic|Google|Bedrock|Github|Mistral] (default: OpenAI)
- `--model`, `-m`: AI model to use for processing (default: provider-specific)
- `--ai-base-url`, `-b`: Override the base URL for the AI provider
- `--system-prompt-file`, `-p`: File containing custom system prompt, if you want to use one other than the default
- `--input-file`, `-i`: File to process, supported extensions: .pdf, .png, .jpg
- `--pricing`, `-p`: Configure pricing summary display [none|price|details] (default: price)
- `--pages`: Comma-separated page numbers or hyphen-separated range (e.g., '1,3,5-7')
- `--output`, `-o`: Output directory for markdown files (default same folder as input file)
- `--debug`, `-D`: Output extra debug info (Default: false)
- `--version`, `-v`: Show version information and exit

### Examples

Note: If running from source prepend "uv run" to the beginning of the example commands.

1. Process a PDF file using the default settings:
   ```bash
   par_ocr --input-file path/to/your/file.pdf
   ```

2. Use a specific AI provider and model:
   ```bash
   par_ocr --ai-provider ANTHROPIC --model claude-3-5-sonnet-20241022 --input-file path/to/your/file.pdf
   ```

3. Process specific pages of a PDF:
   ```bash
   par_ocr --input-file path/to/your/file.pdf --pages 1,3,5-7
   ```

4. Specify an output directory:
   ```bash
   par_ocr --input-file path/to/your/file.pdf --output path/to/output/directory
   ```

5. Enable pricing details:
   ```bash
   par_ocr --pricing details --input-file path/to/your/file.pdf 
   ```

## Note

Make sure to set the appropriate environment variables for the AI provider you're using (e.g., OPENAI_API_KEY for OpenAI).
you may also create a file `~/.par_ocr_config` with your API Keys such as:

```shell
# AI API KEYS
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
GROQ_API_KEY=
XAI_API_KEY=
GOOGLE_API_KEY=
MISTRAL_API_KEY=
GITHUB_TOKEN=
OPENROUTER_API_KEY=
# Used by Bedrock
AWS_PROFILE=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=


### Tracing (optional)
LANGCHAIN_TRACING_V2=false
LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
LANGCHAIN_API_KEY=
LANGCHAIN_PROJECT=par_ocr
```

### AI API KEYS

* ANTHROPIC_API_KEY is required for Anthropic. Get a key from https://console.anthropic.com/
* OPENAI_API_KEY is required for OpenAI. Get a key from https://platform.openai.com/account/api-keys
* GITHUB_TOKEN is required for GitHub Models. Get a free key from https://github.com/marketplace/models
* GOOGLE_API_KEY is required for Google Models. Get a free key from https://console.cloud.google.com
* XAI_API_KEY is required for XAI. Get a free key from https://x.ai/api
* GROQ_API_KEY is required for Groq. Get a free key from https://console.groq.com/
* MISTRAL_API_KEY is required for Mistral. Get a free key from https://console.mistral.ai/
* OPENROUTER_KEY is required for OpenRouter. Get a key from https://openrouter.ai/
* AWS_PROFILE or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are used for Bedrock authentication. The environment must
  already be authenticated with AWS.
* No key required to use with Ollama or LlamaCpp.

### Open AI Compatible Providers

If a specify provider is not listed but has an OpenAI compatible endpoint you can use the following combo of vars:
* PARAI_AI_PROVIDER=OpenAI
* PARAI_MODEL=Your selected model
* PARAI_AI_BASE_URL=The providers OpenAI endpoint URL

## Whats New
- Version 0.2.0:
  - Updated ai lib and other dependencies
  - Added debug flag
- Version 0.1.1:
  - Updated ai lib
  - Fixed markdown fences
- Version 0.1.0:
  - Initial release

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Author

Paul Robello - probello@gmail.com

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "par-ocr",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "Paul Robello <probello@gmail.com>",
    "keywords": "ai, markdown, ocr, pdf",
    "author": null,
    "author_email": "Paul Robello <probello@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ad/05/2907457c01b4b4387ceaab1f24489a5f6d28fccdc8ff2cc3ef359a7d018b/par_ocr-0.2.0.tar.gz",
    "platform": null,
    "description": "# PAR AI OCR\n\n[![PyPI](https://img.shields.io/pypi/v/par_ocr)](https://pypi.org/project/par_ocr/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/par_ocr.svg)](https://pypi.org/project/par_ocr/)  \n![Runs on Linux | MacOS | Windows](https://img.shields.io/badge/runs%20on-Linux%20%7C%20MacOS%20%7C%20Windows-blue)\n![Arch x86-63 | ARM | AppleSilicon](https://img.shields.io/badge/arch-x86--64%20%7C%20ARM%20%7C%20AppleSilicon-blue)  \n![PyPI - License](https://img.shields.io/pypi/l/par_ocr)\n\nPAR AI OCR is a command-line tool that uses artificial intelligence to perform Optical Character Recognition (OCR) on PDF files and images. \nIt extracts text from the input files and generates markdown output.\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://buymeacoffee.com/probello3)\n\n## Screenshots\n![PAR Scrape Screenshot](https://raw.githubusercontent.com/paulrobello/par_ocr/main/Screenshot.png)\n\n## Features\n- Extracts text for PDFs and images to Markdown while preserving as much formatting as possible.\n- Works with most providers and vision models (quality will vary depending on provider and model used)\n- Uses my [PAR AI Core](https://github.com/paulrobello/par_ai_core)\n\n\n## Known Issues\n- Providers other than OpenAI and Anthropic are hit-and-miss depending on provider / model / data being extracted.\n\n## Prerequisites\n\n### Install poppler (Used for PDF processing)\n\n#### Linux\n```bash\napt install poppler-utils\n```\n\n#### Mac\n```bash\nbrew install poppler\n```\n\n#### Windows\n```bash\nscoop install poppler\n```\n\n### uv is recommended\n\n#### Linux and Mac\n```bash\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n```\n\n#### Windows\n```bash\npowershell -ExecutionPolicy ByPass -c \"irm https://astral.sh/uv/install.ps1 | iex\"\n```\n\n\n## Installation\n\n### Installation From Source\nClone the repository and install the package:\n\n```bash\ngit clone https://github.com/paulrobello/par_ocr.git\ncd par_ocr\nuv sync\n```\n\n### From PiPy\n\n```bash\nuv tool install par_ocr\n```\n\n## Usage\n\nBasic usage from source:\n\n```bash\nuv run par_ocr\n```\n\n\nBasic usage if installed:\n\n```bash\npar_ocr\n```\n\n### Command Line Parameters\n\n- `--ai-provider`, `-a`: AI provider to use for processing [Ollama|LlamaCpp|OpenAI|Groq|XAI|Anthropic|Google|Bedrock|Github|Mistral] (default: OpenAI)\n- `--model`, `-m`: AI model to use for processing (default: provider-specific)\n- `--ai-base-url`, `-b`: Override the base URL for the AI provider\n- `--system-prompt-file`, `-p`: File containing custom system prompt, if you want to use one other than the default\n- `--input-file`, `-i`: File to process, supported extensions: .pdf, .png, .jpg\n- `--pricing`, `-p`: Configure pricing summary display [none|price|details] (default: price)\n- `--pages`: Comma-separated page numbers or hyphen-separated range (e.g., '1,3,5-7')\n- `--output`, `-o`: Output directory for markdown files (default same folder as input file)\n- `--debug`, `-D`: Output extra debug info (Default: false)\n- `--version`, `-v`: Show version information and exit\n\n### Examples\n\nNote: If running from source prepend \"uv run\" to the beginning of the example commands.\n\n1. Process a PDF file using the default settings:\n   ```bash\n   par_ocr --input-file path/to/your/file.pdf\n   ```\n\n2. Use a specific AI provider and model:\n   ```bash\n   par_ocr --ai-provider ANTHROPIC --model claude-3-5-sonnet-20241022 --input-file path/to/your/file.pdf\n   ```\n\n3. Process specific pages of a PDF:\n   ```bash\n   par_ocr --input-file path/to/your/file.pdf --pages 1,3,5-7\n   ```\n\n4. Specify an output directory:\n   ```bash\n   par_ocr --input-file path/to/your/file.pdf --output path/to/output/directory\n   ```\n\n5. Enable pricing details:\n   ```bash\n   par_ocr --pricing details --input-file path/to/your/file.pdf \n   ```\n\n## Note\n\nMake sure to set the appropriate environment variables for the AI provider you're using (e.g., OPENAI_API_KEY for OpenAI).\nyou may also create a file `~/.par_ocr_config` with your API Keys such as:\n\n```shell\n# AI API KEYS\nOPENAI_API_KEY=\nANTHROPIC_API_KEY=\nGROQ_API_KEY=\nXAI_API_KEY=\nGOOGLE_API_KEY=\nMISTRAL_API_KEY=\nGITHUB_TOKEN=\nOPENROUTER_API_KEY=\n# Used by Bedrock\nAWS_PROFILE=\nAWS_ACCESS_KEY_ID=\nAWS_SECRET_ACCESS_KEY=\n\n\n### Tracing (optional)\nLANGCHAIN_TRACING_V2=false\nLANGCHAIN_ENDPOINT=https://api.smith.langchain.com\nLANGCHAIN_API_KEY=\nLANGCHAIN_PROJECT=par_ocr\n```\n\n### AI API KEYS\n\n* ANTHROPIC_API_KEY is required for Anthropic. Get a key from https://console.anthropic.com/\n* OPENAI_API_KEY is required for OpenAI. Get a key from https://platform.openai.com/account/api-keys\n* GITHUB_TOKEN is required for GitHub Models. Get a free key from https://github.com/marketplace/models\n* GOOGLE_API_KEY is required for Google Models. Get a free key from https://console.cloud.google.com\n* XAI_API_KEY is required for XAI. Get a free key from https://x.ai/api\n* GROQ_API_KEY is required for Groq. Get a free key from https://console.groq.com/\n* MISTRAL_API_KEY is required for Mistral. Get a free key from https://console.mistral.ai/\n* OPENROUTER_KEY is required for OpenRouter. Get a key from https://openrouter.ai/\n* AWS_PROFILE or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are used for Bedrock authentication. The environment must\n  already be authenticated with AWS.\n* No key required to use with Ollama or LlamaCpp.\n\n### Open AI Compatible Providers\n\nIf a specify provider is not listed but has an OpenAI compatible endpoint you can use the following combo of vars:\n* PARAI_AI_PROVIDER=OpenAI\n* PARAI_MODEL=Your selected model\n* PARAI_AI_BASE_URL=The providers OpenAI endpoint URL\n\n## Whats New\n- Version 0.2.0:\n  - Updated ai lib and other dependencies\n  - Added debug flag\n- Version 0.1.1:\n  - Updated ai lib\n  - Fixed markdown fences\n- Version 0.1.0:\n  - Initial release\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Author\n\nPaul Robello - probello@gmail.com\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2024 Paul Robello\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.",
    "summary": "Use AI vision to OCR PDF and image files to markdown.",
    "version": "0.2.0",
    "project_urls": {
        "Discussions": "https://github.com/paulrobello/par_ocr/discussions",
        "Documentation": "https://github.com/paulrobello/par_ocr/blob/main/README.md",
        "Homepage": "https://github.com/paulrobello/par_ocr",
        "Issues": "https://github.com/paulrobello/par_ocr/issues",
        "Repository": "https://github.com/paulrobello/par_ocr",
        "Wiki": "https://github.com/paulrobello/par_ocr/wiki"
    },
    "split_keywords": [
        "ai",
        " markdown",
        " ocr",
        " pdf"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "65801513ca6c7d4bf96d639b74b15d20cc720bb97a8c3cc21bcb15307e4a9210",
                "md5": "bd11deda3a2d2b1980440393f5358a68",
                "sha256": "5234250417f8712296eb9f5d9bf3adcc3e578779861bcb5844bb17b19b9bf61e"
            },
            "downloads": -1,
            "filename": "par_ocr-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bd11deda3a2d2b1980440393f5358a68",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 9903,
            "upload_time": "2025-01-26T23:17:08",
            "upload_time_iso_8601": "2025-01-26T23:17:08.139925Z",
            "url": "https://files.pythonhosted.org/packages/65/80/1513ca6c7d4bf96d639b74b15d20cc720bb97a8c3cc21bcb15307e4a9210/par_ocr-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ad052907457c01b4b4387ceaab1f24489a5f6d28fccdc8ff2cc3ef359a7d018b",
                "md5": "4e4f2784a0de0c370e0c381cae554022",
                "sha256": "fe2bb2622e1cba55796ae9fd5a3c7b48e2a4137ba158352bc09498c3dfb847c9"
            },
            "downloads": -1,
            "filename": "par_ocr-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4e4f2784a0de0c370e0c381cae554022",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 8369,
            "upload_time": "2025-01-26T23:17:10",
            "upload_time_iso_8601": "2025-01-26T23:17:10.135063Z",
            "url": "https://files.pythonhosted.org/packages/ad/05/2907457c01b4b4387ceaab1f24489a5f6d28fccdc8ff2cc3ef359a7d018b/par_ocr-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-26 23:17:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "paulrobello",
    "github_project": "par_ocr",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "par-ocr"
}
        
Elapsed time: 2.12883s