-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
87 lines (70 loc) · 3.16 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
import json
from flask import Flask, request, render_template, flash, redirect, url_for, send_from_directory
from werkzeug.utils import secure_filename
from main_generate_bpmn_xml import BPMN
from neural_coref import NeuralCoref
ALLOWED_EXTENSIONS = {'txt'}
app = Flask(__name__)
app.secret_key = os.urandom(24)
app.config['UPLOAD_FOLDER'] = 'data'
app.config['MAX_CONTENT_LENGTH'] = 4 * 1024 * 1024 # 4MB max-limit.
flow = []
lane = []
svo = []
# check input file's file extension
def allowed_file(filename):
return '.' in filename and filename.rsplit('.',1)[1].lower() in ALLOWED_EXTENSIONS
# home page
@app.route('/', methods=['POST', 'GET'])
def upload_file():
if request.method == 'POST':
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], "result_bpmn_process_from_nlp.bpmn"))
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], "result_bpmn_process_from_nlp.xml"))
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
read_text = []
for text in request.files.get('file'):
read_text.append(str(text).replace("b'",""))
# run the test function
neuralCoref = NeuralCoref(read_text[0])
text = neuralCoref.get_sentence()
process_name = "BPMN Process"
is_show_lane = True
is_show_gateway = False
bpmn = BPMN(text, process_name)
list_flow, json_list_lane, list_svo_to_generate_bpmn_in_out_diagram = bpmn.bpmn_process(is_show_lane, is_show_gateway)
flow.append(list_flow)
lane.append(json_list_lane)
svo.append(list_svo_to_generate_bpmn_in_out_diagram)
# if the user does not select a file, browser submits an empty file without a filename.
if file.filename == '':
flash('No selected file')
return redirect(request.url)
# if the user submits a file with the correct format
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('download_file'))
return render_template('index.html')
# download page
@app.route('/download', methods=['POST', 'GET'])
def download_file():
if request.method == 'POST':
if request.form['Download Result File'] == 'Download BPMN File':
return send_from_directory(app.config['UPLOAD_FOLDER'], 'result_bpmn_process_from_nlp.bpmn')
json_flow = json.dumps(flow[0], sort_keys = False, indent = 2)
json_lane = json.dumps(lane[0], sort_keys = False, indent = 2)
json_svo = json.dumps(svo[0], sort_keys = False, indent = 2)
return render_template('download.html', flow=json_flow, lane=json_lane, svo=json_svo)
# show xml
@app.route('/showxml', methods=['POST', 'GET'])
def show_xml():
if request.method == 'GET':
return send_from_directory(app.config['UPLOAD_FOLDER'], 'result_bpmn_process_from_nlp.xml')
if __name__ == '__main__':
app.run(debug=True)