TheDarkLord69696969 commited on
Commit
b6ca154
1 Parent(s): 7ea139a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +433 -0
app.py ADDED
@@ -0,0 +1,433 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import docx
3
+ from docx import Document
4
+ import os
5
+ import fill_doc
6
+ # import languages
7
+ from flask import Flask, redirect, url_for, render_template, session
8
+ from flask import send_file
9
+ from flask_wtf import FlaskForm
10
+ from wtforms.fields import DateField
11
+ from wtforms.validators import DataRequired
12
+ from wtforms import validators, SubmitField, FileField
13
+ from flask_wtf import Form
14
+ from flask import request
15
+ from werkzeug.utils import secure_filename
16
+ app = Flask(__name__)
17
+ # app.config['SECRET_KEY'] = 'Some_Text'
18
+ # app.config['UPLOADED_DOCX_DEST'] = './'
19
+ # class Upload(FlaskForm):
20
+ # file = FileField("File")
21
+ # submit = SubmitField("Upload File")
22
+ app.static_folder = 'static'
23
+
24
+ @app.route("/")
25
+ def home():
26
+ return render_template("index.html")
27
+
28
+ @app.route("/downloadfile/")
29
+ def files():
30
+ file_name = str(request.args.get("file_name"))
31
+
32
+ # print(temp_name)
33
+ try:
34
+ return send_file('{}'.format(file_name), attachment_filename=file_name)
35
+ except Exception as e:
36
+ return str(e)
37
+
38
+ ALLOWED_EXTENSIONS = set(['txt','docx', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
39
+
40
+ def allowed_file(filename):
41
+ return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
42
+
43
+ @app.route('/uploader', methods=['POST'])
44
+ def upload_file():
45
+ # check if the post request has the file part
46
+ if 'file' not in request.files:
47
+ resp = {
48
+ "message" : 'No file part in the request',
49
+ "status_code" : 400
50
+ }
51
+ return resp
52
+ file = request.files['file']
53
+ if file.filename == '':
54
+ resp = {
55
+ "message" : 'No file selected for uploading',
56
+ "status_code": 400
57
+ }
58
+ return resp
59
+ if file and allowed_file(file.filename):
60
+ filename = secure_filename(file.filename)
61
+ #uploaded_filename = str(request.args.get("uploaded_filename"))
62
+ file.save(os.path.join('./templates', filename))
63
+ resp = {
64
+ "message" : 'File successfully uploaded',
65
+ "status_code" : 201
66
+ }
67
+ return resp
68
+ else:
69
+ resp = {
70
+ "message" : 'Allowed file types are txt, pdf, png, jpg, jpeg, gif',
71
+ "status_code" : 400
72
+ }
73
+ return resp
74
+
75
+ # @app.route('/uploader', methods = ['GET', 'POST'])
76
+ # def upload_file():
77
+ # if request.method == 'POST':
78
+ # f = request.files['file']
79
+ # f.save(secure_filename(f.filename))
80
+ # return 'file uploaded successfully'
81
+
82
+ # Translation, Important Information Extraction, Similar Clause Search, Template Question generation
83
+ @app.route("/get")
84
+ def index():
85
+ #temp
86
+ st = int(request.args.get('st'))
87
+ responses = request.args.get('ans')
88
+ name = request.args.get('name')
89
+ ans=""
90
+ # new_ans=""
91
+ lang = str(request.args.get('lang'))
92
+ trg = str(request.args.get('trg'))
93
+ trg = lang
94
+ src = str(request.args.get('src'))
95
+ file_name = str(request.args.get('file_name'))
96
+ variables = json.loads(request.args.get('variables'))
97
+ temp = str(request.args.get('temp'))
98
+ new_string = "{{" + temp + "}}"
99
+ variables[new_string] = responses
100
+ inputType = "text"
101
+ #INDIC = ["as", "bn", "gu", "hi", "kn", "ml", "mr", "or", "pa", "ta", "te"]
102
+ if st == -2:
103
+ if responses.lower().find('hindi') != -1:
104
+ lang = 'hi'
105
+ elif responses.lower().find('english') != -1:
106
+ lang = 'en'
107
+ elif responses.lower().find('assamese') != -1:
108
+ lang = 'as'
109
+ elif responses.lower().find('bengali') != -1:
110
+ lang = 'bn'
111
+ elif responses.lower().find('gujarati') != -1:
112
+ lang = 'gu'
113
+ elif responses.lower().find('kannada') != -1:
114
+ lang = 'kn'
115
+ elif responses.lower().find('malyalam') != -1:
116
+ lang = 'ml'
117
+ elif responses.lower().find('marathi') != -1:
118
+ lang = 'mr'
119
+ elif responses.lower().find('oriya') != -1:
120
+ lang = 'or'
121
+ elif responses.lower().find('punjabi') != -1:
122
+ lang = 'pa'
123
+ elif responses.lower().find('tamil') != -1:
124
+ lang = 'ta'
125
+ elif responses.lower().find('telugu') != -1:
126
+ lang = 'te'
127
+ else:
128
+ lang = 'en'
129
+ if st == -1 and (responses.lower().find('drafting') != -1 or responses.lower().find('draft') != -1):
130
+ st = -1
131
+ elif st == -1:
132
+ st = 34
133
+ if st == 0 and responses.lower().find('will') != -1:
134
+ st = 0
135
+ elif st == 0 and responses.lower().find('employer') != -1:
136
+ st = 40
137
+ elif st == 0 and responses.lower().find('employee') != -1:
138
+ st = 81
139
+ elif st == 0 and responses.lower().find('will') == -1:
140
+ st = 24
141
+
142
+ if st == 8 and int(responses) > 0 :
143
+ st = 8
144
+ elif st==8 and int(responses) == 0:
145
+ st = 9
146
+ elif st==16 and responses == "No":
147
+ st = 17
148
+ elif st==16 and responses != "No":
149
+ st = 16
150
+ # fileName = name+".csv"
151
+ # f = open(fileName, "a")
152
+ # #f.write(st+"\t")
153
+ # f.write(responses+"\n")
154
+ # f.close()
155
+
156
+ msgg = " "
157
+ if st == -2:
158
+ ans = "What do you want to do? (Drafting or Analysis) "
159
+ # new_ans = languages(ans,'en',lang)
160
+ elif st == -1:
161
+ ans = "What do you want to Draft?"
162
+ elif st == 0:
163
+ ans = "What is your name?"
164
+ msgg = "Please state your full name as is given in your Matriculation Certificate/valid ID proof."
165
+ elif st == 1:
166
+ ans = "What is your date of birth?"
167
+ inputType = "date"
168
+ msgg = "Please select date from the calender"
169
+ elif st == 2:
170
+ ans = "What is your gender?"
171
+ msgg = "Select the gender of the person whose will is being made."
172
+ elif st == 3:
173
+ ans = "What are your preferred pronouns?"
174
+ msgg = '''Select your pronouns. These shall be used as reference to the person whose will is being made, throughout the document.
175
+ '''
176
+ elif st == 4:
177
+ ans = "What is your father/mothers’ name?"
178
+ msgg = "Please enter either the name of your father or your mother."
179
+ elif st == 5:
180
+ ans = "What is your marital status?"
181
+ msgg = "Please indicate your marital status."
182
+ elif st == 6:
183
+ ans = "What is your religion?"
184
+
185
+ elif st == 7:
186
+ ans = "Do you have any children?"
187
+ inputType = "number"
188
+ msgg = "Please state how many children you have. If you do have a child/children, please state their details as required."
189
+ elif st == 8:
190
+ ans = "Write Your Children Details"
191
+ msgg = "Format should be Name of child, Sex of child, Age of child, Address of child for each child"
192
+ elif st == 9:
193
+ ans = "What is your address?"
194
+ msgg = "Please state the address where you are presently residing."
195
+ elif st == 10:
196
+ ans = "Where is your will being executed?"
197
+ msgg = "Please state the name of the place where your will is being executed/signed."
198
+ elif st == 11:
199
+ ans = "What is the date on which your will is being executed?"
200
+ inputType = "date"
201
+ msgg = "Please mention the date on which your will is being executed/signed."
202
+ elif st == 12:
203
+ ans = "Who are your beneficiaries?"
204
+ msgg = "Please state your beneficiaries. Beneficiaries are any and all those persons whom you wish to bequeath your asset/liability to, under this will."
205
+ elif st == 13:
206
+ ans = "Who is the executor of your will?"
207
+ msgg = '''Please state the name and other details of your executor. An executor is a person who will be responsible for ensuring that the terms of your will are followed, including division of assets and liabilities as per your wishes. '''
208
+ elif st == 14:
209
+ ans = "What are the duties of your executor?"
210
+ msgg = "Please select the duties which you would like the executor to observe under your will."
211
+ elif st == 15:
212
+ ans = "Do you want to compensate the executor for disposing of your will?"
213
+ elif st == 16:
214
+ ans = "Write the amount to compensate the executor for disposing of your will?"
215
+ msgg = "If you would like to compensate the executor, kindly mention the amount."
216
+ elif st == 17:
217
+ ans = "What are your assets?"
218
+ msgg = "Please mention details about all your assets, both immovable and movable, and the details of the person/organization you are bequeathing it to."
219
+ elif st == 18:
220
+ ans = "What are your liabilities?"
221
+ msgg = '''Please mention details about all your liabilities, and the details of the person/organization you are bequeathing it to.
222
+ '''
223
+ elif st == 19:
224
+ ans = "Will you appoint a guardian for your minor child?"
225
+ elif st == 20:
226
+ ans = "How would you prefer the disposal of remains?"
227
+ ans = "Please state details about how you would like your remains to be disposed off."
228
+ elif st == 24:
229
+ ans = "When is the deed going to be executed?"
230
+ inputType = "date"
231
+ elif st == 25:
232
+ ans = "Where is the deed going to be executed?"
233
+ elif st == 26:
234
+ ans = "Are you the Donor or the Donee?"
235
+ elif st == 27:
236
+ ans = "Please provide your name, father’s name and address."
237
+ elif st == 28:
238
+ ans = "Please provide the other party’s name, father’s name and address."
239
+ elif st == 29:
240
+ ans = "What is the relationship between the parties?"
241
+ elif st == 30:
242
+ ans = "What type of asset is to be gifted? (Drop down box with options like land, movable property, building, cash in bank account, etc)"
243
+ elif st == 31:
244
+ ans = "Please provide details of the asset to be gifted."
245
+ elif st == 32:
246
+ ans = "What is the value of the asset mentioned above?"
247
+ elif st == 33:
248
+ ans = "Please provide the name and address of the witnesses."
249
+ elif st == 34:
250
+ ans = f'''
251
+ <html>
252
+ <body>
253
+ <h3> Please upload the Document to be Analyzed. </h3>
254
+ <input id="fileupload" type="file" name="fileupload" />
255
+ <button id="upload-button" onclick="uploadFile()"> Upload file </button>
256
+ </body>
257
+ </html>
258
+ '''
259
+ elif st == 35:
260
+ # ans = f'''
261
+ # <html>
262
+ # <body>
263
+ # <div class = "form-group">
264
+ # <label for = "Documents"> Please select the Analysis </label>
265
+ # <select id = "dropdown" class = "form-control" name = "Documents"
266
+ # required="">
267
+ # <option value = "Translation">Translation </option>
268
+ # <option value = "Important Information Extraction">Important Information Extraction </option>
269
+ # <option value = "Similar Clause Search">Similar Clause Search </option>
270
+ # <option value = "Template Question generation">Template Question generation </option>
271
+ # </select>
272
+ # </body>
273
+ # </html>
274
+ # '''
275
+ ans = "Please select anyone of this!"
276
+ inputType="select"
277
+ elif st == 21:
278
+ ans = "Other special instructions"
279
+ msgg = "Please mention any other special instructions which you may wish to include in your will."
280
+ elif st == 22:
281
+ file_path = r"C:\Users\Prince Raj\Desktop\BOT\Last Will and Testament.docx"
282
+ assert os.path.isfile(file_path)
283
+ with open(file_path, "r") as f:
284
+ pass
285
+ result_path = name + ".docx"
286
+ # assert os.path.isfile(result_path)
287
+ # with open(result_path, "r") as f:
288
+ # pass
289
+ # temp_name = result_path
290
+ fill_doc(file_path, result_path, variables)
291
+ # print(temp_name)
292
+ inputType = 'text'
293
+ ans = f'''
294
+ <html>
295
+ <body>
296
+ <a href="/downloadfile?file_name={result_path}" >{result_path} Download</a>
297
+ </body>
298
+ </html>
299
+ '''
300
+ #name.docx
301
+ inputType = "text"
302
+ elif st == 40:
303
+ ans = "What is the name of the company?"
304
+ elif st == 41:
305
+ ans = "What is the employee code?"
306
+ elif st == 42:
307
+ ans = "What is the employee name?"
308
+ elif st == 43:
309
+ ans = "What is the date of the appointment letter?"
310
+ inputType = "date"
311
+ elif st == 44:
312
+ ans = "What is the date of appointment?"
313
+ inputType = "date"
314
+ elif st == 45:
315
+ ans = "What was the date of interview?"
316
+ inputType = "date"
317
+ elif st == 46:
318
+ ans = "What is the designation?"
319
+ elif st == 47:
320
+ ans = "What is the place of the execution this agreement?"
321
+ #both - needs to be the same
322
+ elif st == 48:
323
+ ans = "What is the date of execution of this agreement?"
324
+ inputType = "date"
325
+ elif st == 49:
326
+ ans = "Company Details - What is the CIN no?"
327
+ elif st == 50:
328
+ ans = "Company Details - What is the PAN no?"
329
+ elif st == 51:
330
+ ans = "Company Details - What is registered office address?"
331
+ elif st == 52:
332
+ ans = "Company Details - What is the name of authorized signatory/director?"
333
+ elif st == 53:
334
+ ans = "Company Details - What is the date of the board resolution?"
335
+ elif st == 54:
336
+ ans = "Which department is employee assigned to?"
337
+ elif st == 55:
338
+ ans = "What is the term?"
339
+ elif st == 56:
340
+ ans = "Who shall the employee report to?"
341
+ elif st == 57:
342
+ ans = "What is the place of posting?"
343
+ elif st == 58:
344
+ ans = "What is the probationary period?"
345
+ elif st == 59:
346
+ ans = "What is the notice period for resignation during probationary period?"
347
+ elif st == 60:
348
+ ans = "What shall be the working hours during the week?"
349
+ elif st == 61:
350
+ ans = "What is the number of casual leave days entitled to the employee?"
351
+ elif st == 62:
352
+ ans = "What is the number of sick days entitled to the employee?"
353
+ elif st == 63:
354
+ ans = "What is the number of public holidays entitled to the employee?"
355
+ elif st == 64:
356
+ ans = "Whom shall the employee report to in case of unforeseen sickness/injury?"
357
+ elif st == 65:
358
+ ans = "Within how many hours is the employee supposed to inform in case of unforeseen sickness/injury?"
359
+ elif st == 66:
360
+ ans = "For how many days of absence does the employee need to submit the self certification form?"
361
+ elif st == 67:
362
+ ans = "For how many days of absence does the employee need to submit a medical certificate signed by a medical practitioner?"
363
+ elif st == 68:
364
+ ans = "What shall be employee’s responsibilities?"
365
+ elif st == 69:
366
+ ans = "What shall be the employee’s obligations?"
367
+ elif st == 70:
368
+ ans = "What shall be the grounds of termination?"
369
+ elif st == 71:
370
+ ans = "What shall be the notice period for the employee to resign?"
371
+ elif st == 72:
372
+ ans = "For how many years shall the employee be bound by confidentiality?"
373
+ elif st == 73:
374
+ ans = "Company Notice Details - What is the name of the designated person?"
375
+ elif st == 74:
376
+ ans = "Company Notice Details - What is the address of designated person?"
377
+ elif st == 75:
378
+ ans = "Company Notice Details - What is the email ID of the designated person?"
379
+ elif st == 76:
380
+ ans = "For how many years shall the employee be bound by non - solicitation and non - compete?"
381
+ elif st == 77:
382
+ ans = "Applicable laws of which place shall apply?"
383
+ elif st == 78:
384
+ ans = "Which courts will have jurisdiction during dispute resolution?"
385
+ elif st == 79:
386
+ with open("employer", "w") as fp:
387
+ json.dump(variables,fp)
388
+ ans = "Thank you for recording your responses!"
389
+ elif st == 81:
390
+ ans = "What is the place of the execution this agreement?"
391
+ elif st == 82:
392
+ ans = "What is the date of execution of this agreement?"
393
+ inputType = "date"
394
+ elif st == 83:
395
+ ans = "Employee Details - What is the name of father of employee?"
396
+ elif st == 84:
397
+ ans = "Employee Details - What is the address of the employee?"
398
+ elif st == 85:
399
+ ans = "Employee Notice Details - What is the name of the employee?"
400
+ elif st == 86:
401
+ ans = "Employee Notice Details - What is the address of the employee?"
402
+ elif st == 87:
403
+ ans = "Employee Notice Details - What is the email ID of the employee?"
404
+ else:
405
+ with open('employer', 'r') as f:
406
+ data = json.load(f)
407
+ q1 = "{{What is the place of the execution this agreement?}}"
408
+ q2 = "{{What is the date of execution of this agreement?}}"
409
+ if data[q1] == variables[q1] and data[q2] == variables[q2]:
410
+ ans = "Responses matched : Success!"
411
+ elif data[q1] != variables[q1] and data[q2] != variables[q2]:
412
+ ans = "Responses did not match --> " + "Employer Response for : " + "What is the place of the execution this agreement? -> " + data[q1] + " and " + "Employee Response for : " + "What is the place of the execution this agreement? -> " + variables[q1] + "\nEmployer Response for " + "What is the date of execution of this agreement? -> "+ data[q2] + " and " + "Employee Response for " + "What is the date of execution of this agreement? -> "+ variables[q2]
413
+ elif data[q1] != variables[q1]:
414
+ ans = "Responses did not match --> " + "Employer Response for : " + "What is the place of the execution this agreement? -> " + data[q1] + " and " + "Employee Response for : " + "What is the place of the execution this agreement? -> " + variables[q1]
415
+ else:
416
+ ans = "Responses did not match --> " + "Employer Response for : " + "What is the date of execution of this agreement? -> "+ data[q2] + " and " + "Employee Response for : " + "What is the date of execution of this agreement? -> "+ variables[q2]
417
+ with open("employee", "w") as fp:
418
+ json.dump(variables,fp)
419
+ res = {
420
+ "ans": ans,
421
+ "inputType": inputType,
422
+ "msgg": msgg,
423
+ "st":st,
424
+ "temp":ans,
425
+ "variables": variables,
426
+ "file_name":file_name,
427
+ "lang":lang
428
+ }
429
+ return res
430
+
431
+
432
+ if __name__ == "__main__":
433
+ app.run(port=5001)