-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
51 lines (34 loc) · 1.08 KB
/
server.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
from flask import Flask, request, render_template
import json
import sys
import time
from train import split_sentences, train_model
sys.path.insert(0, './utils')
TEMPLATES_AUTO_RELOAD = True
app = Flask(__name__)
@app.route('/', methods=['GET'])
def get_render_gui():
return render_template('gui.html')
@app.route('/split_sents', methods=['POST'])
def split_sents():
text = request.form.get("text")
sentences = split_sentences(text)
return json.dumps(sentences)
@app.route('/send_ner', methods=['POST'])
def send_ner():
data = request.form.get("ner")
model_name = request.form.get("model_name")
jsonData = json.loads(data)
TRAIN_DATA = []
for key in jsonData:
sentence = key
tuple = (sentence,
{'entities': [(x[0], x[1], x[2]) for x in jsonData[key]["entities"]]}
)
TRAIN_DATA.append(tuple)
print(TRAIN_DATA)
train_model(output_dir="./models/"+model_name, training_data=TRAIN_DATA)
return "OK"
app.jinja_env.auto_reload = True
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.run(host= '0.0.0.0')