-
Notifications
You must be signed in to change notification settings - Fork 1
/
tsener_api.py
61 lines (54 loc) · 1.93 KB
/
tsener_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
from flask import Flask, jsonify, request
from flasgger import Swagger
from flasgger.utils import swag_from
from m2_labelling import ner_labelling
from config import ROOTPATH
import flask
app = Flask(__name__)
template = {
"swagger": "2.0",
"info": {
"description": "This is the server for users interested in training and using NER models to label long-tail "
"entities in text. Find more information about TSE-NER in the [paper](to-do.tudelft) and check "
"out our [code](https://github.com/mvallet91/SmartPub-TSENER) for more details and if you want "
"to create your own application.",
"version": "1.0.0",
"title": "SmartPub TSE-NER",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"email": "[email protected]"},
"license": {
"name": "GNU GPL v3.0",
"url": "https://github.com/mvallet91/SmartPub-TSENER/blob/master/LICENSE"}
}
}
Swagger(app, template=template)
# @app.route('/api/<string:model_name>/', methods=['GET'])
# @swag_from('m1_index.yml')
# def m1(model_name):
# word_list = model_name.split()
# word_list = [w.lower().strip() for w in word_list]
# model = str(request.args.get('model', 1))
# results = filtering.filter_ws_fly(word_list)
# return jsonify(
# text=model_name,
# model=model,
# entities=results
# )
@app.route('/api/<string:text>/', methods=['GET'])
@swag_from('m2_index.yml')
def m2(text):
model = str(request.args.get('model', 1))
path_to_model = ROOTPATH + '/crf_trained_files/' + model + '_TSE_model_3.ser.gz'
if not os.path.isfile(path_to_model):
flask.abort(501)
if len(text) > 10000:
flask.abort(502)
results = ner_labelling.long_tail_labelling(model, text)
return jsonify(
text=text,
model=model,
entities=results
)
app.run(debug=True)