Git Product home page Git Product logo

optical-character-recognition's Introduction

Optical Character Recognition

Typing SVG

Typing SVG

License Last Commit Code Size Repo Size License

Overview

This project contains the implementation of REST API empowered by Vision AI to detect the text available in the input image. The REST API services are being distributed through the docker image. You can pull the image from Docker Hub. The image comes as production-ready with unit tests and a standard algorithm implemented which can be used to expose the REST API to the web.
Following are the major contents to follow, you can jump to any section:

  1. Run Locally
  2. REST API with Docker

Run Locally

  • Ensure you have Python 3.7+ installed.

  • Create a new Python Conda environment:

conda create -n ocr python=3.10  # create ocr
conda activate ocr  # activate ocr

OR

  • Create a new Python virtual environment with pip:
virtualenv ocr --python=python3.10  # create ocr
source ocr/bin/activate   # activate ocr

Install dependencies

  pip install -r requirements.txt

or

 conda env create -f environment.yaml

Clone the project

  git clone https://github.com/Hassi34/Optical-Character-Recognition.git

Go to the project directory

  cd Optical-Character-Recognition

Install dependencies

  pip install -r requirements.txt

Start the server

  uvicorn main:app --reload

REST API with Docker

To run the following sequence of commands, make sure you have the docker installed on your system.

Pull Image from Docker Hub

In case you have not already pulled the image from the Docker Hub, you can use the following command:

docker pull hassi34/optical-character-recognition

Docker Container

Now once you have the docker image from the Docker Hub, you can now run the following commands to test and deploy the container to the web

  • Run a Docker Container
    Check all the available images:
docker images

Use the following command to run a docker container on your system:

docker run --name <CONTAINER NAME> -p 80:80 -d <IMAGE NAME OR ID>

Check if the container is running:

docker ps

If the container is running, then the API services will be available on all the network interfaces
Type localhost in the browser and see if you get the success message from the API service.

  • Perform Unit Tests
    After when the API services are up and running, run the following command on the terminal to perform the unit test:
docker exec -it <CONTAINER NAME OR ID> pytest

Make an API Request

Use the following script as a reference to make a REST API request:

import requests
import base64

BASE64_STR = "" 
ENDPOINT = "http://127.0.0.1/predict"


def encodeImageIntoBase64(IN_IMG_PATH):
    with open(IN_IMG_PATH, "rb") as f:
        return base64.b64encode(f.read())

if __name__ == '__main__':
    response = requests.post(ENDPOINT, json={"base64_str":BASE64_STR})
    if response.status_code == 200:
        response = response.json()
        print(response)
    else :
        print(response)

Thank you for visiting ๐Ÿ™ I hope you find this project useful

๐Ÿ“ƒ License

MIT ยฉ Hasanain

Copyright ยฉ 2023 Hasanain
Let's connect on LinkedIn

optical-character-recognition's People

Contributors

hassi34 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

yat1ma30

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.