Skip to content

Instantly share code, notes, and snippets.

@OlegJakushkin
Created September 23, 2021 13:21
Show Gist options
  • Save OlegJakushkin/3efa359c1fbdf65ffb5cac447214c361 to your computer and use it in GitHub Desktop.
Save OlegJakushkin/3efa359c1fbdf65ffb5cac447214c361 to your computer and use it in GitHub Desktop.
#/usr/bin/python
from fastapi import FastAPI, File, UploadFile
app = FastAPI()
@app.post("/get_ocr")
async def image(image: UploadFile = File(...), json : str = "{'name':[x,y,w,h]}"):
print(image.file, json)
# print('../'+os.path.isdir(os.getcwd()+"images"),"*************")
try:
os.mkdir("images")
print(os.getcwd())
except Exception as e:
print(e)
file_name = os.getcwd()+"/images/"+image.filename.replace(" ", "-")
with open(file_name,'wb+') as f:
f.write(image.file.read())
f.close()
file = jsonable_encoder({"imagePath":file_name})
new_image = await add_image(file)
return {"filename": new_image}
FROM python:3.6.5-stretch
MAINTAINER Sandeep Srinivasa "sss@lambdacurry.com"
ENV DEBIAN_FRONTEND noninteractive
RUN pip install Cython
RUN pip install Pillow
RUN apt-get update && apt-get install -y \
autoconf automake libtool \
rsync \
libpng-dev \
libjpeg-dev \
libtiff-dev \
zlib1g-dev tesseract-ocr libtesseract-dev libleptonica-dev libcairo2-dev
RUN wget https://github.com/tesseract-ocr/tessdata/archive/4.00.tar.gz -O /tmp/tessdata.tgz
RUN tar -xvf /tmp/tessdata.tgz --directory /tmp
WORKDIR /tmp
RUN mkdir -p /usr/local/share/tessdata/ && rsync -a tessdata-4.00/ /usr/local/share/tessdata
RUN mkdir /tmp/tesserocr
ADD setup.py README.rst tesseract.pxd tesserocr_experiment.pyx tesserocr.pyx tests/ tox.ini /tmp/tesserocr/
WORKDIR /tmp/tesserocr
RUN python setup.py bdist_wheel
RUN python setup.py install
RUN pip install numpy Pillow opencv-python
RUN pip install fastapi
COPY ./app.py /app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment