From aa6cfb6c30bb47be1aa29aa99ce131717b420154 Mon Sep 17 00:00:00 2001 From: Narate Ketram Date: Tue, 23 Oct 2018 22:53:41 +0700 Subject: [PATCH 1/2] Add docker support --- .dockerignore | 1 + Dockerfile | 11 +++++++++++ README.md | 19 +++++++++++++++++++ docker-compose.yaml | 6 ++++++ requirements.txt | 1 - 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8fa5b33 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..334789f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python +LABEL maintainer="Narate Ketram " +WORKDIR /app +RUN apt-get update && \ + apt-get install -y tesseract-ocr libtesseract-dev +ADD requirements.txt . +RUN pip install -r requirements.txt + +ADD . . +EXPOSE 5000 +CMD ["python", "main.py"] diff --git a/README.md b/README.md index ebf51b7..4bed5d4 100644 --- a/README.md +++ b/README.md @@ -14,5 +14,24 @@ Run the respective python scripts for respective use-cases. * Pillow (For Image Processing) * [ImageMagick](https://legacy.imagemagick.org/script/binary-releases.php#windows) * wand(Python binding for ImageMagick) + +## Run in Docker + +First build docker image +``` +docker build -t ocr . +``` + +Run Docker container +``` +docker run -it --rm -p 5000:5000 ocr +``` + +Or run using docker-compose + +``` +docker-compose up +``` + *** **[Tesseract](https://github.com/tesseract-ocr/tesseract)** was originally written in C++ and uses an LSTM Network behind the scenes, for more reading and installation guide, you can check out this very helpful [blog post](https://appliedmachinelearning.blog/2018/06/30/performing-ocr-by-running-parallel-instances-of-tesseract-4-0-python/). This will explain you the essential stuff. I have also extended this for PDFs to make it more useful for real-world use-case. diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..9e46718 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,6 @@ +version: '3.7' +services: + ocr: + build: . + ports: + - 5000:5000 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8e15f17..daac1ba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,6 @@ ItsDangerous==1.0.0 Jinja2==2.10 MarkupSafe==1.0 Pillow==5.3.0 -pkg-resources==0.0.0 pytesseract==0.2.5 Wand==0.4.4 Werkzeug==0.14.1 From cd35ccd7ef2833e4b3ed4a56cd9f7001531f5f3e Mon Sep 17 00:00:00 2001 From: Narate Ketram Date: Tue, 23 Oct 2018 23:42:25 +0700 Subject: [PATCH 2/2] Fixed ValueError: 'jpeg' is unsupported format --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 334789f..4a4ceb3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python LABEL maintainer="Narate Ketram " WORKDIR /app RUN apt-get update && \ - apt-get install -y tesseract-ocr libtesseract-dev + apt-get install -y tesseract-ocr libtesseract-dev imagemagick ghostscript ADD requirements.txt . RUN pip install -r requirements.txt