Skip to main content

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.
  • Generate annotated images showing detected elements.
  • (Optional) Perform OCR on detected elements using Azure Document Intelligence.
  • Save structured document data (layouts, chunks, OCR text) in JSON format.

Installation

Prerequisites

  • Python 3.10+
  • Pip package manager
  • (Optional but Recommended) CUDA-capable GPU for YOLO model inference acceleration.

Steps

  1. Install the Package:
    # pip install cv-doc-chunker
    

User-Provided Data

This package requires the user to provide certain data externally:

  1. 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.
  2. 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

# --- Initialize and Run ---
processor = PDFProcessor(model_path=model_path, output_dir=output_dir)

# Process the document (layout detection, chunking, etc.)
results = processor.process_document(pdf_path=input_pdf_path)

print(f"Processing complete. Results saved in {output_dir}")

Understanding the Output

After running the parser, the following outputs will typically be available in the specified output_dir:

  1. {your-document}_parsed.json: JSON file containing the detected document structure (element labels, coordinates, confidence).
  2. {your-document}_annotations/: Directory containing annotated images showing the detected elements for each page (if generate_annotations=True).
  3. {your-document}_boxes/: Directory containing individual images for each detected element, organized by page number (if save_bounding_boxes=True). This is required for OCR.
  4. {your-document}_sorted_text.json: (Only if ocr=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.

Metadata

Release files for cv-doc-chunker 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cv-doc-chunker 0.2.2
File Size Uploaded
cv_doc_chunker-0.2.2.tar.gz 25.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cv-doc-chunker 0.2.2
File Interpreter ABI Platform
cv_doc_chunker-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 50.0 kB

Release files / cv_doc_chunker-0.2.2.tar.gz

Download URL cv_doc_chunker-0.2.2.tar.gz
Size 25.0 kB
Tags Source
SHA-256 checksum
How to use checksums
09bfca2a3b25c8e6831132ef41b7244639d3515acded10ae767893bea48240db
BLAKE2b-256 checksum
How to use checksums
81052ee1d24edfa5c0e95e80a147454f33e2bcf9397bc47d2f324db8a617acd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.14

Release files / cv_doc_chunker-0.2.2-py3-none-any.whl

Download URL cv_doc_chunker-0.2.2-py3-none-any.whl
Size 25.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7bd190fc62cec6e2e7d1fd4c01d1097f087922e961d88cb283fe735e2c3ac606
BLAKE2b-256 checksum
How to use checksums
b345465e1101cad84bd35127c4d611d74273ccb34cf9bbb1f98e6117edd8ca0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.14

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page