Metadata-Version: 2.1
Name: py-inkwell
Version: 0.0.2
Summary: Python library for document processing
Home-page: https://github.com/tensorlakeai/indexify
License: Apache 2.0
Author: Mohit Raghavendra
Author-email: mohithmitra@gmail.com
Requires-Python: >=3.9,<4.0
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: Pillow (>=9.5.0,<10.0.0)
Requires-Dist: accelerate (>=0.34.2,<0.35.0)
Requires-Dist: flash-attn (>=2.6.3,<3.0.0)
Requires-Dist: huggingface-hub (>=0.24.6,<0.25.0)
Requires-Dist: iopath (>=0.1.10,<0.2.0)
Requires-Dist: jupyter (>=1.0,<2.0)
Requires-Dist: jupyterlab (>=3.2,<4.0)
Requires-Dist: notebook (>=6.4,<7.0)
Requires-Dist: openai (>=1.46.1,<2.0.0)
Requires-Dist: opencv-python (>=4.10.0.84,<5.0.0.0)
Requires-Dist: pandas (>=2.2.2,<3.0.0)
Requires-Dist: pdfplumber (>=0.11.4,<0.12.0)
Requires-Dist: pydantic (>=2.8,<3.0)
Requires-Dist: pytesseract (>=0.3.13,<0.4.0)
Requires-Dist: timm (>=1.0.9,<2.0.0)
Requires-Dist: torch (>=2.3.1,<3.0.0)
Requires-Dist: torchvision (>=0.19.1,<0.20.0)
Requires-Dist: transformers (>=4.44.2,<5.0.0)
Project-URL: Repository, https://github.com/tensorlakeai/inkwell
Description-Content-Type: text/markdown

# Inkwell

Inkwell is a modular Python library for extracting information from documents. It is designed to be flexible and easy to extend, with a focus on document layout detection, OCR, and table detection. 

You can easily swap out components of the pipeline, and add your own components, using custom models or a cloud-based API.  

## Installation

```bash
pip install inkwell
```

In addition, install detectron2 and transformers from source

```bash
pip install git+https://github.com/facebookresearch/detectron2.git
pip install git+https://github.com/huggingface/transformers.git
```

Install [Tesseract](https://tesseract-ocr.github.io/tessdoc/Installation.html) for your Operating System 

#### Ubuntu

```bash
sudo apt install tesseract-ocr
sudo apt install libtesseract-dev
```

#### Mac OS

```bash
brew install tesseract
```

### Basic Usage

```python
from inkwell.pipeline import Pipeline
from inkwell import PipelineConfig

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](inkwell/pipeline/pipeline_config.py), 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. 

```python
from inkwell.pipeline import DefaultGPUPipelineConfig, Pipeline
config = DefaultGPUPipelineConfig()
pipeline = Pipeline(config=config)
```

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:

#### Layout Detection

* Faster RCNN
* LayoutLMv3

#### Table Detection

* Table Transformer

#### Table Extraction

* Table Transformer
* Phi3.5-Vision
* Qwen2 VL 2B

#### OCR

* Tesseract
* Phi 3.5-Vision
* Qwen2 VL 2B
* OpenAI GPT-4o (requires an API key)

```python
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](notebooks/demo_pipeline_custom.ipynb) notebook

### Acknowledgements

We derived inspiration from several open-source libraries in our implementation, like [Layout Parser](https://github.com/Layout-Parser/layout-parser) and [Deepdoctection](https://github.com/deepdoctection/deepdoctection). We would like to thank the contributors to these libraries for their work.

