root commited on
Commit
5c10fea
·
1 Parent(s): 261e9aa

Application file

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from azure.core.credentials import AzureKeyCredential
2
+ from azure.ai.formrecognizer import FormRecognizerClient, DocumentAnalysisClient
3
+ import pandas as pd
4
+ import numpy as np
5
+ import gradio as gr
6
+
7
+
8
+ from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
9
+ model_name = "deepset/bert-base-uncased-squad2"
10
+
11
+ # a) Get predictions
12
+ nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
13
+
14
+
15
+ endpoint = "https://invoice-extract.cognitiveservices.azure.com/"
16
+ key = "af03126391e141d482255941fdb16b7c"
17
+ # form_recognizer_client = FormRecognizerClient(endpoint=endpoint, credential=AzureKeyCredential(key))
18
+ document_analysis_client = DocumentAnalysisClient(
19
+ endpoint=endpoint, credential=AzureKeyCredential(key))
20
+
21
+
22
+ def extract_check_info(img):
23
+
24
+ with open(img, "rb") as f:
25
+ poller = document_analysis_client.begin_analyze_document(
26
+ "prebuilt-document", document=f)
27
+ document_data = poller.result()
28
+ content = document_data.content.strip()
29
+ QA_input = {
30
+ 'question': 'What is the IFSC code?',
31
+ 'context': content}
32
+ r1= nlp(QA_input)
33
+ ifsc_code = r1['answer']
34
+
35
+ QA_input = {
36
+ 'question': 'What is the A/C Number?',
37
+ 'context': content}
38
+ r2 = nlp(QA_input)
39
+ ac_number = r2['answer']
40
+
41
+ QA_input = {
42
+ 'question': 'What is the person name?',
43
+ 'context': content}
44
+ r3 = nlp(QA_input)
45
+ person_name = r3['answer']
46
+
47
+ return ifsc_code, ac_number, person_name
48
+
49
+
50
+
51
+
52
+ if __name__ = "__main__":
53
+
54
+ iface = gr.Interface(fn=extract_check_info,
55
+ inputs=[gr.inputs.Image(type='filepath', label='Input')],
56
+ outputs = [gr.outputs.Textbox(type='text', label='IFSC code'),
57
+ gr.outputs.Textbox(type='text', label='Account Number'),
58
+ gr.outputs.Textbox(type='text', label='Beneficiary Name')],
59
+ title="Check information extraction demo")
60
+ iface.launch()
61
+