VemorPhose/Adobe-India-Hackathon25-1a

0

stars

30

commits

Python

primary language

Jul 28, 2025

updated

README

Challenge 1A – Heading Structure Extraction from PDF (Tiny LayoutLM)

This repository contains an offline, CPU-only solution for Adobe India Hackathon 2025 - Challenge 1A. It extracts the title and hierarchical headings (H1, H2, H3) from a PDF document and outputs a JSON in the specified format.

The model uses a Tiny LayoutLM-style architecture to classify each line of text using both layout and textual features. It is designed to run within strict constraints:

  • < 10 seconds for a 50-page PDF
  • 🧠 ≤ 200 MB model size
  • 💻 CPU-only, 8 cores, 16 GB RAM
  • 🌐 Offline execution (no network access)

🗂️ Project Structure

Challenge_1A/
├── app/
│   ├── process_pdfs.py             # Entry point
│   ├── pdf_utils.py                # PDF text + layout extraction
│   ├── classify_headings.py        # Tiny LayoutLM inference wrapper
│   └── model/                      # Pretrained model files (≤200MB)
│       ├── config.json
│       ├── pytorch_model.bin
│       └── tokenizer/
│           └── vocab.txt
├── requirements.txt
├── Dockerfile
└── README.md

🔧 How It Works

  1. Text + Layout Extraction:

    • Extract lines from PDFs using PyMuPDF.
    • For each line: gather bounding box, font size, bold flag.
  2. Tokenization + Embeddings:

    • Tokenize line text using HuggingFace tokenizer.
    • Layout (bbox) is converted to 2D position embeddings.
  3. Classification:

    • Use a Tiny LayoutLM model to classify each line as Title, H1, H2, H3, or Other.
  4. Output:

    • JSON per PDF in /app/output, matching required schema.

🐳 Dockerized Execution

This solution runs entirely in a Docker container on linux/amd64 without any internet connection.

🔨 Build Image

docker build --platform linux/amd64 -t pdf-headings .

🚀 Run Container

docker run --rm \\
  -v $(pwd)/input:/app/input:ro \\
  -v $(pwd)/output:/app/output \\
  --network none \\
  pdf-headings
  • Place your .pdf files in input/ folder.
  • Processed .json files will be saved to output/.

⚙️ Manual Setup (Without Docker)

Requirements:

pip install -r requirements.txt

Run Script:

python app/process_pdfs.py

Input and output paths are hardcoded to /app/input and /app/output. You may change these for local use.


📤 Output Format (Example)

{
  "title": "Introduction to Document AI",
  "outline": [
    { "level": "H1", "text": "Overview", "page": 0 },
    { "level": "H2", "text": "Challenges", "page": 1 },
    { "level": "H3", "text": "Scanned PDFs", "page": 2 }
  ]
}

📦 Model Information

  • Uses a Tiny LayoutLM / LiLT-style model pre-trained on document classification tasks.
  • Model is bundled inside /app/model/ and ≤ 200 MB in size.
  • No fine-tuning required — generalizes across domains reasonably well.

🧪 Testing Notes

  • Tested on both native and OCR’d PDFs (though OCR not enabled by default).
  • Best accuracy on native PDFs with font/size metadata.
  • You may extend pdf_utils.py to add OCR fallback (e.g., ocrmypdf + Tesseract).

🛠️ TODO (Optional Enhancements)

  • Batch processing for speed optimization.
  • OCR integration for scanned PDFs.
  • Better heading hierarchy using numbering detection (e.g. 1., 1.2).

🧑‍💻 Contact / Maintainer

Feel free to reach out for queries, suggestions, or collaboration ideas related to this project.


Contributors

VemorPhose

22 commits

ShouryaAswal

6 commits

Pranita1305

2 commits

VemorPhose/Adobe-India-Hackathon25-1a

0

stars

30

commits

Python

primary language

Jul 28, 2025

updated

README

Challenge 1A – Heading Structure Extraction from PDF (Tiny LayoutLM)

This repository contains an offline, CPU-only solution for Adobe India Hackathon 2025 - Challenge 1A. It extracts the title and hierarchical headings (H1, H2, H3) from a PDF document and outputs a JSON in the specified format.

The model uses a Tiny LayoutLM-style architecture to classify each line of text using both layout and textual features. It is designed to run within strict constraints:

  • < 10 seconds for a 50-page PDF
  • 🧠 ≤ 200 MB model size
  • 💻 CPU-only, 8 cores, 16 GB RAM
  • 🌐 Offline execution (no network access)

🗂️ Project Structure

Challenge_1A/
├── app/
│   ├── process_pdfs.py             # Entry point
│   ├── pdf_utils.py                # PDF text + layout extraction
│   ├── classify_headings.py        # Tiny LayoutLM inference wrapper
│   └── model/                      # Pretrained model files (≤200MB)
│       ├── config.json
│       ├── pytorch_model.bin
│       └── tokenizer/
│           └── vocab.txt
├── requirements.txt
├── Dockerfile
└── README.md

🔧 How It Works

  1. Text + Layout Extraction:

    • Extract lines from PDFs using PyMuPDF.
    • For each line: gather bounding box, font size, bold flag.
  2. Tokenization + Embeddings:

    • Tokenize line text using HuggingFace tokenizer.
    • Layout (bbox) is converted to 2D position embeddings.
  3. Classification:

    • Use a Tiny LayoutLM model to classify each line as Title, H1, H2, H3, or Other.
  4. Output:

    • JSON per PDF in /app/output, matching required schema.

🐳 Dockerized Execution

This solution runs entirely in a Docker container on linux/amd64 without any internet connection.

🔨 Build Image

docker build --platform linux/amd64 -t pdf-headings .

🚀 Run Container

docker run --rm \\
  -v $(pwd)/input:/app/input:ro \\
  -v $(pwd)/output:/app/output \\
  --network none \\
  pdf-headings
  • Place your .pdf files in input/ folder.
  • Processed .json files will be saved to output/.

⚙️ Manual Setup (Without Docker)

Requirements:

pip install -r requirements.txt

Run Script:

python app/process_pdfs.py

Input and output paths are hardcoded to /app/input and /app/output. You may change these for local use.


📤 Output Format (Example)

{
  "title": "Introduction to Document AI",
  "outline": [
    { "level": "H1", "text": "Overview", "page": 0 },
    { "level": "H2", "text": "Challenges", "page": 1 },
    { "level": "H3", "text": "Scanned PDFs", "page": 2 }
  ]
}

📦 Model Information

  • Uses a Tiny LayoutLM / LiLT-style model pre-trained on document classification tasks.
  • Model is bundled inside /app/model/ and ≤ 200 MB in size.
  • No fine-tuning required — generalizes across domains reasonably well.

🧪 Testing Notes

  • Tested on both native and OCR’d PDFs (though OCR not enabled by default).
  • Best accuracy on native PDFs with font/size metadata.
  • You may extend pdf_utils.py to add OCR fallback (e.g., ocrmypdf + Tesseract).

🛠️ TODO (Optional Enhancements)

  • Batch processing for speed optimization.
  • OCR integration for scanned PDFs.
  • Better heading hierarchy using numbering detection (e.g. 1., 1.2).

🧑‍💻 Contact / Maintainer

Feel free to reach out for queries, suggestions, or collaboration ideas related to this project.


Contributors

VemorPhose

22 commits

ShouryaAswal

6 commits

Pranita1305

2 commits

Languages

Python

98.7%

Dockerfile

1.3%