Omarrran commited on
Commit
e603781
·
verified ·
1 Parent(s): 441ea08

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +612 -0
app.py ADDED
@@ -0,0 +1,612 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import time
4
+ import pandas as pd
5
+ import sqlite3
6
+ import ocrmypdf
7
+
8
+ from langchain.document_loaders import OnlinePDFLoader # for loading the pdf
9
+ from langchain.embeddings import HuggingFaceEmbeddings # open source embedding model
10
+ from langchain.text_splitter import CharacterTextSplitter
11
+ from langchain.vectorstores import Chroma # for the vectorization part
12
+ from langchain.chains import RetrievalQA # for conversing with chatGPT
13
+ from langchain.chat_models import ChatOpenAI # the LLM model we'll use (ChatGPT)
14
+ from langchain import PromptTemplate
15
+
16
+ def load_pdf_and_generate_embeddings(pdf_doc, open_ai_key, relevant_pages):
17
+ # If an OpenAI API key is provided, it will be used for ChatOpenAI (GPT-4)
18
+ if open_ai_key is not None:
19
+ os.environ['OPENAI_API_KEY'] = open_ai_key
20
+ # OCR Conversion - skips conversion of pages that already contain text
21
+ pdf_doc = ocr_converter(pdf_doc)
22
+ # Load the pdf file
23
+ loader = OnlinePDFLoader(pdf_doc)
24
+ pages = loader.load_and_split()
25
+ print('pages loaded:', len(pages))
26
+
27
+ # Create an instance of HuggingFaceEmbeddings (open source) for generating embeddings
28
+ embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
29
+
30
+ pages_to_be_loaded = []
31
+
32
+ if relevant_pages:
33
+ page_numbers = relevant_pages.split(",")
34
+ if len(page_numbers) != 0:
35
+ for page_number in page_numbers:
36
+ if page_number.isdigit():
37
+ pageIndex = int(page_number) - 1
38
+ if pageIndex >= 0 and pageIndex < len(pages):
39
+ pages_to_be_loaded.append(pages[pageIndex])
40
+
41
+ # If no valid pages are specified, use the entire PDF.
42
+ if len(pages_to_be_loaded) == 0:
43
+ pages_to_be_loaded = pages.copy()
44
+
45
+ # Create a vector store using the Chroma class with the open-source embeddings
46
+ vectordb = Chroma.from_documents(pages_to_be_loaded, embedding=embeddings)
47
+
48
+ # Configure the prompt template for the QA chain
49
+ prompt_template = (
50
+ """Use the following pieces of context to answer the question at the end. If you do not know the answer, just return N/A.
51
+ If you encounter a date, return it in mm/dd/yyyy format. If there is a Preface section in the document, extract the chapter# and the short description from the Preface.
52
+ Chapter numbers are listed to the left in Preface and always start with an alphabet, for example A1-1.
53
+ {context}
54
+ Question: {question}
55
+ Return the answer. Provide the answer in the JSON format and extract the key from the question. Where applicable, break the answer into bullet points.
56
+ When the sentences are long, try and break them into sub sections and include all the information and do not skip any information.
57
+ If there is an exception to the answer, please do include it in a 'Note:' section. If there are no exceptions to the answer, please skip the 'Note:' section.
58
+ Include a 'For additional details refer to' section when the document has more information to offer on the topic being questioned.
59
+ If the document has a Preface or 'Table of Contents' section, extract the chapter# and a short description and include the info under the 'For additional details refer to' section.
60
+ List only the chapters that contain information or skip this section altogether. Do not use page numbers as chapter numbers as they are different.
61
+ If additional information is found in multiple pages within the same chapter, list the chapter only once.
62
+ If chapter information cannot be extracted, include any other information that will help the user navigate to the relevant sections of the document.
63
+ If the document does not contain a Preface or 'Table of Contents' section, please do not call that out. For example, do not include statements like
64
+ the following in the answer - 'The document does not contain a Preface or 'Table of Contents' section'"""
65
+ )
66
+
67
+ PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
68
+ chain_type_kwargs = {"prompt": PROMPT}
69
+
70
+ global pdf_qa
71
+ pdf_qa = RetrievalQA.from_chain_type(
72
+ llm=ChatOpenAI(temperature=0, model_name="gpt-4"),
73
+ chain_type="stuff",
74
+ retriever=vectordb.as_retriever(search_kwargs={"k": 5}),
75
+ chain_type_kwargs=chain_type_kwargs,
76
+ return_source_documents=False
77
+ )
78
+
79
+ return "Ready"
80
+
81
+ def create_db_connection():
82
+ DB_FILE = "./questionset.db"
83
+ connection = sqlite3.connect(DB_FILE, check_same_thread=False)
84
+ return connection
85
+
86
+ def create_sqlite_table(connection):
87
+ print("*****Entered the create_sqlite_table method*****")
88
+ cursor = connection.cursor()
89
+ try:
90
+ data = f'SELECT * FROM questions'
91
+ cursor.execute(data)
92
+ cursor.fetchall()
93
+ except sqlite3.OperationalError:
94
+ cursor.execute(
95
+ '''
96
+ CREATE TABLE questions (document_type TEXT NOT NULL, questionset_tag TEXT NOT NULL, field TEXT NOT NULL, question TEXT NOT NULL)
97
+ ''')
98
+ print("*****questions table has been created******")
99
+ connection.commit()
100
+
101
+ def load_master_questionset_into_sqlite(connection):
102
+ create_sqlite_table(connection)
103
+ cursor = connection.cursor()
104
+ masterlist_for_DOT_count = cursor.execute(
105
+ "Select COUNT(document_type) from questions where document_type=? and questionset_tag=?",
106
+ ("DOT", "masterlist",)
107
+ ).fetchone()[0]
108
+ if masterlist_for_DOT_count == 0:
109
+ print("DOT masterlist has not yet been loaded, proceeding to load.")
110
+ fieldListForDOT, queryListForDOT = create_field_and_question_list_for_DOT()
111
+ fieldListForTransmittalSummary, queryListForTransmittalSummary = create_field_and_question_list_for_Transmittal_Summary()
112
+ i = 0
113
+ print("*****Entered the load master question set method*****")
114
+ while i < len(queryListForDOT):
115
+ cursor.execute(
116
+ "INSERT INTO questions(document_type, questionset_tag, field, question) VALUES(?,?,?,?)",
117
+ ["DOT", "masterlist", fieldListForDOT[i], queryListForDOT[i]]
118
+ )
119
+ i += 1
120
+ i = 0
121
+ while i < len(queryListForTransmittalSummary):
122
+ cursor.execute(
123
+ "INSERT INTO questions(document_type, questionset_tag, field, question) VALUES(?,?,?,?)",
124
+ ["Transmittal Summary", "masterlist", fieldListForTransmittalSummary[i], queryListForTransmittalSummary[i]]
125
+ )
126
+ i += 1
127
+ connection.commit()
128
+ total_questions = cursor.execute("Select COUNT(document_type) from questions").fetchone()[0]
129
+ print("*******Total number of questions in the DB:", total_questions)
130
+
131
+ def create_field_and_question_list_for_DOT():
132
+ query1 = "what is the Loan Number?"
133
+ field1 = "Loan Number"
134
+ query2 = "Who is the Borrower?"
135
+ field2 = "Borrower"
136
+ query3 = "what is the Case Number?"
137
+ field3 = "Case Number"
138
+ query4 = "what is the Mortgage Identification number?"
139
+ field4 = "MIN Number"
140
+ query5 = "DOT signed date?"
141
+ field5 = "Signed Date"
142
+ query6 = "Who is the Lender?"
143
+ field6 = "Lender"
144
+ query7 = "what is the VA/FHA Number?"
145
+ field7 = "VA/FHA Number"
146
+ query8 = "Who is the Co-Borrower?"
147
+ field8 = "Co-Borrower"
148
+ query9 = "What is the property type - single family, multi family?"
149
+ field9 = "Property Type"
150
+ query10 = "what is the Property Address?"
151
+ field10 = "Property Address"
152
+ query11 = "In what County is the property located?"
153
+ field11 = "Property County"
154
+ query12 = "what is the Electronically recorded date"
155
+ field12 = "Electronic Recording Date"
156
+ queryList = [query1, query2, query3, query4, query5, query6, query7, query8, query9, query10, query11, query12]
157
+ fieldList = [field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12]
158
+ return fieldList, queryList
159
+
160
+ def create_field_and_question_list_for_Transmittal_Summary():
161
+ query1 = "Who is the Borrower?"
162
+ field1 = "Borrower"
163
+ query2 = "what is the Property Address?"
164
+ field2 = "Property Address"
165
+ query3 = "what is the Loan Term?"
166
+ field3 = "Loan Term"
167
+ query4 = "What is the Base Income?"
168
+ field4 = "Base Income"
169
+ query5 = "what is the Borrower's SSN?"
170
+ field5 = "Borrower's SSN"
171
+ query6 = "Who is the Co-Borrower?"
172
+ field6 = "Co-Borrower"
173
+ query7 = "What is the Original Loan Amount?"
174
+ field7 = "Original Loan Amount"
175
+ query8 = "What is the Initial P&I payment?"
176
+ field8 = "Initial P&I payment"
177
+ query9 = "What is the Co-Borrower's SSN?"
178
+ field9 = "Co-Borrower’s SSN"
179
+ query10 = "Number of units?"
180
+ field10 = "Units#"
181
+ query11 = "Who is the Seller?"
182
+ field11 = "Seller"
183
+ query12 = "Document signed date?"
184
+ field12 = "Signed Date"
185
+ queryList = [query1, query2, query3, query4, query5, query6, query7, query8, query9, query10, query11, query12]
186
+ fieldList = [field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12]
187
+ return fieldList, queryList
188
+
189
+ def retrieve_document_type_and_questionsettag_from_sqlite():
190
+ connection = create_db_connection()
191
+ load_master_questionset_into_sqlite(connection)
192
+ cursor = connection.cursor()
193
+ rows = cursor.execute("SELECT document_type, questionset_tag FROM questions order by document_type, upper(questionset_tag)").fetchall()
194
+ print("Number of rows retrieved from DB:", len(rows))
195
+ list_for_dropdown = []
196
+ for i in rows:
197
+ entries_in_row = list(i)
198
+ concatenated_value = entries_in_row[0] + ":" + entries_in_row[1]
199
+ if concatenated_value not in list_for_dropdown:
200
+ list_for_dropdown.append(concatenated_value)
201
+ print(concatenated_value)
202
+ print("Number of unique entries found in the DB:", len(list_for_dropdown))
203
+ connection.close()
204
+ return gr.Dropdown.update(choices=list_for_dropdown, value=list_for_dropdown[0])
205
+
206
+ def retrieve_fields_and_questions(dropdownoption):
207
+ print("dropdownoption is:", dropdownoption)
208
+ splitwords = dropdownoption.split(":")
209
+ connection = create_db_connection()
210
+ cursor = connection.cursor()
211
+ fields_and_questions = cursor.execute(
212
+ "SELECT document_type, field, question FROM questions where document_type=? and questionset_tag=?",
213
+ (splitwords[0], splitwords[1],)
214
+ ).fetchall()
215
+ connection.close()
216
+ return pd.DataFrame(fields_and_questions, columns=["documentType", "field", "question"])
217
+
218
+ def add_questionset(data, document_type, tag_for_questionset):
219
+ connection = create_db_connection()
220
+ create_sqlite_table(connection)
221
+ cursor = connection.cursor()
222
+ for index, row in data.iterrows():
223
+ cursor.execute(
224
+ "INSERT INTO questions(document_type, questionset_tag, field, question) VALUES(?,?,?,?)",
225
+ [document_type, tag_for_questionset, row['field'], row['question']]
226
+ )
227
+ connection.commit()
228
+ connection.close()
229
+
230
+ def load_csv_and_store_questionset_into_sqlite(csv_file, document_type, tag_for_questionset):
231
+ print('document type is:', document_type)
232
+ print('tag_for_questionset is:', tag_for_questionset)
233
+
234
+ if tag_for_questionset:
235
+ if document_type:
236
+ data = pd.read_csv(csv_file.name)
237
+ add_questionset(data, document_type, tag_for_questionset)
238
+ responseString = "Task Complete. Uploaded {} fields and the corresponding questions into the Database for {}:{}".format(data.shape[0], document_type, tag_for_questionset)
239
+ return responseString
240
+ else:
241
+ return "Please select the Document Type and provide a name for the Question Set"
242
+
243
+ def answer_predefined_questions(document_type_and_questionset):
244
+ print('chosen document_type_and_questionset:', document_type_and_questionset)
245
+ option_chosen = document_type_and_questionset.split(":")
246
+ document_type = option_chosen[0]
247
+ question_set = option_chosen[1]
248
+ fields = []
249
+ questions = []
250
+ responses = []
251
+ connection = create_db_connection()
252
+ cursor = connection.cursor()
253
+ if document_type is not None and question_set is not None:
254
+ rows = cursor.execute(
255
+ "SELECT field, question FROM questions where document_type=? and questionset_tag=?",
256
+ (document_type, question_set,)
257
+ ).fetchall()
258
+ for i in rows:
259
+ entries_in_row = list(i)
260
+ fields.append(entries_in_row[0])
261
+ questions.append(entries_in_row[1])
262
+ responses.append(pdf_qa.run(entries_in_row[1]))
263
+ else:
264
+ return "Please choose your Document Type:QuestionSet"
265
+ return pd.DataFrame({"Field": fields, "Question to gpt-4": questions, "Response from gpt-4": responses})
266
+
267
+ def ocr_converter(input_file):
268
+ image_pdf = input_file.name
269
+ ocrmypdf.ocr(image_pdf, image_pdf, redo_ocr=True, language="eng")
270
+ return image_pdf
271
+
272
+ def summarize_contents():
273
+ question = "Generate a short summary of the contents along with no more than 3 leading/example questions. Do not return the response in json format"
274
+ return pdf_qa.run(question)
275
+
276
+ def answer_query(query):
277
+ question = query
278
+ return pdf_qa.run(question)
279
+
280
+ css = """
281
+ #col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
282
+ """
283
+
284
+ title = """
285
+ <div style="text-align: center;max-width: 700px;">
286
+ <h1>AskMoli - Chatbot for PDFs</h1>
287
+ <p style="text-align: center;">Upload a .PDF, click the "Upload PDF and generate embeddings" button, <br />
288
+ Wait for the Status to show Ready. You can choose to get answers to the pre-defined question set OR ask your own question <br />
289
+ The app is built on GPT-4 and leverages the magic of PromptTemplate</p>
290
+ </div>
291
+ """
292
+
293
+ with gr.Blocks(css=css, theme=gr.themes.Monochrome()) as demo:
294
+ with gr.Column(elem_id="col-container"):
295
+ gr.HTML(title)
296
+
297
+ with gr.Tab("Chatbot"):
298
+ with gr.Column():
299
+ open_ai_key = gr.Textbox(label="Your GPT-4 OpenAI API key", type="password")
300
+ pdf_doc = gr.File(label="Load a pdf", file_types=['.pdf'], type='file')
301
+ relevant_pages = gr.Textbox(label="*Optional - List comma separated page numbers to load or leave this field blank to use the entire PDF")
302
+
303
+ with gr.Row():
304
+ status = gr.Textbox(label="Status", placeholder="", interactive=False)
305
+ load_pdf = gr.Button("Upload PDF and generate embeddings").style(full_width=False)
306
+
307
+ with gr.Row():
308
+ summary = gr.Textbox(label="Summary")
309
+ summarize_pdf = gr.Button("Have Moli Summarize the Contents").style(full_width=False)
310
+
311
+ with gr.Row():
312
+ input = gr.Textbox(label="Type in your question")
313
+ output = gr.Textbox(label="Answer")
314
+ submit_query = gr.Button("Submit your own question to AskMoli").style(full_width=False)
315
+
316
+ with gr.Row():
317
+ questionsets = gr.Dropdown(label="Pre-defined Question Sets stored in the DB", choices=[])
318
+ load_questionsets = gr.Button("Retrieve Pre-defined Question Sets from DB").style(full_width=False)
319
+ fields_and_questions = gr.Dataframe(label="Fields and Questions in the chosen Question Set")
320
+ load_fields_and_questions = gr.Button("Retrieve Pre-defined Questions from the DB for the chosen QuestionSet").style(full_width=False)
321
+
322
+ with gr.Row():
323
+ answers = gr.Dataframe(label="Answers to Predefined Question set")
324
+ answers_for_predefined_question_set = gr.Button("Get answers to the chosen pre-defined question set").style(full_width=False)
325
+
326
+ with gr.Tab("OCR Converter"):
327
+ with gr.Column():
328
+ image_pdf = gr.File(label="Load the pdf to be converted", file_types=['.pdf'], type='file')
329
+
330
+ with gr.Row():
331
+ ocr_pdf = gr.File(label="OCR'd pdf", file_types=['.pdf'], type='file', file_count="single")
332
+ convert_into_ocr = gr.Button("Convert").style(full_width=False)
333
+
334
+ with gr.Tab("Upload Question Set"):
335
+ with gr.Column():
336
+ document_types = [
337
+ "Mortgage 1040 US Individual Tax Returns 8453 Elec Form",
338
+ "Mortgage 1098",
339
+ "Mortgage 1099",
340
+ "Mortgage Abstract",
341
+ "Mortgage ACH Authorization Form",
342
+ "Mortgage Advance Fee Agreement",
343
+ "Mortgage Affidavit",
344
+ "Mortgage Affidavit of Suspense Funds",
345
+ "Mortgage Agreement Documents",
346
+ "Mortgage Sales Contract",
347
+ "Mortgage Loan Estimate",
348
+ "Mortgage Alimony Or Child Support",
349
+ "Mortgage Amended Proof Of Claim",
350
+ "Mortgage Amortization Schedule",
351
+ "Mortgage Flood Insurance",
352
+ "Mortgage Appraisal Report",
353
+ "Mortgage Appraisal Disclosure",
354
+ "Mortgage ARM Letter",
355
+ "Mortgage Arms Length Affidavit",
356
+ "Mortgage Assignment-Recorded",
357
+ "Mortgage Assignment-Unrecorded",
358
+ "Mortgage Assignment of Rent or Lease",
359
+ "Mortgage Automated Value Model",
360
+ "Mortgage Award Letters",
361
+ "Mortgage Bailee Letter",
362
+ "Mortgage Balloon Disclosure",
363
+ "Mortgage Bank Statement",
364
+ "Mortgage Bankruptcy Documents",
365
+ "Mortgage Bill of Sale",
366
+ "Mortgage Billing Statement",
367
+ "Mortgage Birth-Marriage-Death Certificate",
368
+ "Mortgage Borrower Certification Authorization",
369
+ "Mortgage Borrower Response Package",
370
+ "Mortgage Brokers Price Opinion",
371
+ "Mortgage Business Plan",
372
+ "Mortgage Buydown Agreement",
373
+ "Mortgage Bylaws Covenants Conditions Restrictions",
374
+ "Mortgage Cash for Keys",
375
+ "Mortgage Certificate of Redemption",
376
+ "Mortgage Certificate of Sale",
377
+ "Mortgage Certificate of Title",
378
+ "Mortgage Certification of Amount Due Payoff Reinstatement",
379
+ "Mortgage Checks-Regular or Cashiers",
380
+ "Mortgage Closing Disclosure",
381
+ "Mortgage Closing Protection Letter",
382
+ "Mortgage Closing Other",
383
+ "Mortgage Code Violations",
384
+ "Mortgage Request for Release",
385
+ "Mortgage Certificate of Liability Insurance",
386
+ "Mortgage Commitment Letter",
387
+ "Mortgage Complaint",
388
+ "Mortgage Complaint Answer Counter Claim",
389
+ "Mortgage Conditional Approval Letter",
390
+ "Mortgage Conditional Commitment",
391
+ "Mortgage Consent Order",
392
+ "Mortgage Consolidated Mortgage CEMA",
393
+ "Mortgage Conveyance Claims",
394
+ "Mortgage Correction and Revision Agreement",
395
+ "Mortgage Correspondence",
396
+ "Mortgage Court Order Settlement Divorce Decree",
397
+ "Mortgage Credit Report",
398
+ "Mortgage Customer Signature Authorization",
399
+ "Mortgage Debt Validation",
400
+ "Mortgage Deed",
401
+ "Mortgage Default Notices",
402
+ "Mortgage Direct Debit Authorization Form",
403
+ "Mortgage Disclosure Documents",
404
+ "Mortgage Document Checklist",
405
+ "Mortgage Document Correction and Fee Due Agreement",
406
+ "Mortgage Dodd Frank Certification",
407
+ "Mortgage Drivers License",
408
+ "Mortgage Request for VOE",
409
+ "Mortgage Environmental Indemnity Agreement",
410
+ "Mortgage Equal Credit Opportunity Act Notice",
411
+ "Mortgage Escrow Agreement",
412
+ "Mortgage Escrow Analysis Trial Balance Worksheet",
413
+ "Mortgage Instructions to Escrow Agent",
414
+ "Mortgage Escrow Letters",
415
+ "Mortgage Executed Deeds",
416
+ "Mortgage Fair Lending Notice",
417
+ "Mortgage Foreclosure Complaint",
418
+ "Mortgage Foreclosure Judgement",
419
+ "Mortgage Foreclosure Sale",
420
+ "Mortgage FHA Neighborhood Watch",
421
+ "Mortgage Truth-In-Lending Disclosure Statement",
422
+ "Mortgage Financial Form",
423
+ "Mortgage Financing Agreement",
424
+ "Mortgage First Payment Letter",
425
+ "Mortgage Forced Place Insurance Documents",
426
+ "Mortgage Foreclosure Documents",
427
+ "Mortgage Good Faith Estimate",
428
+ "Mortgage Guaranty",
429
+ "Mortgage HAMP Certifications",
430
+ "Mortgage HOA-Condo Covenants and Dues",
431
+ "Mortgage Exemption Hold Harmless Letter",
432
+ "Mortgage Home Equity Signature Verification Card",
433
+ "Mortgage Home Inspection",
434
+ "Mortgage Property Liability Insurance",
435
+ "Mortgage Homeowners Insurance Notice",
436
+ "Mortgage HUD-1 Settlement Statement",
437
+ "Mortgage Income Other",
438
+ "Mortgage Indemnity Agreement",
439
+ "Mortgage Informed Consumer Choice Disclosure Notice",
440
+ "Mortgage Initial Escrow Account Disclosure Statement",
441
+ "Mortgage Invoices",
442
+ "Mortgage Land Lease or Land Trust",
443
+ "Mortgage Land Title Adjustment",
444
+ "Mortgage Last Will and Testament",
445
+ "Mortgage Legal Description",
446
+ "Mortgage Letters Of Administration",
447
+ "Mortgage Letters of Testamentary",
448
+ "Mortgage Listing Agreement",
449
+ "Mortgage Litigation Guarantee",
450
+ "Mortgage DIL Closing",
451
+ "Mortgage Hardship Letter",
452
+ "Mortgage Hardship Affidavit",
453
+ "Mortgage Home Affordable Modification Agreement",
454
+ "Mortgage Profit And Loss",
455
+ "Mortgage Earnest Money Promissory Note",
456
+ "Mortgage Rental Agreement",
457
+ "Mortgage Repayment Plan",
458
+ "Mortgage Short Sale Miscellaneous",
459
+ "Mortgage LM - Trial Offer Letter or Plan",
460
+ "Mortgage Errors and Omissions Agreement",
461
+ "Mortgage Custom Type 2",
462
+ "Mortgage Custom Type 1",
463
+ "Mortgage Loan Agreement",
464
+ "Mortgage Loan Closing Information Summary",
465
+ "Mortgage Loan Modification",
466
+ "Mortgage Loan Summary Report",
467
+ "Mortgage Lock Confirmation",
468
+ "Mortgage Loss Drafts",
469
+ "Mortgage Loss Mitigation",
470
+ "Mortgage Lost Assignment Affidavit",
471
+ "Mortgage Mech Lien",
472
+ "Mortgage Mediation",
473
+ "Mortgage MI Claim Explanation of Benefits",
474
+ "Mortgage MI Policy Cancellation Document",
475
+ "Mortgage MI Repurchase Document",
476
+ "Mortgage Miscellaneous Lien Release",
477
+ "Mortgage Mobile Home Documentation",
478
+ "Mortgage Monthly Activity Report",
479
+ "Mortgage Deed of Trust-Recorded",
480
+ "Mortgage PMI Disclosure",
481
+ "Mortgage Payments",
482
+ "Mortgage Deed of Trust-Unrecorded",
483
+ "Mortgage Motion For Relief",
484
+ "Mortgage Note",
485
+ "Mortgage Note Affidavit",
486
+ "Mortgage Note Endorsements",
487
+ "Mortgage Notice Of Appearance",
488
+ "Mortgage Notice of Default Filedrecorded",
489
+ "Mortgage Notice of Final Cure",
490
+ "Mortgage Notice of Levy",
491
+ "Mortgage Notice of Payment Change",
492
+ "Mortgage Notice of Right to Cancel",
493
+ "Mortgage Notice of Sale",
494
+ "Mortgage Notice of Second Lien",
495
+ "Mortgage Notice of Servicing Transfer-Transferee",
496
+ "Mortgage Notice of Servicing Transfer-Transferor",
497
+ "Mortgage Notice of Termination",
498
+ "Mortgage Notice to Quit",
499
+ "Mortgage Objection to Claim",
500
+ "Mortgage Processing and Underwriting Doc Set",
501
+ "Mortgage Objection to Motion for Relief",
502
+ "Mortgage Affidavit of Occupancy",
503
+ "Mortgage Occupancy Agreement",
504
+ "Mortgage Occupancy Termination Agreement",
505
+ "Mortgage Ombudsman Documents",
506
+ "Mortgage Owner Affidavit",
507
+ "Mortgage Ownership and Encumbrances Report",
508
+ "Mortgage Pay History External",
509
+ "Mortgage Paystub",
510
+ "Mortgage Payoff Demand Statement",
511
+ "Mortgage PMI Certificate",
512
+ "Mortgage Post Petition Fee Notices",
513
+ "Mortgage Post Sale Documents",
514
+ "Mortgage Power of Attorney-Recorded",
515
+ "Mortgage Power of Attorney-Unrecorded",
516
+ "Mortgage Closing Instructions",
517
+ "Mortgage Preliminary Modification",
518
+ "Mortgage Merged-Privacy Policy Notice-Title Policy - Privacy Policy-1098 Privacy Policy",
519
+ "Mortgage Probate Court Order",
520
+ "Mortgage Proof of Claim",
521
+ "Mortgage Property Legal and Vesting Report",
522
+ "Mortgage Property Management Agreement",
523
+ "Mortgage Property Notices",
524
+ "Mortgage Public Assistance",
525
+ "Mortgage Record Owner and Lien Certificate",
526
+ "Mortgage Recorded Satisfaction",
527
+ "Mortgage Regfore Affidavit Executed",
528
+ "Mortgage Release of Lis Pendens",
529
+ "Mortgage REO Bids",
530
+ "Mortgage REO Other",
531
+ "Mortgage Form 26-1820 Report and Certificate of Loan Disbursement",
532
+ "Mortgage Request for Verification of Rent or Mortgage",
533
+ "Mortgage Request for Waiver of R.E. Tax Escrow Requirements",
534
+ "Mortgage 1003",
535
+ "Mortgage RMA Package",
536
+ "Mortgage Sale Postponement",
537
+ "Mortgage Sale or Milestone Rescission",
538
+ "Mortgage Satisfaction of Judgement Tax Mortgage Liens",
539
+ "Mortgage Security Agreement",
540
+ "Mortgage Separation Agreement",
541
+ "Mortgage Servicing Acquisition",
542
+ "Mortgage Servicing Disclosure Statement",
543
+ "Mortgage Short Payoffs",
544
+ "Mortgage Signature-Name Affidavit",
545
+ "Mortgage Assumption of Mortgage",
546
+ "Mortgage SCRA Related Documents",
547
+ "Mortgage Social Security Card or Customer ID",
548
+ "Mortgage Soft Delete",
549
+ "Mortgage Flood Hazard Determination Form",
550
+ "Mortgage Stipulated Agreement",
551
+ "Mortgage Subordination Agreement",
552
+ "Mortgage Subordination Request Form",
553
+ "Mortgage Appointment of Substitute Trustee",
554
+ "Mortgage Merged-Real Estate Taxes-Tax Bill-Tax Certificate",
555
+ "Mortgage Tax Certificate",
556
+ "Mortgage Tax Record Information Sheet",
557
+ "Mortgage Tax Liens",
558
+ "Mortgage Tax Search",
559
+ "Mortgage Third Party Authorization",
560
+ "Mortgage Title Commitment-Equity or Property Report",
561
+ "Mortgage Title Policy",
562
+ "Mortgage Title Policy Endorsement",
563
+ "Mortgage Title Search",
564
+ "Mortgage Title Insurance Other",
565
+ "Mortgage Transfer of Claim",
566
+ "Mortgage Uniform Underwriting and Transmittal Summary",
567
+ "Mortgage Trustee Sale Guarantee",
568
+ "Mortgage UCC-1 Financing Statement",
569
+ "Mortgage Others",
570
+ "Mortgage Unknown",
571
+ "Mortgage Utility Bill",
572
+ "Mortgage Valuation Orders",
573
+ "Mortgage Verification Document Set",
574
+ "Mortgage Verification of Service for Military Home Buyers",
575
+ "Mortgage W2",
576
+ "Mortgage W9",
577
+ "Mortgage Wire Transfer Instructions",
578
+ "Mortgage Workmens Compensation",
579
+ "Mortgage Writ of Possession",
580
+ "Mortgage Cover Page",
581
+ "Mortgage Barcode Page",
582
+ "Mortgage Wisconsin Tax Escrow Option Notice",
583
+ "Mortgage Hazard Insurance Declaration",
584
+ "Mortgage Flood Insurance Declaration",
585
+ "Mortgage Quitclaim Deed",
586
+ "Mortgage Tax Deed",
587
+ "Mortgage Warranty Deed",
588
+ "Mortgage ALTA Settlement Statement",
589
+ "Mortgage Home Inspection Waiver",
590
+ "Mortgage Insurance Disclosure"
591
+ ]
592
+ document_type_for_questionset = gr.Dropdown(choices=document_types, label="Select the Document Type")
593
+ tag_for_questionset = gr.Textbox(label="Please provide a name for the question set. Ex: rwikd-dot-basic-questionset-20230707.")
594
+ csv_file = gr.File(label="Load a csv - 2 columns with the headers as field, question", file_types=['.csv'], type='file')
595
+
596
+ with gr.Row():
597
+ status_for_loading_csv = gr.Textbox(label="Status", placeholder="", interactive=False)
598
+ load_csv = gr.Button("Upload data into the database").style(full_width=False)
599
+
600
+ load_pdf.click(load_pdf_and_generate_embeddings, inputs=[pdf_doc, open_ai_key, relevant_pages], outputs=status)
601
+ summarize_pdf.click(summarize_contents, outputs=summary)
602
+ load_csv.click(load_csv_and_store_questionset_into_sqlite, inputs=[csv_file, document_type_for_questionset, tag_for_questionset], outputs=status_for_loading_csv)
603
+
604
+ load_questionsets.click(retrieve_document_type_and_questionsettag_from_sqlite, outputs=questionsets)
605
+ load_fields_and_questions.click(retrieve_fields_and_questions, questionsets, fields_and_questions)
606
+ answers_for_predefined_question_set.click(answer_predefined_questions, questionsets, answers)
607
+
608
+ convert_into_ocr.click(ocr_converter, image_pdf, ocr_pdf)
609
+ submit_query.click(answer_query, input, output)
610
+
611
+ # Use this flavor of demo.launch if you need the app to have an admin page.
612
+ demo.launch(debug=True)