Spaces:
Sleeping
Sleeping
base64 image
Browse files
app.py
CHANGED
|
@@ -5,8 +5,10 @@ import os
|
|
| 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
|
|
@@ -28,19 +30,26 @@ pipe = pipeline("document-question-answering", model="impira/layoutlm-document-q
|
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
-
@app.
|
| 32 |
-
def read_root():
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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[0]['answer']
|
| 44 |
response['toal vat'] = output_2[0]['answer']
|
| 45 |
response['date'] = output_3[0]['answer']
|
|
|
|
| 46 |
return response
|
|
|
|
| 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 |
+
import base64
|
| 11 |
+
import io
|
| 12 |
|
| 13 |
|
| 14 |
import tesserocr
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
+
@app.post("/image")
|
| 34 |
+
def read_root(imageBase64:str):
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
img = Image.open(io.BytesIO(base64.decodebytes(bytes(imageBase64, "utf-8"))))
|
| 38 |
+
print(img)
|
| 39 |
+
image = img
|
| 40 |
|
| 41 |
question_1 = "What is the Total amount?"
|
| 42 |
question_2 = "What is Total VAT amount?"
|
| 43 |
question_3 = "What is the Date?"
|
| 44 |
+
question_4 = "What is the total amount currency?"
|
| 45 |
output_1 = pipe(image, question_1)
|
| 46 |
output_2 = pipe(image, question_2)
|
| 47 |
output_3 = pipe(image, question_3)
|
| 48 |
+
output_4 = pipe(image, question_4)
|
| 49 |
|
| 50 |
response = {}
|
| 51 |
response['total amount'] = output_1[0]['answer']
|
| 52 |
response['toal vat'] = output_2[0]['answer']
|
| 53 |
response['date'] = output_3[0]['answer']
|
| 54 |
+
response['currency'] = output_4[0]['answer']
|
| 55 |
return response
|