import json import docx from docx import Document import os import fill_doc # import languages from flask import Flask, redirect, url_for, render_template, session from flask import send_file from flask_wtf import FlaskForm from wtforms.fields import DateField from wtforms.validators import DataRequired from wtforms import validators, SubmitField, FileField from flask_wtf import Form from flask import request from werkzeug.utils import secure_filename app = Flask(__name__) # app.config['SECRET_KEY'] = 'Some_Text' # app.config['UPLOADED_DOCX_DEST'] = './' # class Upload(FlaskForm): # file = FileField("File") # submit = SubmitField("Upload File") app.static_folder = 'static' @app.route("/") def home(): return render_template("index.html") @app.route("/downloadfile/") def files(): file_name = str(request.args.get("file_name")) # print(temp_name) try: return send_file('{}'.format(file_name), attachment_filename=file_name) except Exception as e: return str(e) ALLOWED_EXTENSIONS = set(['txt','docx', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS @app.route('/uploader', methods=['POST']) def upload_file(): # check if the post request has the file part if 'file' not in request.files: resp = { "message" : 'No file part in the request', "status_code" : 400 } return resp file = request.files['file'] if file.filename == '': resp = { "message" : 'No file selected for uploading', "status_code": 400 } return resp if file and allowed_file(file.filename): filename = secure_filename(file.filename) #uploaded_filename = str(request.args.get("uploaded_filename")) file.save(os.path.join('./templates', filename)) resp = { "message" : 'File successfully uploaded', "status_code" : 201 } return resp else: resp = { "message" : 'Allowed file types are txt, pdf, png, jpg, jpeg, gif', "status_code" : 400 } return resp # @app.route('/uploader', methods = ['GET', 'POST']) # def upload_file(): # if request.method == 'POST': # f = request.files['file'] # f.save(secure_filename(f.filename)) # return 'file uploaded successfully' # Translation, Important Information Extraction, Similar Clause Search, Template Question generation @app.route("/get") def index(): #temp st = int(request.args.get('st')) responses = request.args.get('ans') name = request.args.get('name') ans="" # new_ans="" lang = str(request.args.get('lang')) trg = str(request.args.get('trg')) trg = lang src = str(request.args.get('src')) file_name = str(request.args.get('file_name')) variables = json.loads(request.args.get('variables')) temp = str(request.args.get('temp')) new_string = "{{" + temp + "}}" variables[new_string] = responses inputType = "text" #INDIC = ["as", "bn", "gu", "hi", "kn", "ml", "mr", "or", "pa", "ta", "te"] if st == -2: if responses.lower().find('hindi') != -1: lang = 'hi' elif responses.lower().find('english') != -1: lang = 'en' elif responses.lower().find('assamese') != -1: lang = 'as' elif responses.lower().find('bengali') != -1: lang = 'bn' elif responses.lower().find('gujarati') != -1: lang = 'gu' elif responses.lower().find('kannada') != -1: lang = 'kn' elif responses.lower().find('malyalam') != -1: lang = 'ml' elif responses.lower().find('marathi') != -1: lang = 'mr' elif responses.lower().find('oriya') != -1: lang = 'or' elif responses.lower().find('punjabi') != -1: lang = 'pa' elif responses.lower().find('tamil') != -1: lang = 'ta' elif responses.lower().find('telugu') != -1: lang = 'te' else: lang = 'en' if st == -1 and (responses.lower().find('drafting') != -1 or responses.lower().find('draft') != -1): st = -1 elif st == -1: st = 34 if st == 0 and responses.lower().find('will') != -1: st = 0 elif st == 0 and responses.lower().find('employer') != -1: st = 40 elif st == 0 and responses.lower().find('employee') != -1: st = 81 elif st == 0 and responses.lower().find('will') == -1: st = 24 if st == 8 and int(responses) > 0 : st = 8 elif st==8 and int(responses) == 0: st = 9 elif st==16 and responses == "No": st = 17 elif st==16 and responses != "No": st = 16 # fileName = name+".csv" # f = open(fileName, "a") # #f.write(st+"\t") # f.write(responses+"\n") # f.close() msgg = " " if st == -2: ans = "What do you want to do? (Drafting or Analysis) " # new_ans = languages(ans,'en',lang) elif st == -1: ans = "What do you want to Draft?" elif st == 0: ans = "What is your name?" msgg = "Please state your full name as is given in your Matriculation Certificate/valid ID proof." elif st == 1: ans = "What is your date of birth?" inputType = "date" msgg = "Please select date from the calender" elif st == 2: ans = "What is your gender?" msgg = "Select the gender of the person whose will is being made." elif st == 3: ans = "What are your preferred pronouns?" msgg = '''Select your pronouns. These shall be used as reference to the person whose will is being made, throughout the document. ''' elif st == 4: ans = "What is your father/mothers’ name?" msgg = "Please enter either the name of your father or your mother." elif st == 5: ans = "What is your marital status?" msgg = "Please indicate your marital status." elif st == 6: ans = "What is your religion?" elif st == 7: ans = "Do you have any children?" inputType = "number" msgg = "Please state how many children you have. If you do have a child/children, please state their details as required." elif st == 8: ans = "Write Your Children Details" msgg = "Format should be Name of child, Sex of child, Age of child, Address of child for each child" elif st == 9: ans = "What is your address?" msgg = "Please state the address where you are presently residing." elif st == 10: ans = "Where is your will being executed?" msgg = "Please state the name of the place where your will is being executed/signed." elif st == 11: ans = "What is the date on which your will is being executed?" inputType = "date" msgg = "Please mention the date on which your will is being executed/signed." elif st == 12: ans = "Who are your beneficiaries?" msgg = "Please state your beneficiaries. Beneficiaries are any and all those persons whom you wish to bequeath your asset/liability to, under this will." elif st == 13: ans = "Who is the executor of your will?" 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. ''' elif st == 14: ans = "What are the duties of your executor?" msgg = "Please select the duties which you would like the executor to observe under your will." elif st == 15: ans = "Do you want to compensate the executor for disposing of your will?" elif st == 16: ans = "Write the amount to compensate the executor for disposing of your will?" msgg = "If you would like to compensate the executor, kindly mention the amount." elif st == 17: ans = "What are your assets?" msgg = "Please mention details about all your assets, both immovable and movable, and the details of the person/organization you are bequeathing it to." elif st == 18: ans = "What are your liabilities?" msgg = '''Please mention details about all your liabilities, and the details of the person/organization you are bequeathing it to. ''' elif st == 19: ans = "Will you appoint a guardian for your minor child?" elif st == 20: ans = "How would you prefer the disposal of remains?" ans = "Please state details about how you would like your remains to be disposed off." elif st == 24: ans = "When is the deed going to be executed?" inputType = "date" elif st == 25: ans = "Where is the deed going to be executed?" elif st == 26: ans = "Are you the Donor or the Donee?" elif st == 27: ans = "Please provide your name, father’s name and address." elif st == 28: ans = "Please provide the other party’s name, father’s name and address." elif st == 29: ans = "What is the relationship between the parties?" elif st == 30: ans = "What type of asset is to be gifted? (Drop down box with options like land, movable property, building, cash in bank account, etc)" elif st == 31: ans = "Please provide details of the asset to be gifted." elif st == 32: ans = "What is the value of the asset mentioned above?" elif st == 33: ans = "Please provide the name and address of the witnesses." elif st == 34: ans = f'''