A tool for parsing PDF document layouts and chunking content
Project description
CV Document Chunker
A Python package for parsing PDF document layouts using YOLO models, chunking content based on layout, and optionally performing OCR.
Features
- Convert PDF documents to images for processing.
- Detect document layout elements (e.g., paragraphs, tables, figures) using YOLO.
- Process and refine bounding boxes.
- Chunk document content based on detected layout.
- (Optional) Perform OCR on detected elements using Azure Document Intelligence.
- Save structured document data (layouts, chunks, OCR text) in JSON format.
- Get paragraph embeddings using OpenAI embedder
Installation
Prerequisites
- Python 3.10+
- Pip package manager
- (Optional but Recommended) CUDA-capable GPU for YOLO model inference acceleration.
Steps
- Install the Package:
# pip install cv-doc-chunker
User-Provided Data
This package requires the user to provide certain data externally:
- Input Directory (
input/): Place the PDF documents you want to process in a directory (e.g.,input/). You will need to provide the path to your input file(s) when using the package. - Models Directory (
models/): Download the necessary YOLO model(s) (e.g.,doclayout_yolo_docstructbench_imgsz1024.pt) and place them in a dedicated directory (e.g.,models/). The path to this directory (or the specific model file) will be needed by the parser.
Usage
Provide examples of how to import and use your library functions or the command-line tool.
Example (Conceptual Python Usage):
from cv_doc_chunker import PDFProcessor
# --- User Configuration ---
input_pdf_path = "path/to/your/input/document.pdf" # Path to user's PDF
model_path = "path/to/your/models/doclayout_yolo.pt" # Path to user's model
output_dir = "path/to/your/output/" # Directory to save results
parser = PDFParser(ocr = True, embed = True, yolo_model_path = model_path, azure_key = "api key for azure ocr",
azure_endpoint = "api endpoint for azure ocr", openai_api_key = openai_api_key)
# --- OR ---
# For Azure OpenAI embeddings, you would use these arguments instead:
# azure_openai_api_key=azure_openai_api_key,
# azure_openai_api_version=azure_openai_api_version,
# azure_openai_endpoint=azure_openai_endpoint
results = parser.parse_document(input_pdf_path, output_dir=output_dir, use_tesseract = True)
Understanding the Output
After running the parser, the following outputs will typically be available in the specified output_dir:
{your-document}_parsed.json: JSON file containing the detected document structure (element labels, coordinates, confidence).{your-document}_annotations/: Directory containing annotated images showing the detected elements for each page (ifgenerate_annotations=True).{your-document}_boxes/: Directory containing individual images for each detected element, organized by page number (ifsave_bounding_boxes=True). This is required for OCR.{your-document}_sorted_text.json: (Only ifocr=True) JSON file containing the extracted text for each element, sorted according to the structure defined in_parsed.json.
If debug mode is enabled (debug_mode=True), additional debug images might be saved, typically in a debug/ subdirectory within the output_dir, showing intermediate steps of the parsing process.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kiwi_pdf_chunker-0.1.1.tar.gz.
File metadata
- Download URL: kiwi_pdf_chunker-0.1.1.tar.gz
- Upload date:
- Size: 26.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24b18a7300ebf5d14aba9446102ae4316330754dfaa1ee94aad282fdd972fe2e
|
|
| MD5 |
a5b2b1dffc2298b5d2b38aaeda82dc70
|
|
| BLAKE2b-256 |
5db7eeb4336a52f2bf5f2fa0dfcb8e0fc8c730e6aba6def8b9297b0865caff65
|
File details
Details for the file kiwi_pdf_chunker-0.1.1-py3-none-any.whl.
File metadata
- Download URL: kiwi_pdf_chunker-0.1.1-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45ccde3f7d4bbe02fa4fd8d6873724e5c75706865e2587119c995f01beb8c738
|
|
| MD5 |
d2d5205a80c2b3d494d67a3891b751fa
|
|
| BLAKE2b-256 |
27b11b97ecd431b563d578265f390edb30dd28938b68e20d847a346e97250780
|