ocr-server

OCR Server

A lightweight and async OCR server powered by FastAPI, Celery, EasyOCR, and Redis. Supports image and PDF OCR using CPU.


Features


๐Ÿ“ Project Structure

ocr-server/
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ __main__.py       # FastAPI app entrypoint
โ”‚   โ”œโ”€โ”€ worker.py         # Celery worker app
โ”‚   โ”œโ”€โ”€ tasks.py          # Celery OCR task
โ”‚   โ”œโ”€โ”€ ocr_engine.py     # EasyOCR logic
โ”‚   โ”œโ”€โ”€ utils.py          # PDF/Image tools
โ”‚   โ””โ”€โ”€ config.py         # Paths & settings

โš™๏ธ Requirements


๐Ÿณ Run with Docker

docker-compose up --build

๐Ÿ“ก API Endpoints

Submit OCR task

POST /ocr
Form-Data: file=@yourfile.pdf

Get result

GET /result/{task_id}

โœ… Example Response

{
  "status": "completed",
  "result": {
    "type": "pdf",
    "pages": [
      {
        "page": 1,
        "text": [
          {
            "text": "Hello World",
            "confidence": 0.98,
            "box": [[x1, y1], [x2, y2], ...]
          }
        ]
      }
    ]
  }
}

๐Ÿงช Test with curl

curl -F "file=@sample.pdf" http://localhost:8000/ocr
curl http://localhost:8000/result/<task_id>