-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
23 lines (22 loc) · 732 Bytes
/
app.py
File metadata and controls
23 lines (22 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import time
from flask import Flask, request
import json
from untils import supertranslate
app = Flask(__name__)
trans=supertranslate(model_dir="models/damo/nlp_csanmt_translation_en2zh_base")
@app.route("/predict", methods=["POST"])
def predict():
raw_data = request.data
json_data = json.loads(raw_data.decode())
print(json_data,flush=True)
res=[]
textlists=json_data['textlists']
if type(textlists)==list:
t1 = time.time()
trans_result = trans.translate(textlists)
print(time.time() - t1)
print(trans_result,flush=True)
res.append(trans_result)
return json.dumps({'prediction': res})
if __name__ == '__main__':
app.run(threaded=False,port=6006,debug=False)