-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrestApp.py
More file actions
62 lines (48 loc) · 1.74 KB
/
restApp.py
File metadata and controls
62 lines (48 loc) · 1.74 KB
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
import sys
sys.path.append('../')
from flask import Flask
from flask_restful import Api, Resource, reqparse
from flask_cors import CORS
from frameBERT import frame_parser
app = Flask(__name__)
CORS(app)
api = Api(app)
# import jpype
# jpype.attachThreadToJVM()
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--model', required=True)
parser.add_argument('--language', required=False, default='ko')
parser.add_argument('--port', required=False, default=1106)
args = parser.parse_args()
# In[1]:
f_parser = frame_parser.FrameParser(model_path=args.model, masking=True, language=args.language)
class WebService(Resource):
def __init__(self):
pass
# self.parser = frame_parser.FrameParser(model_path=args.model, masking=True, language=args.language)
def post(self):
try:
req_parser = reqparse.RequestParser()
req_parser.add_argument('text', type=str)
req_parser.add_argument('sent_id', type=str)
req_parser.add_argument('result_format', type=str)
args = req_parser.parse_args()
print(args)
if not args['sent_id']:
sent_id = False
else:
sent_id = args['sent_id']
if not args['result_format']:
result_format = 'graph'
else:
result_format = args['result_format']
result = f_parser.parser(args['text'], sent_id=sent_id, result_format=result_format)
return result, 200
except KeyboardInterrupt:
raise
except Exception as e:
return {'error':str(e)}
api.add_resource(WebService, '/frameBERT')
app.run(debug=True, host='0.0.0.0', port=args.port)