This repository contains a FastAPI application that uses Tesseract OCR to extract text from images and PDFs. The application exposes several endpoints to upload files, retrieve analysis results, generate searchable PDFs, and check the health of the service.
- ✅ OCR on Images and PDFs
- ✅ REST Endpoints
- ✅ Sync / Async Support
- ✅ Create searchable PDFs
- ✅ Add more languages with ease
docker pull jannichorst/tesseract-ocr:latest
docker run -d -p 8000:8000 jannichorst/tesseract-ocr:latest
Access the Swagger documentation under http://localhost:8000/docs.
import requests
url = "http://localhost:8000/ocr/"
file_path = "path_to_your_image_or_pdf.jpg"
with open(file_path, "rb") as file:
files = {"file": file}
response = requests.post(url, files=files)
print("OCR Result:", response.json())
Note
Check out more examples in the demo.iypnb notebook
- URL:
/ocr/
- Method:
POST
- Request: Multipart/form-data with a file, language (default: "eng"), DPI (optional), config (optional), and PSM (default: 3)
- Response: JSON containing OCR results and job information
Example using curl
:
curl -X POST "http://localhost:8000/ocr/" -F "file=@path_to_your_file"
- URL:
/start_ocr/
- Method:
POST
- Request: Multipart/form-data with a file, language (default: "eng"), DPI (optional), config (optional), and PSM (default: 3)
- Response: JSON containing a task ID
Example using curl
:
curl -X POST "http://localhost:8000/start_ocr/" -F "file=@path_to_your_file"
- URL:
/results/{task_id}
- Method:
GET
- Request: Path parameter with the task ID
- Response: JSON containing the OCR results or the status of the task
Example using curl
:
curl "http://localhost:8000/results/{task_id}"
- URL:
/create_searchable/
- Method:
POST
- Request: Multipart/form-data with a file, language (default: "eng"), DPI (optional), PSM (default: 3), and config (optional)
- Response: Searchable PDF file
Example using curl
:
curl -X POST "http://localhost:8000/create_searchable/" -F "file=@path_to_your_file" --output output_ocr.pdf
- URL:
/jobs
- Method:
GET
- Request: Query parameter for status (default: "pending")
- Response: JSON containing job information
Example using curl
:
curl "http://localhost:8000/jobs?status=all"
- URL:
/info
- Method:
GET
- Response: JSON containing system information
Example using curl
:
curl "http://localhost:8000/info"
- URL:
/health
- Method:
GET
- Response: JSON indicating the health status of the application
Example using curl
:
curl "http://localhost:8000/health"
- URL:
/docs
- Method:
GET
- Response: Autogenerated documentation & testing area
Note
For the full guide on how to add more languages see: How to add lmore anguages
-
Clone the repository:
git clone https://github.com/jannichorst/tesseract-container.git cd tesseract-container
-
To build and run the Docker container in one step:
./scripts/build_and_run.sh
-
Access the Swagger documentation under http://localhost:8000/docs.
-
Check out the examples in demo.ipynb and install the required packages with:
pip install -r requirements.txt
The main application code is located in src/app/main.py
. The Dockerfile and scripts for building and running the container are located in the root directory and the scripts
directory, respectively. Under tests
you find a Postman collection that can be run with run-postman-collection.sh
(needs Newman CLI).
tesseract-container
├── Dockerfile
├── README.md
├── requirements.txt
├── examples
│ └── demo.ipynb
├── scripts
│ ├── build.sh
│ ├── run.sh
│ ├── build_and_run.sh
│ └── run-postman-collection.sh
├── src
│ ├── requirements.txt
│ └── app
│ ├── main.py
│ └── ...
└── tests
├── postman_collection.json
├── test-image.jpg
└── ...