Giter Club home page Giter Club logo

ocr-service-restapi's Introduction

OCR-Service-Restapi

Overview

A FastAPI-based simple web service that accepts images, runs optical character recognition (OCR) on them and returns the extracted text.

Prerequisites

Before you begin, make sure you have the following prerequisites installed:

  • Python 3.10
  • Pip (Python package installer)
  • Docker
  • fastapi
  • uvicorn
  • python-dotenv
  • pyyaml
  • python-multipart
  • pytesseract
  • Pillow

Installation

  1. Clone the repository:

    git clone https://github.com/99sbr/OCR-Service-Restapi.git
  2. Navigate to the project directory:

    cd OCR-Service-Restapi

Containerize the Service

To run the web service in a Docker container:

  1. Build the Docker image:
    docker build -t ocrservice-image  .
  1. Run the Docker container:
    docker run -p 80:80 ocrservice-image

Visit http://localhost:80/docs to access the Swagger documentation and interact with the API.

Api

API Endpoints

  1. POST /imgsync
    • Description: Synchronously extracts text from an image.
    • Request Body: Provide a JSON object with the base64-encoded image data.
    • Response: Returns a JSON object with the extracted text.
  2. POST /imgasync
    • Description: Asynchronously extracts text from an image.
    • Request Body: Provide a JSON object with the base64-encoded image data.
    • Response: Returns a JSON object with a job_id for tracking the asynchronous task.
  3. GET /ocr_text
    • Description: Asynchronously gets OCR text from Job ID.
    • Request Body: Provide a JSON object with the job-ID data.
    • Response: Returns a JSON object with the extracted text.

Code Structure

  • api_template: Contains all the API-related Code Base.

    • manage.py: Only entry point for API. Contains no logic.
    • .env: Most important file for our API and contains global configs. Avoid using application/variable level configs here.
    • application: It contains all our API-related codes and test modules. I prefer keeping the application folder global.
    • logs: Logs are self-explanatory. FYI it will not contain any configuration information, just raw logs. Feel free to move according to your comfort but not inside the application folder.
    • settings: Logger/DataBase/Model global settings files in yaml/json format.
  • application:

    • main: priority folder of all your application-related code.
      • ๐Ÿ“ฎ routers: API routers and they strictly do not contain any business logic
      • ๐Ÿ“ก services: All processing and business logic for routers here at the service layer
      • โš’ utility:
        • logger Logging module for application
        • manager A manager utility contains workers and handlers for Data Related Tasks which can be common for different services.
    • initializer.py: Preload/Initialisation of Models and Module common across applications. The preloading model improves inferencing.

ocr-service-restapi's People

Contributors

99sbr 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.