template_maker / app.py
TheDarkLord69696969's picture
Upload app.py
b6ca154
raw
history blame
No virus
18 kB
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'''
<html>
<body>
<h3> Please upload the Document to be Analyzed. </h3>
<input id="fileupload" type="file" name="fileupload" />
<button id="upload-button" onclick="uploadFile()"> Upload file </button>
</body>
</html>
'''
elif st == 35:
# ans = f'''
# <html>
# <body>
# <div class = "form-group">
# <label for = "Documents"> Please select the Analysis </label>
# <select id = "dropdown" class = "form-control" name = "Documents"
# required="">
# <option value = "Translation">Translation </option>
# <option value = "Important Information Extraction">Important Information Extraction </option>
# <option value = "Similar Clause Search">Similar Clause Search </option>
# <option value = "Template Question generation">Template Question generation </option>
# </select>
# </body>
# </html>
# '''
ans = "Please select anyone of this!"
inputType="select"
elif st == 21:
ans = "Other special instructions"
msgg = "Please mention any other special instructions which you may wish to include in your will."
elif st == 22:
file_path = r"C:\Users\Prince Raj\Desktop\BOT\Last Will and Testament.docx"
assert os.path.isfile(file_path)
with open(file_path, "r") as f:
pass
result_path = name + ".docx"
# assert os.path.isfile(result_path)
# with open(result_path, "r") as f:
# pass
# temp_name = result_path
fill_doc(file_path, result_path, variables)
# print(temp_name)
inputType = 'text'
ans = f'''
<html>
<body>
<a href="/downloadfile?file_name={result_path}" >{result_path} Download</a>
</body>
</html>
'''
#name.docx
inputType = "text"
elif st == 40:
ans = "What is the name of the company?"
elif st == 41:
ans = "What is the employee code?"
elif st == 42:
ans = "What is the employee name?"
elif st == 43:
ans = "What is the date of the appointment letter?"
inputType = "date"
elif st == 44:
ans = "What is the date of appointment?"
inputType = "date"
elif st == 45:
ans = "What was the date of interview?"
inputType = "date"
elif st == 46:
ans = "What is the designation?"
elif st == 47:
ans = "What is the place of the execution this agreement?"
#both - needs to be the same
elif st == 48:
ans = "What is the date of execution of this agreement?"
inputType = "date"
elif st == 49:
ans = "Company Details - What is the CIN no?"
elif st == 50:
ans = "Company Details - What is the PAN no?"
elif st == 51:
ans = "Company Details - What is registered office address?"
elif st == 52:
ans = "Company Details - What is the name of authorized signatory/director?"
elif st == 53:
ans = "Company Details - What is the date of the board resolution?"
elif st == 54:
ans = "Which department is employee assigned to?"
elif st == 55:
ans = "What is the term?"
elif st == 56:
ans = "Who shall the employee report to?"
elif st == 57:
ans = "What is the place of posting?"
elif st == 58:
ans = "What is the probationary period?"
elif st == 59:
ans = "What is the notice period for resignation during probationary period?"
elif st == 60:
ans = "What shall be the working hours during the week?"
elif st == 61:
ans = "What is the number of casual leave days entitled to the employee?"
elif st == 62:
ans = "What is the number of sick days entitled to the employee?"
elif st == 63:
ans = "What is the number of public holidays entitled to the employee?"
elif st == 64:
ans = "Whom shall the employee report to in case of unforeseen sickness/injury?"
elif st == 65:
ans = "Within how many hours is the employee supposed to inform in case of unforeseen sickness/injury?"
elif st == 66:
ans = "For how many days of absence does the employee need to submit the self certification form?"
elif st == 67:
ans = "For how many days of absence does the employee need to submit a medical certificate signed by a medical practitioner?"
elif st == 68:
ans = "What shall be employee’s responsibilities?"
elif st == 69:
ans = "What shall be the employee’s obligations?"
elif st == 70:
ans = "What shall be the grounds of termination?"
elif st == 71:
ans = "What shall be the notice period for the employee to resign?"
elif st == 72:
ans = "For how many years shall the employee be bound by confidentiality?"
elif st == 73:
ans = "Company Notice Details - What is the name of the designated person?"
elif st == 74:
ans = "Company Notice Details - What is the address of designated person?"
elif st == 75:
ans = "Company Notice Details - What is the email ID of the designated person?"
elif st == 76:
ans = "For how many years shall the employee be bound by non - solicitation and non - compete?"
elif st == 77:
ans = "Applicable laws of which place shall apply?"
elif st == 78:
ans = "Which courts will have jurisdiction during dispute resolution?"
elif st == 79:
with open("employer", "w") as fp:
json.dump(variables,fp)
ans = "Thank you for recording your responses!"
elif st == 81:
ans = "What is the place of the execution this agreement?"
elif st == 82:
ans = "What is the date of execution of this agreement?"
inputType = "date"
elif st == 83:
ans = "Employee Details - What is the name of father of employee?"
elif st == 84:
ans = "Employee Details - What is the address of the employee?"
elif st == 85:
ans = "Employee Notice Details - What is the name of the employee?"
elif st == 86:
ans = "Employee Notice Details - What is the address of the employee?"
elif st == 87:
ans = "Employee Notice Details - What is the email ID of the employee?"
else:
with open('employer', 'r') as f:
data = json.load(f)
q1 = "{{What is the place of the execution this agreement?}}"
q2 = "{{What is the date of execution of this agreement?}}"
if data[q1] == variables[q1] and data[q2] == variables[q2]:
ans = "Responses matched : Success!"
elif data[q1] != variables[q1] and data[q2] != variables[q2]:
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]
elif data[q1] != variables[q1]:
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]
else:
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]
with open("employee", "w") as fp:
json.dump(variables,fp)
res = {
"ans": ans,
"inputType": inputType,
"msgg": msgg,
"st":st,
"temp":ans,
"variables": variables,
"file_name":file_name,
"lang":lang
}
return res
if __name__ == "__main__":
app.run(port=5001)