sarim commited on
Commit
b7f8371
·
1 Parent(s): 8838912

initial commit

Browse files
Files changed (4) hide show
  1. Dockerfile +11 -0
  2. app.py +58 -0
  3. packages.txt +1 -0
  4. requirements.txt +9 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ # os.system('chmod 777 /tmp')
4
+ # os.system('apt-get update -y')
5
+ # os.system('apt-get install tesseract-ocr -y')
6
+ # os.system('pip install -q pytesseract')
7
+
8
+ from base64 import b64decode, b64encode
9
+ from io import BytesIO
10
+
11
+
12
+ import tesserocr
13
+ from fastapi import FastAPI, File, Form
14
+ from PIL import Image
15
+ from transformers import pipeline
16
+ #import streamlit as st
17
+
18
+ # pytesseract.pytesseract.tesseract_cmd = r’./Tesseract-OCR/tesseract.exe’
19
+ choices = os.popen('tesseract --list-langs').read().split('\n')[1:-1]
20
+ description = """
21
+ ## DocQA with 🤗 transformers, FastAPI, and Docker
22
+ This app shows how to do Document Question Answering using
23
+ FastAPI in a Docker Space 🚀
24
+ Check out the docs for the `/predict` endpoint below to try it out!
25
+ """
26
+
27
+ # NOTE - we configure docs_url to serve the interactive Docs at the root path
28
+ # of the app. This way, we can use the docs as a landing page for the app on Spaces.
29
+ app = FastAPI()
30
+
31
+ pipe = pipeline("document-question-answering", model="impira/layoutlm-document-qa")
32
+
33
+
34
+ #st.write(output)
35
+
36
+ # @app.post("/predict")
37
+ # def predict(image_file: bytes = File(...), question: str = Form(...)):
38
+ # """
39
+ # Using the document-question-answering pipeline from `transformers`, take
40
+ # a given input document (image) and a question about it, and return the
41
+ # predicted answer. The model used is available on the hub at:
42
+ # [`impira/layoutlm-document-qa`](https://huggingface.co/impira/layoutlm-document-qa).
43
+ # """
44
+ # image = Image.open(BytesIO(image_file))
45
+ # output = pipe(image, question)
46
+ # return output
47
+
48
+ @app.get("/")
49
+ def root():
50
+ return {"Hello":"world"}
51
+
52
+ @app.get("/hello")
53
+ def read_root():
54
+ image = 'https://templates.invoicehome.com/invoice-template-us-neat-750px.png'
55
+
56
+ question = "What is the invoice number?"
57
+ output = pipe(image, question)
58
+ return output
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ tesseract-ocr-all
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ fastapi==0.74.*
2
+ requests==2.27.*
3
+ uvicorn[standard]==0.17.*
4
+ sentencepiece==0.1.*
5
+ torch==1.11.*
6
+ transformers[vision]==4.*
7
+ pytesseract==0.3.10
8
+ tesserocr
9
+ python-multipart==0.0.6