-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
49 lines (36 loc) · 1.58 KB
/
app.py
File metadata and controls
49 lines (36 loc) · 1.58 KB
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
from flask import abort, request, Flask, jsonify, render_template
from services.thaigov_attention import AttentionInferencer
from services.thaigov_attention2 import AttentionInferencer2
from services.thaigov_attention_with_stopword import AttentionWithStopwordInferencer
from services.extractive import ExtractiveInferencer
from services.seq2seq import Seq2SeqInferencer
inferencers = {
'1ext': ExtractiveInferencer(),
'attn': AttentionInferencer(),
'attn_stop': AttentionWithStopwordInferencer(),
'seq2seq': Seq2SeqInferencer()
}
model_options = list(map(lambda model: (model, inferencers[model].get_name()) , inferencers))
app = Flask(__name__)
@app.route('/', methods=['GET'])
def hello():
return render_template('index.html', options=model_options)
#! Just test not for fully used
@app.route('/preprocess', methods=['POST'])
def preprocess():
if not request.json or not 'content' in request.json:
abort(400)
preprocessed_text = preprocess_text(request.json['content'])
return jsonify({'preprocessed_text': preprocessed_text}), 201
# fully inference headline generation with word-based
@app.route('/inference/<inf_name>', methods=['POST'])
def infer(inf_name='thaigov'):
if not request.json or not 'content' in request.json:
abort(400)
if inf_name not in inferencers:
abort(404)
content = request.json['content']
inferred_headline = inferencers[inf_name].infer(content)
return jsonify({'inferred_headline': inferred_headline}), 201
if __name__ == '__main__':
app.run(debug=True, threaded=True, host='0.0.0.0')