FastAPI + RQ + Redis service that runs OCR on PDFs and images using the LightOnOCR-2-1B vision-language model. Jobs are queued, processed by workers, and results are returned as structured JSON that can be converted to Markdown.
- Upload a PDF or image and queue OCR in Redis
- Background workers run the model and return per-page text
- Simple status endpoint for job polling
- Utility CLI to convert OCR JSON output to Markdown
POST /process_file(multipart file upload)GET /jobs/{job_id}GET /health
Example:
curl -X POST "http://localhost:8000/process_file" -F "file=@sample.pdf"- Install dependencies:
pip install -r requirements.txt- Set environment variables (see
.env.example). - Start Redis (local or Docker).
- Start the API:
uvicorn app.main:app --host 0.0.0.0 --port 8000- Start a worker:
cd app
rq worker OCR_TASK_QUEUEdocker-compose up --buildConvert OCR JSON output to Markdown:
python -m app.utils.ocr_to_md path/to/ocr.jsonWrite to a specific file:
python -m app.utils.ocr_to_md path/to/ocr.json -o output.mdREDIS_HOSTREDIS_PORTREDIS_QUEUE_NAMEHF_TOKEN(optional, for Hugging Face access)
This project uses the LightOnOCR-2-1B model from Hugging Face, which is described as a flagship OCR model and is licensed under Apache-2.0. The model card and details are available on Hugging Face.