OCR & Document Extraction using vision models
A dead simple way of OCR-ing a document for AI ingestion. Documents are meant to be a visual representation after all. With weird layouts, tables, charts, etc. The vision models just make sense!
The general logic:
Try out the hosted version here: https://getomni.ai/ocr-demo Or visit our full documentation at: https://docs.getomni.ai/zerox
Zerox is available as both a Node and Python package.
| Feature | Node.js | Python |
|---|---|---|
| PDF Processing | ✓ (requires graphicsmagick) | ✓ (requires poppler) |
| Image Processing | ✓ | ✓ |
| OpenAI Support | ✓ | ✓ |
| Azure OpenAI Support | ✓ | ✓ |
| AWS Bedrock Support | ✓ | ✓ |
| Google Gemini Support | ✓ | ✓ |
| Vertex AI Support | ✗ | ✓ |
| Data Extraction | ✓ (schema) |
✗ |
| Per-page Extraction | ✓ (extractPerPage) |
✗ |
| Custom System Prompts | ✗ | ✓ (custom_system_prompt) |
| Maintain Format Option | ✓ (maintainFormat) |
✓ (maintain_format) |
| Async API | ✓ | ✓ |
| Error Handling Modes | ✓ (errorMode) |
✗ |
| Concurrent Processing | ✓ (concurrency) |
✓ (concurrency) |
| Temp Directory Management | ✓ (tempDir) |
✓ (temp_dir) |
| Page Selection | ✓ (pagesToConvertAsImages) |
✓ (select_pages) |
| Orientation Correction | ✓ (correctOrientation) |
✗ |
| Edge Trimming | ✓ (trimEdges) |
✗ |
(Node.js SDK - supports vision models from different providers like OpenAI, Azure OpenAI, Anthropic, AWS Bedrock, Google Gemini, etc.)
npm install zeroxZerox uses graphicsmagick and ghostscript for the PDF => image processing step. These should be pulled automatically, but you may need to manually install.
On linux use:
sudo apt-get update
sudo apt-get install -y graphicsmagickWith file URL
import { zerox } from "zerox";
const result = await zerox({
filePath: "https://omni-demo-data.s3.amazonaws.com/test/cs101.pdf",
credentials: {
apiKey: process.env.OPENAI_API_KEY,
},
});From local path
import { zerox } from "zerox";
import path from "path";
const result = await zerox({
filePath: path.resolve(__dirname, "./cs101.pdf"),
credentials: {
apiKey: process.env.OPENAI_API_KEY,
},
});…The maintainFormat option tries to return the markdown in a consistent format by passing the output of a prior page in as additional context for the next page. This requires the requests to run synchronously, so it's a lot slower. But valuable if your documents have a lot of tabular data, or frequently have tables that cross pages.
Request #1 => page_1_image
Request #2 => page_1_markdown + page_2_image
Request #3 => page_2_markdown + page_3_image…Zerox supports structured data extraction from documents using a schema. This allows you to pull specific information from documents in a structured format instead of getting the full markdown conversion.
Set extractOnly: true and provide a schema to extract structured data. The schema follows the JSON Schema standard.
Use extractPerPage to extract data per page instead of from the whole document at once.
You can also set extractionModel, extractionModelProvider, and extractionCredentials to use a different model for extraction than OCR. By default, the same model is used.
Zerox supports a wide range of models across different providers:
Azure OpenAI
OpenAI
AWS Bedrock
Google Gemini
…(Python SDK - supports vision models from different providers like OpenAI, Azure OpenAI, Anthropic, AWS Bedrock, etc.)
pip install py-zeroxThe pyzerox.zerox function is an asynchronous API that performs OCR (Optical Character Recognition) to markdown using vision models. It processes PDF files and converts them into markdown format. Make sure to set up the environment variables for the model and the model provider before using this API.
Refer to the LiteLLM Documentation for setting up the environment and passing the correct model name.
…async def zerox(
cleanup: bool = True,
concurrency: int = 10,
file_path: Optional[str] = "",
maintain_format: bool = False,
model: str = "gpt-4o-mini",
output_dir: Optional[str] = None,
temp_dir: Optional[str] = None,
custom_system_prompt: Optional[str] = None,
select_pages: Optional[Union[int, Iterable[int]]] = None,
**kwargs
) -> ZeroxOutput:
...Parameters
Returns
Note the output is manually wrapped for this documentation for better readability.
…java\n' + 'int numUnits;\n' + 'double costPerUnit;\n' + 'char firstInitial;\n' + 'boolean isStudent;\n' + '
…`
We use a combination of libreoffice and graphicsmagick to do document => image conversion. For non-image / non-PDF files, we use libreoffice to convert that file to a PDF, and then to an image.
…This project is licensed under the MIT License.
OS command injection via document URL extension reaches pdfinfo/pdftoppm shell exec (unauthenticated RCE)
[Python SDK] Feature Parity Gap: `errorMode`, `correctOrientation`, `trimEdges`, `schema`, and `extractPerPage` Missing vs Node.js SDK
Support passing api_key via kwargs instead of only environment variables
Jay shree ram
Ashish Kumar mahato
Mahato
Ai dubbing
Jay shree ram
Security Vulnerabilities in SheetJS Dependency (xlsx npm package)
Output repeats