Spaces:
Running
Running
formate response
Browse files
app.py
CHANGED
@@ -18,63 +18,29 @@ from transformers import pipeline
|
|
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 |
-
|
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 |
-
title="
|
31 |
docs_url="/", description=description)
|
32 |
|
33 |
pipe = pipeline("document-question-answering", model="impira/layoutlm-document-qa")
|
34 |
|
35 |
|
36 |
-
#st.write(output)
|
37 |
-
|
38 |
-
# @app.post("/predict")
|
39 |
-
# def predict(image_file: bytes = File(...), question: str = Form(...)):
|
40 |
-
# """
|
41 |
-
# Using the document-question-answering pipeline from `transformers`, take
|
42 |
-
# a given input document (image) and a question about it, and return the
|
43 |
-
# predicted answer. The model used is available on the hub at:
|
44 |
-
# [`impira/layoutlm-document-qa`](https://huggingface.co/impira/layoutlm-document-qa).
|
45 |
-
# """
|
46 |
-
# image = Image.open(BytesIO(image_file))
|
47 |
-
# output = pipe(image, question)
|
48 |
-
# return output
|
49 |
|
50 |
@app.get("/hello_2")
|
51 |
def read_root():
|
52 |
image = 'https://templates.invoicehome.com/invoice-template-us-neat-750px.png'
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
@app.get("/hello_4")
|
67 |
-
def read_root():
|
68 |
-
image = 'https://templates.invoicehome.com/invoice-template-us-neat-750px.png'
|
69 |
-
|
70 |
-
question = "What is the invoice number?"
|
71 |
-
output = pipe(image, question)
|
72 |
-
return output
|
73 |
-
|
74 |
-
@app.get("/hello")
|
75 |
-
def read_root():
|
76 |
-
image = 'https://templates.invoicehome.com/invoice-template-us-neat-750px.png'
|
77 |
-
|
78 |
-
question = "What is the invoice number?"
|
79 |
-
output = pipe(image, question)
|
80 |
-
return output
|
|
|
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 |
+
Upload Receipt and get
|
|
|
|
|
|
|
22 |
"""
|
|
|
|
|
|
|
23 |
app = FastAPI(
|
24 |
+
title="ReceiptOCR",
|
25 |
docs_url="/", description=description)
|
26 |
|
27 |
pipe = pipeline("document-question-answering", model="impira/layoutlm-document-qa")
|
28 |
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
@app.get("/hello_2")
|
32 |
def read_root():
|
33 |
image = 'https://templates.invoicehome.com/invoice-template-us-neat-750px.png'
|
34 |
|
35 |
+
question_1 = "What is the Total amount?"
|
36 |
+
question_2 = "What is Total VAT amount?"
|
37 |
+
question_3 = "What is the Date?"
|
38 |
+
output_1 = pipe(image, question_1)
|
39 |
+
output_2 = pipe(image, question_2)
|
40 |
+
output_3 = pipe(image, question_3)
|
41 |
+
|
42 |
+
response = {}
|
43 |
+
response['total amount'] = output_1.first['answer']
|
44 |
+
response['toal vat'] = output_2.first['answer']
|
45 |
+
response['date'] = output_3.first['answer']
|
46 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|