Spaces:
Sleeping
Sleeping
File size: 1,297 Bytes
b7f8371 d37ff71 b7f8371 c1ded46 d37ff71 c1ded46 b7f8371 c1ded46 d37ff71 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import os
# os.system('chmod 777 /tmp')
# os.system('apt-get update -y')
# os.system('apt-get install tesseract-ocr -y')
# os.system('pip install -q pytesseract')
from base64 import b64decode, b64encode
from io import BytesIO
import tesserocr
from fastapi import FastAPI, File, Form
from PIL import Image
from transformers import pipeline
#import streamlit as st
# pytesseract.pytesseract.tesseract_cmd = r’./Tesseract-OCR/tesseract.exe’
choices = os.popen('tesseract --list-langs').read().split('\n')[1:-1]
description = """
Upload Receipt and get
"""
app = FastAPI(
title="ReceiptOCR",
docs_url="/", description=description)
pipe = pipeline("document-question-answering", model="impira/layoutlm-document-qa")
@app.get("/hello_2")
def read_root():
image = 'https://templates.invoicehome.com/invoice-template-us-neat-750px.png'
question_1 = "What is the Total amount?"
question_2 = "What is Total VAT amount?"
question_3 = "What is the Date?"
output_1 = pipe(image, question_1)
output_2 = pipe(image, question_2)
output_3 = pipe(image, question_3)
response = {}
response['total amount'] = output_1.first['answer']
response['toal vat'] = output_2.first['answer']
response['date'] = output_3.first['answer']
return response
|