This repository contains a FastAPI-based backend for document processing using YOLO-based layout detection, OCR-based table extraction, and OneChart-based chart analysis.
- Detects tables, charts, images, and figures from PDF or image files.
- Crops and classifies regions using a custom YOLO model.
- Preloads the model at startup for fast inference.
- Applies OCR on detected table regions.
- Auto-detects table rows/columns using bounding box clustering.
- Returns structured JSON output ready for UI display.
- Extracts key information from charts using the OneChart transformer model.
- Gracefully handles CUDA errors and switches to CPU fallback.
- Uses timeouts to prevent long-running GPU operations.
ChartOCR / OneChart currently fails or times out due to insufficient
GPU VRAM.
On systems with low compute resources, chart analysis will return
"status": "failed" or "timeout".
git clone <repo-url>
cd <project-folder>You must install dependencies manually or via requirements.txt.
Example:
conda create -n doc-process python=3.10
conda activate doc-process
pip install -r requirements.txtRequired for pdf2image.
sudo apt install poppler-utilsDownload from:
https://github.com/oschwartz10612/poppler-windows
uvicorn main:app --reloadServer runs at:
http://127.0.0.1:8000
GET /health
POST /upload_and_process/
Payload: - PDF, PNG, JPG files - Optional flag analyze_charts=true
Returns: - Layout detections\
- Extracted table data\
- Chart images & analysis (if enabled)\
- Summary statistics
main.py ← Main FastAPI application
models/ ← YOLO model files (custom)
utils/ ← OCR + processing utilities
- Causes CUDA OOM or inference timeout
- CPU fallback works but is very slow
- Expected output:
"status": "failed","timeout", or"skipped"
- Consider switching to PaddleOCR or Tesseract if speed is required.
Set environment variable:
export YOLO_MODEL_PATH="path/to/model.pt"POST /upload_and_process/?analyze_charts=falseMIT License (modify as per your project needs)
If you need a documentation site, Postman collection, or frontend integration, I can generate those as well.