lekkalar commited on
Commit
fe57073
1 Parent(s): 5f4364a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -5
app.py CHANGED
@@ -41,7 +41,73 @@ def load_pdf_and_generate_embeddings(pdf_doc, open_ai_key):
41
  return "Please provide an OpenAI API key"
42
 
43
 
44
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  def answer_query(query):
47
  question = query
@@ -72,17 +138,21 @@ with gr.Blocks(css=css,theme=gr.themes.Monochrome()) as demo:
72
  with gr.Row():
73
  status = gr.Textbox(label="Status", placeholder="", interactive=False)
74
  load_pdf = gr.Button("Load PDF")
75
-
76
-
77
 
 
 
 
 
 
78
  with gr.Row():
79
  input = gr.Textbox(label="Type in your question")
80
  output = gr.Textbox(label="Answer")
81
- submit_query = gr.Button("Submit")
82
 
83
 
84
  load_pdf.click(load_pdf_and_generate_embeddings, inputs=[pdf_doc, openai_key], outputs=status)
85
-
 
86
 
87
  submit_query.click(answer_query,input,output)
88
 
 
41
  return "Please provide an OpenAI API key"
42
 
43
 
44
+ def answer_predefined_questions(document_type):
45
+ if document_type == "Deed of Trust":
46
+ #Create a list of questions around the relevant fields of a Deed of Trust(DOT) document
47
+ query0 = "what is the Lender's Name?"
48
+ field0 = "Lender"
49
+ query1 = "what is the Loan Number?"
50
+ field1 = "Loan Number"
51
+ query2 = "what is the Case Number?"
52
+ field2 = "Case Number"
53
+ query3 = "what is the VA/FHA Number?"
54
+ field3 = "VA/FHA Number"
55
+ query4 = "who is the Borrower?"
56
+ field4 = "Borrower"
57
+ query5 = "who is the Co-Borrower?"
58
+ field5 = "Co-Borrower"
59
+ query6 = "what is the Mortgage Identification number?"
60
+ field6 = "MIN Number"
61
+ query7 = "what is the property type - single fmaily, multi family?"
62
+ field7 = "Property Type"
63
+ query8 = "what is the Property Address?"
64
+ field8 = "Property Address"
65
+ query9 = "On what date was the Deed of Trust signed?"
66
+ field9 = "Signed Date"
67
+ query10 = "What is the Property County?"
68
+ field10 = "Property County"
69
+ query11 = "what is the Electronically recorded date"
70
+ field11 = "Electronic Recording Date"
71
+ queryList = [query0, query1, query2, query3, query4, query5, query6, query7, query8, query9, query10, query11]
72
+ fieldList = [field0, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11]
73
+
74
+ elif document_type == "Transmittal Summary":
75
+ #Create a list of questions around the relevant fields of a TRANSMITTAL SUMMARY document
76
+ queryA0 = "who is the Borrower?"
77
+ fieldA0 = "Borrower"
78
+ queryA1 = "what is the Property Address?"
79
+ fieldA1 = "Property Address"
80
+ queryA2 = "who is the Co-Borrower?"
81
+ fieldA2 = "Co-Borrower"
82
+ queryA3 = "what is the loan term?"
83
+ fieldA3 = "Loan Term"
84
+ queryA4 = "What is the base income?"
85
+ fieldA4 = "Base Income"
86
+ queryA5 = "what is the original loan amount?"
87
+ fieldA5 = "Original Loan Amount"
88
+ queryA6 = "what is the Initial P&I Payment?"
89
+ fieldA6 = "Initial P&I Payment"
90
+ queryA7 = "what is the borrower's SSN?"
91
+ fieldA7 = "Borrower SSN"
92
+ queryA8 = "what is the co-borrower's SSN?"
93
+ fieldA8 = "C0-Borrower SSN"
94
+ queryA9 = "Number of units?"
95
+ fieldA9 = "Number of units"
96
+ queryA10 = "who is the seller?"
97
+ fieldA10 = "Seller"
98
+ queryA11 = "Document signed date?"
99
+ fieldA11 = "Singed Date"
100
+ queryList = [queryA0, queryA1, queryA2, queryA3, queryA4, queryA5, queryA6, queryA7, queryA8, queryA9, queryA10, queryA11]
101
+ fieldList = [fieldA0, fieldA1, fieldA2, fieldA3, fieldA4, fieldA5, fieldA6, fieldA7, fieldA8, fieldA9, fieldA10, fieldA11]
102
+
103
+ i = 0
104
+ while i < len(queryList):
105
+ question = questionList[i]
106
+ field = fieldList[i]
107
+ response += "Field Name:", field "; Question sent to gpt-4: ", question, "; Response from gpt-4:",pdf_qa.run(question)
108
+ return response
109
+
110
+
111
 
112
  def answer_query(query):
113
  question = query
 
138
  with gr.Row():
139
  status = gr.Textbox(label="Status", placeholder="", interactive=False)
140
  load_pdf = gr.Button("Load PDF")
 
 
141
 
142
+ with gr.Row():
143
+ document_type = gr.Radio(['Deed of Trust', 'Transmittal Summary'], label="Select the Document Type")
144
+ answers = gr.Textbox(label="Answers to Predefined Question set")
145
+ answers_for_predefined_question_set = gr.Button("Get Answers to Pre-defined Question set")
146
+
147
  with gr.Row():
148
  input = gr.Textbox(label="Type in your question")
149
  output = gr.Textbox(label="Answer")
150
+ submit_query = gr.Button("Submit your question")
151
 
152
 
153
  load_pdf.click(load_pdf_and_generate_embeddings, inputs=[pdf_doc, openai_key], outputs=status)
154
+
155
+ answers_for_predefined_question_set.click(answer_predefined_questions, document_type, answers)
156
 
157
  submit_query.click(answer_query,input,output)
158