Git Product home page Git Product logo

tesseract-container's Introduction

CI Worklfow

Tesseract Container

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.

✨ Features

  • ✅ OCR on Images and PDFs
  • ✅ REST Endpoints
  • ✅ Sync / Async Support
  • ✅ Create searchable PDFs
  • ✅ Add more languages with ease

📖 Contents

1. Pull Image

docker pull jannichorst/tesseract-ocr:latest

2. Run Container

docker run -d -p 8000:8000 jannichorst/tesseract-ocr:latest

3. Usage

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

Perform OCR [SYNC]

  • 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"

Start OCR Processing [ASYNC]

  • 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"

Get OCR Results

  • 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}"

Create Searchable PDF [SYNC]

  • 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

Get Jobs

  • 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"

Get System Information

  • URL: /info
  • Method: GET
  • Response: JSON containing system information

Example using curl:

curl "http://localhost:8000/info"

Health Check

  • URL: /health
  • Method: GET
  • Response: JSON indicating the health status of the application

Example using curl:

curl "http://localhost:8000/health"

Swagger Documentation

  • 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

  1. Clone the repository:

    git clone https://github.com/jannichorst/tesseract-container.git
    cd tesseract-container
  2. To build and run the Docker container in one step:

    ./scripts/build_and_run.sh
  3. Access the Swagger documentation under http://localhost:8000/docs.

  4. 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).

Directory Structure

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
    └── ...

tesseract-container's People

Contributors

jannichorst avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.