-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
37 lines (24 loc) · 760 Bytes
/
api.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
# -*- coding:UTF-8 -*-
#
from flask import Flask, jsonify
from flask import request
import logging
import service
app = Flask(__name__)
@app.route('/api/v1.0/lstm', methods=['POST'])
def create_lstm():
if not request.json or not 'text' in request.json:
abort(400)
# sentence = (request.json['text']).encode('utf-8')
sentence = (request.json['text'])
print(u'sentence: %s' % str(sentence))
per, loc, org = service.do_lstm(str(sentence))
return jsonify({'text': {'per': per, 'loc': loc, 'org': org}}), 201
if __name__ == '__main__':
hdl = logging.FileHandler('api.log', encoding='UTF-8')
hdl.setLevel(logging.DEBUG)
app.logger.addHandler(hdl)
app.run(host="0.0.0.0", port=8183, debug=False)
#
# Eof
#