Documents and large language models.
Project description
About
Docprompt is a library for Document AI. It aims to make enterprise-level document analysis easy thanks to the zero-shot capability of large language models.
Supercharged Document Analysis
- Common utilities for interacting with PDFs
- PDF loading and serialization
- PDF byte compression using Ghostscript :ghost:
- Fast rasterization :fire: :rocket:
- Page splitting, re-export with PDFium
- Document Search, powered by Rust :fire:
- Support for most OCR providers with batched inference
- Google :white_check_mark:
- Azure Document Intelligence :red_circle:
- Amazon Textract :red_circle:
- Tesseract :red_circle:
- Prompt Garden for common document analysis tasks zero-shot, including:
- Table Extraction
- Page Classification
- Segmentation
- Key-value extraction
Documents and large language models
- Documentation: https://docprompt.dev
- GitHub: https://github.com/Page-Leaf/docprompt
- PyPI: https://pypi.org/project/docprompt/
- Free software: Apache-2.0
Features
- Representations for common document layout types -
TextBlock
,BoundingBox
, etc - Generic implementations of OCR providers
- Document Search powered by Rust and R-trees :fire:
Installation
Use the package manager pip to install Docprompt.
pip install docprompt
With an OCR provider
pip install "docprompt[google]
With search support
pip install "docprompt[search]"
Usage
Simple Operations
from docprompt import load_document
# Load a document
document = load_document("path/to/my.pdf")
# Rasterize a single page using Ghostscript
page_number = 5
rastered = document.rasterize_page(page_number, dpi=120)
# Split a pdf based on a page range
document_2 = document.split(start=125, stop=130)
Performing OCR
from docprompt import load_document, DocumentNode
from docprompt.tasks.ocr.gcp import GoogleOcrProvider
provider = GoogleOcrProvider.from_service_account_file(
project_id=my_project_id,
processor_id=my_processor_id,
service_account_file=path_to_service_file
)
document = load_document("path/to/my.pdf")
# A container holds derived data for a document, like OCR or classification results
document_node = DocumentNode.from_document(document)
provider.process_document_node(document_node) # Caches results on the document_node
document_node[0].ocr_result # Access OCR results
Document Search
When a large language model returns a result, we might want to highlight that result for our users. However, language models return results as text, while what we need to show our users requires a page number and a bounding box.
After extracting text from a PDF, we can support this pattern using DocumentProvenanceLocator
, which lives on a DocumentNode
from docprompt import load_document, DocumentNode
from docprompt.tasks.ocr.gcp import GoogleOcrProvider
provider = GoogleOcrProvider.from_service_account_file(
project_id=my_project_id,
processor_id=my_processor_id,
service_account_file=path_to_service_file
)
document = load_document("path/to/my.pdf")
# A container holds derived data for a document, like OCR or classification results
document_node = DocumentNode.from_document(document)
provider.process_document_node(document_node) # Caches results on the document_node
# With OCR results available, we can now instantiate a locator and search through documents.
document_node.locator.search("John Doe") # This will return a list of all terms across the document that contain "John Doe"
document_node.locator.search("Jane Doe", page_number=4) # Just return results a list of matching results from page 4
This functionality uses a combination of rtree
and the Rust library tantivy
, allowing you to perform thousands of searches in seconds :fire: :rocket:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file docprompt-0.2.1.tar.gz
.
File metadata
- Download URL: docprompt-0.2.1.tar.gz
- Upload date:
- Size: 295.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-25-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9ade3e450102fdc47d2867a423d739ad6f79bec12de7c9ba0a770d0eabb4399 |
|
MD5 | 07c92b1557cfb115cbed3168dabed47e |
|
BLAKE2b-256 | 7e9106c7329f0b09fd4e7004be6c09b31890b1568b9b5211b18213d95c2bb3c1 |
File details
Details for the file docprompt-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: docprompt-0.2.1-py3-none-any.whl
- Upload date:
- Size: 32.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-25-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bba842a27965b984fa9b1d55fe8c21cbfea96ba7f3daa0ed28d4883f01517491 |
|
MD5 | 4a887a15353337ba55f2a6dd307e3eac |
|
BLAKE2b-256 | ea0cd9834480a45f41d27f65de2ed06e51a1f5978be125044c7d2f5d5ab467f6 |