-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_path.py
50 lines (43 loc) · 1.38 KB
/
server_path.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
##############server_path.py##############
import time
import logging
import argsparser
from flask_restplus import *
from flask import *
import numpy
from jessica_text_embedding import text_embedding
ns = Namespace('jessica', description='')
args = argsparser.prepare_args()
parser = ns.parser()
parser.add_argument('text', type=str, location='json')
req_fields = {'text': fields.String(example = u"Abu Dhabi Finance")}
jessica_api_req = ns.model('jessica_req_fields', req_fields)
rsp_fields = {
'embedding_vector': fields.List(fields.Float),
'embedding_vector_dim':fields.Integer,
'error':fields.String,
'running_time':fields.Float
}
jessica_api_rsp = ns.model('jessica_rsp_fields', rsp_fields)
@ns.route('/bert_text_embedding')
class jessica_api(Resource):
def __init__(self, *args, **kwargs):
super(jessica_api, self).__init__(*args, **kwargs)
@ns.marshal_with(jessica_api_rsp)
@ns.expect(jessica_api_req)
def post(self):
start = time.time()
try:
args = parser.parse_args()
output = {}
output['embedding_vector_dim'] = 2048
output['embedding_vector'] = text_embedding(args['text'])
output['error'] = 'success'
output['running_time'] = float(time.time()- start)
return output, 200
except Exception as e:
output = {}
output['error'] = str(e)
output['running_time'] = float(time.time()- start)
return output
##############server_path.py##############