Spaces:
Build error
Build error
File size: 2,206 Bytes
5c10fea 1b0b994 5c10fea 1b0b994 5c10fea d882a04 5c10fea 0734cee 5c10fea ae633dd ac09c29 e9c51d2 5c10fea |
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import FormRecognizerClient, DocumentAnalysisClient
import pandas as pd
import numpy as np
import gradio as gr
from PIL import Image
import os
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
model_name = "deepset/bert-base-uncased-squad2"
# a) Get predictions
nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
endpoint = "https://invoice-extract.cognitiveservices.azure.com/"
key = "af03126391e141d482255941fdb16b7c"
# form_recognizer_client = FormRecognizerClient(endpoint=endpoint, credential=AzureKeyCredential(key))
document_analysis_client = DocumentAnalysisClient(
endpoint=endpoint, credential=AzureKeyCredential(key))
def extract_check_info(img):
f1 = Image.open(img)
f1.save('upload.jpg',optimize=True, quality=95)
os.remove(img)
with open("upload.jpg", "rb") as f:
poller = document_analysis_client.begin_analyze_document(
"prebuilt-document", document=f)
document_data = poller.result()
os.remove("upload.jpg")
content = document_data.content.strip()
QA_input = {
'question': 'What is the IFSC code?',
'context': content}
r1= nlp(QA_input)
ifsc_code = r1['answer']
QA_input = {
'question': 'What is the A/C Number?',
'context': content}
r2 = nlp(QA_input)
ac_number = r2['answer']
QA_input = {
'question': 'What is the person name?',
'context': content}
r3 = nlp(QA_input)
person_name = r3['answer']
return ifsc_code, ac_number, person_name
if __name__ == "__main__":
iface = gr.Interface(fn=extract_check_info,
inputs=[gr.inputs.Image(type='filepath', label='Input')],
outputs = [gr.outputs.Textbox(type='text', label='IFSC code'),
gr.outputs.Textbox(type='text', label='Account Number'),
gr.outputs.Textbox(type='text', label='Signatory Name')],
title="Cheque Information Extraction Demo")
iface.launch()
|