Olserra/xmem-pdf-worker
0
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 namedapp), also serves the Gradio UImain.py: PDF extraction and chunking logicpyproject.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.spaceon port 7860
Usage
- Web UI: Open the Space in your browser and go to
/gradioto use the Gradio interface for PDF upload and chunking. - API:
POST /extract-pdfwith a PDF file (multipart/form-data) and optional fields:ocr: (bool) Force OCR extractionsource: (str) Source label
Example API Usage
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-pdfendpoint for programmatic PDF text extraction and chunking. - Gradio UI:
/gradioweb 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 extractionsource: (optional, str) Source label
Response:
{
"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
