-
Notifications
You must be signed in to change notification settings - Fork 7
/
nlp_server.py
45 lines (33 loc) · 1.1 KB
/
nlp_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
from flask import Flask, request
app = Flask(__name__, static_folder='static/nlp/', static_url_path='')
import json
import sys
import coffeescript, sass
from nlp import NLP
@app.route('/')
def root():
return app.send_static_file('index.html')
@app.route('/nlp-api', methods=['POST'])
def nlp_api():
return app.nlp.run(request.get_json())
def compile_assets():
static = app.static_folder
with open("{}/javascript/index.js".format(static), 'w') as f:
infile = "{}/coffeescript/index.coffee".format(static)
js = coffeescript.compile_file(infile)
f.write(js)
with open('{}/css/tagged-text.css'.format(app.static_folder), 'w') as f:
infile = "{}/scss/tagged-text.scss".format(static)
css = sass.compile(filename=infile)
f.write(css)
def server(config):
print('Compiling assets...')
compile_assets()
print('Loading NLP models...')
app.nlp = NLP(config)
return app
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: {} config.toml".format(sys.argv[0]))
sys.exit(1)
server(sys.argv[1]).run(debug=True)