Skip to main content

No project description provided

Project description

PDF Segmentation

PDF Segmentation is a utility for parsing PDFs into structured page-range chunks using LLMs, designed for downstream processing such as image conversion, question extraction, derivations, and document analysis.

It is intended to sit at the front of a PDF processing pipeline, handling segmentation and orchestration.


Features

  • LLM-driven PDF segmentation into page ranges
  • Schema-validated, structured outputs
  • PDF → image conversion utilities
  • PDF page and range splitting
  • Multimodal (PDF + image) LLM support

Core Components

Segmentation Graph

from graph.graph import (
    graph as PDFSegmentation,
    Section,
    ListOutput,
    State as SegmentationInput,
)
  • PDFSegmentation – main graph entry point
  • Section – base class for output units
  • ListOutput[T] – typed LLM output container
  • State – input configuration for segmentation

The graph:

  • Accepts a PDF (path or bytes)
  • Invokes an LLM
  • Returns schema-validated segmentation results

PDF Utilities

PDF → Images

from pdf_image_converter import PDFImageConverter

PDF Page Splitting

from pdf_seperator import PDFSeperator

Multimodal LLM Invocation

from pdf_llm import PDFMultiModalLLM

Example

Define an Output Schema

from typing import Literal, List
from pydantic import BaseModel
from graph.graph import Section, ListOutput

class MySection(Section, BaseModel):
    title: str
    description: str
    section_type: Literal["derivation", "question"]

class MySections(ListOutput[MySection]):
    items: List[MySection]

Run Segmentation

from pathlib import Path
from graph.graph import graph, State

result = graph.invoke(
    State(
        pdf=Path("data/Lecture_02_03.pdf"),
        prompt="Extract the content into these chunks",
        output_schema=MySections,
    )
)

Input State

class State(BaseModel, Generic[T]):
    pdf: str | Path
    prompt: str
    pdf_bytes: bytes | None = None

    output_schema: Type[ListOutput[T]] = Field(exclude=True)
    raw_output: List[T] = []
    parsed: list[ParsedUnit[T]] = Field(default_factory=list)

    @field_serializer("pdf_bytes")
    def serialize_pdf_bytes(self, value: bytes):
        return base64.b64encode(value).decode("ascii")

Notes

  • Provide either pdf or pdf_bytes
  • output_schema controls the LLM output structure
  • parsed contains validated segmentation results

Typical Pipeline

PDF → LLM Segmentation → Page Ranges
   → PDF Splitter
   → PDF → Image Conversion
   → Downstream Processing

Common use cases include lecture parsing, educational content generation, and document analysis.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdf_segmentation-1.0.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdf_segmentation-1.0.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file pdf_segmentation-1.0.0.tar.gz.

File metadata

  • Download URL: pdf_segmentation-1.0.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.7 Windows/11

File hashes

Hashes for pdf_segmentation-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ea0bda37befb4eaa6f1289b4e6eac0fd3879310543c47fbedb05c3e47860f90d
MD5 876c73c547c0084e3b25da391ca6ec7c
BLAKE2b-256 d3235052968d1b1823839f786ec695ae1e882c04618a3e9d46b4c4f3524f45c3

See more details on using hashes here.

File details

Details for the file pdf_segmentation-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pdf_segmentation-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.7 Windows/11

File hashes

Hashes for pdf_segmentation-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d9b0833486da28ccad4982561c6c9db6f1c260057ed2b3723d9fec5d5464a4b
MD5 c96dd8b63cba663fc2d39c07753d7136
BLAKE2b-256 87c6190adcb5daa9d3e3ae3355d8684368a13ab9ad6b6c27851869938d9c5254

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page