Python library for document processing
Project description
Inkwell
Quickstart on Colab
Overview
Inkwell is a modular Python library for extracting information from PDF documents documents with state of the art Vision Language Models. We make use of layout understanding models to improve accuracy of Vision Language models. You can swap out the layout models or the vision language models pretty easily to create pipelines which work well for specific document layouts.
Inkwell uses the following models, with more integrations in the work
- Layout Detection: Faster RCNN, LayoutLMv3, Paddle
- Table Detection: Table Transformer
- Table Data Extraction: Phi3.5-Vision, Qwen2 VL 2B, Table Transformer, OpenAI 4o Mini
- OCR: Tesseract, PaddleOCR, Phi3.5-Vision, Qwen2 VL 2B
Installation
pip install py-inkwell
In addition, install detectron2
pip install git+https://github.com/facebookresearch/detectron2.git
Install Tesseract
For Ubuntu -
sudo apt install tesseract-ocr
sudo apt install libtesseract-dev
and, Mac OS
brew install tesseract
For GPUs, install flash attention for faster inference.
pip install flash-attn --no-build-isolation
Basic Usage
from inkwell.pipeline import Pipeline
pipeline = Pipeline()
document = pipeline.process("/path/to/file.pdf")
for page in document.pages:
figures = page.image_fragments()
tables = page.table_fragments()
text_blocks = page.text_fragments()
# Check the content of the image fragments
for figure in figures:
figure_image = figure.content.image
print(f"Text in figure:\n{figure.content.text}")
# Check the content of the table fragments
for table in tables:
table_image = table.content.image
print(f"Table detected: {table.content.data}")
# Check the content of the text blocks
for text_block in text_blocks:
text_block_image = text_block.content.image
print(f"Text block detected: {text_block.content.text}")
Models/Frameworks currently available
Default models: We have defined a config class here, and we use the default CPU Config in the pipeline for best results. If you want to use the default GPU pipeline, you can instantiate it with the GPU config class.
from inkwell.pipeline import DefaultGPUPipelineConfig, Pipeline
config = DefaultGPUPipelineConfig()
pipeline = Pipeline(config=config)
Changing the configuration
If you want to change the default models, you can replace them with models listed below by passing them in the config during pipeline initialization:
from inkwell.pipeline import PipelineConfig, Pipeline
from inkwell.layout_detector import LayoutDetectorType
from inkwell.ocr import OCRType
from inkwell.table_detector import TableDetectorType, TableExtractorType
config = PipelineConfig(
layout_detector=LayoutDetectorType.FASTER_RCNN,
table_extractor=TableExtractorType.PHI3_VISION,
)
pipeline = Pipeline(config=config)
Advanced Customizations
You can add custom detectors and other components to the pipeline yourself - follow the instructions in the Custom Components notebook
Acknowledgements
We derived inspiration from several open-source libraries in our implementation, like Layout Parser and Deepdoctection. We would like to thank the contributors to these libraries for their work.
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 py_inkwell-0.0.8.tar.gz
.
File metadata
- Download URL: py_inkwell-0.0.8.tar.gz
- Upload date:
- Size: 19.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/23.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c08aff582fe20e2d564d86f7f1ceb0a375d8601b2fc2c80801d96a455a695ec3 |
|
MD5 | 310976b327c2a95f51d0b79b298ef6f3 |
|
BLAKE2b-256 | 88943efb7f71f2246da34b72f5d162c6707ec747eeadb7671a1a6bed0cd32560 |
File details
Details for the file py_inkwell-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: py_inkwell-0.0.8-py3-none-any.whl
- Upload date:
- Size: 19.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/23.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7551d4227595fa71f005db388643d9b47c09a187b7af301cf0cdb1b495ffe0a3 |
|
MD5 | f5f98eaa89559b9efcb934757da23af5 |
|
BLAKE2b-256 | c121cc93025852ad338b89a6c701efb84521e023c72c9cbe98fbc4406c02981a |