CoolFace
Apppublic

Olserra/xmem-pdf-worker

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

xmem PDF Extraction Service for Hugging Face Spaces

This project provides a hybrid FastAPI + Gradio backend for extracting and chunking text from PDFs, with optional OCR support. Designed to run on Hugging Face Spaces (Docker SDK, free tier).

Project Structure

  • app.py: FastAPI entrypoint (app is named app), also serves the Gradio UI
  • main.py: PDF extraction and chunking logic
  • pyproject.toml / poetry.lock: Python dependencies (managed by Poetry)
  • Dockerfile: For building and running the app on Hugging Face Spaces

Deployment

  • Push this directory to your Hugging Face Space (Docker SDK)
  • The service will be available at https://<your-space>.hf.space on port 7860

Usage

  • Web UI: Open the Space in your browser and go to /gradio to use the Gradio interface for PDF upload and chunking.
  • API:
  • POST /extract-pdf with a PDF file (multipart/form-data) and optional fields:
  • ocr: (bool) Force OCR extraction
  • source: (str) Source label

Example API Usage

bash
curl -X POST "https://<your-space>.hf.space/extract-pdf" \
  -F "file=@yourfile.pdf" \
  -F "ocr=false" \
  -F "source=upload"

For more information, see the Hugging Face Spaces documentation.

Features

  • REST API: /extract-pdf endpoint for programmatic PDF text extraction and chunking.
  • Gradio UI: /gradio web interface for easy PDF upload and testing.
  • OCR Support: Uses Tesseract and pdf2image for image-based PDFs.
  • CORS Enabled: Ready for integration with web frontends (e.g., Next.js).

Usage

API

POST /extract-pdf

  • file: PDF file (multipart/form-data)
  • ocr: (optional, bool) Force OCR extraction
  • source: (optional, str) Source label

Response:

json
{
  "chunks": [
    {
      "text": "chunked text...",
      "metadata": {
        "page": 1,
        "chunk": 0,
        "source": "upload"
      }
    },
    ...
  ]
}

Gradio UI

Visit /gradio to upload a PDF and view the extracted chunks in your browser.

Deployment

This Space uses a Dockerfile for full reproducibility and system dependencies (Tesseract, Poppler). All dependencies are managed via Poetry.


Maintainer: Olserra