CoolFace
Datasetpublic

uv-scripts/dataset-creation

Dataset Creation Scripts Ready-to-run scripts for creating Hugging Face datasets from local files. Available Scripts ๐Ÿ“„ pdf-to-dataset.py Convert directories of PDF files into Hugging Face datasets. Features: ๐Ÿ“ Uploads PDFs as dataset objects for flexible processing ๐Ÿท๏ธ Automatic labeling from folder structure ๐Ÿš€ Zero configuration - just point at your PDFs ๐Ÿ“ค Direct upload to Hugging Face Hub Usage: # Basic usage uv run pdf-to-dataset.pyโ€ฆ See the full description on the dataset page: https://huggingface.co/datasets/uv-scripts/dataset-creation.

sourceHugging Faceupdated 1y agoView on Hugging Face
7likes72downloads
Dataset Card

Dataset Creation Scripts

Ready-to-run scripts for creating Hugging Face datasets from local files.

Available Scripts

๐Ÿ“„ pdf-to-dataset.py

Convert directories of PDF files into Hugging Face datasets.

Features:

  • โ€”๐Ÿ“ Uploads PDFs as dataset objects for flexible processing
  • โ€”๐Ÿท๏ธ Automatic labeling from folder structure
  • โ€”๐Ÿš€ Zero configuration - just point at your PDFs
  • โ€”๐Ÿ“ค Direct upload to Hugging Face Hub

Usage:

bash
# Basic usage
uv run pdf-to-dataset.py /path/to/pdfs username/my-dataset

# Create private dataset
uv run pdf-to-dataset.py /path/to/pdfs username/my-dataset --private

# Organized by categories (folder structure creates labels)
# /pdfs/invoice/doc1.pdf โ†’ label: "invoice"
# /pdfs/receipt/doc2.pdf โ†’ label: "receipt"
uv run pdf-to-dataset.py /path/to/organized-pdfs username/categorized-docs

Output Format: The script creates a dataset where each example contains a pdf object that can be processed using the datasets library. Users can then extract text, convert to images, or perform other operations as needed.

python
from datasets import load_dataset

# Load your uploaded dataset
dataset = load_dataset("username/my-dataset")

# Access PDF objects
pdf = dataset["train"][0]["pdf"]

Requirements:

  • โ€”Directory containing PDF files
  • โ€”Hugging Face account (for uploading)
  • โ€”No GPU needed - runs on CPU

Installation

No installation needed! Just run with uv:

bash
# Run directly from GitHub
uv run https://huggingface.co/datasets/uv-scripts/dataset-creation/resolve/main/pdf-to-dataset.py --help

# Or clone and run locally
git clone https://huggingface.co/datasets/uv-scripts/dataset-creation
cd dataset-creation
uv run pdf-to-dataset.py /path/to/pdfs my-dataset

Authentication

Scripts use Hugging Face authentication:

  1. 1.Pass token via --hf-token argument
  2. 2.Set HF_TOKEN environment variable
  3. 3.Use cached credentials from huggingface-cli login

Examples

Create a Dataset from Research Papers

bash
uv run pdf-to-dataset.py ~/Documents/papers username/research-papers

Organize Documents by Type

bash
# Directory structure:
# documents/
# โ”œโ”€โ”€ invoices/
# โ”‚   โ”œโ”€โ”€ invoice1.pdf
# โ”‚   โ””โ”€โ”€ invoice2.pdf
# โ””โ”€โ”€ receipts/
#     โ”œโ”€โ”€ receipt1.pdf
#     โ””โ”€โ”€ receipt2.pdf

uv run pdf-to-dataset.py documents/ username/financial-docs
# Creates dataset with labels: "invoices" and "receipts"

Tips

  • โ€”Large PDFs: The script handles large PDFs efficiently by uploading them as objects
  • โ€”Organization: Use subdirectories to automatically create labeled datasets
  • โ€”Privacy: Use --private flag for sensitive documents
  • โ€”Processing: After upload, use the datasets library to extract text, images, or metadata as needed

License

MIT