-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.py
54 lines (41 loc) · 1.88 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
from flask import Flask,render_template,request,jsonify
import main
""" pipeline FLask application """
app = Flask(__name__)
@app.route('/',methods=['post','get'])
def index():
if request.method == 'POST':
data = request.get_json(force=True)
# get user pipeline selected configuration option
config = data['configuration']#return string
# get user sentence
sentence = data['user_utterance']
# get candidate selection(pruning) flag
if "pruning" in data:
pruning = data['pruning']
else:
pruning = "Off"
# check if user want to compute paraphrases automated quality scores
if "compute_metrics" in data:
compute_metrics = data['compute_metrics']
else:
compute_metrics = "Off"# default value don't compute
# check if pivot-level radio option is not disabled
if "pivot_level" in data:
# get selected pivot level option: 1-pivot or 2-pivot
pivot_level = data['pivot_level']#return string
# Machine Translator option: pre-trained MT(e.g. Huggingface Marian MT) or Online MT model(Deepl,Google)
pre_trained = data['pre_trained_mt']#return string
else:
pivot_level = None
pre_trained = None
# check T5 num_seq_slider(number of independently computed returned sequences for each element in the batch)
if 'num_seq_slider' in data:
num_seq = int(data['num_seq_slider'])
else:
num_seq = None
paraphrases = main.generate_from_gui(sentence,config,pruning=pruning,pivot_level=pivot_level,pre_trained=pre_trained,num_seq=num_seq,compute_metrics=compute_metrics)
return jsonify(paraphrases)
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)