aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/api_squad_online.py
diff options
context:
space:
mode:
authorzhaoyehua <zhaoyh6@asiainfo.com>2021-03-24 16:25:33 +0800
committerzhaoyehua <zhaoyh6@asiainfo.com>2021-03-24 16:27:48 +0800
commitdd67db0dede71551c772caa685d3c12a1a3e57d2 (patch)
tree3c36524a6f65e49002f8dd9767445300da343734 /scripts/api_squad_online.py
parent11b32441cc0235cc5ca4066085a3d8d0253e5789 (diff)
feat:Adjust the directory and increase the image production process
Issue-ID: USECASEUI-525 Change-Id: I7bcbf0b48778fd59946483b253f32dda217913c0 Signed-off-by: zhaoyehua <zhaoyh6@asiainfo.com>
Diffstat (limited to 'scripts/api_squad_online.py')
-rw-r--r--scripts/api_squad_online.py81
1 files changed, 0 insertions, 81 deletions
diff --git a/scripts/api_squad_online.py b/scripts/api_squad_online.py
deleted file mode 100644
index abe3d5f..0000000
--- a/scripts/api_squad_online.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/usr/bin/env python
-# coding: utf-8
-
-# auther = 'liuzhiyong'
-# date = 20201204
-
-
-from __future__ import absolute_import
-from __future__ import division
-from __future__ import print_function
-import json
-import sys
-from flask import Flask, abort, request, jsonify
-
-import os
-from global_setting import questions, tokenizer_ch, CUDA_VISIBLE_DEVICES
-from create_squad_features import get_squad_feature_result
-
-
-app = Flask(__name__)
-
-
-class AI2Flask:
-
- def __init__(self, port=5000, workers=4):
- self.app = app
- self.port = port
-
- @app.route('/api/online/predict', methods=['POST'])
- def text_analyse():
- if not request.json:
- abort(400)
-
- else:
- try:
- try:
- title = request.json['title']
- except:
- title = 'Not available'
- text_origin = request.json['text']
-
- if len(text_origin) > 800:
- text = text_origin[:800]
- else:
- text = text_origin
-
- result = {}
- for ques in questions:
- tmp = get_squad_feature_result(title=title, text=text, tokenizer=tokenizer_ch, question=[ques], url='http://localhost:8502/v1/models/predict:predict')
- result[ques] = dict(tmp)[ques]
-
- print('finished!!')
- return json.dumps(result)
-
- except KeyError as e:
- return jsonify({"Des": 'KeyError: {}'.format(str(e)), "Result": 'None', "Status": "Error"})
- except Exception as e:
- return jsonify({"Des": str(e), "Result": 'None', "Status": "Error"})
-
- @app.route('/api/online/load', methods=['POST'])
- def load_model():
- if not request.json:
- abort(400)
- else:
- try:
- path = request.json['path']
- flag = os.system('./load_model.sh ' + path + ' ' + CUDA_VISIBLE_DEVICES)
- if flag == 0:
- return jsonify({"Des": "Model loaded successfully !", "Status": "OK"})
- else:
- return jsonify({"Des": "Model loaded failed , check the logs !", "Status": "Error"})
- except Exception as e:
- return jsonify({"Des": str(e), "Status": "Error"})
-
- def start(self):
- self.app.run(host="0.0.0.0", port=self.port, threaded=True)
-
-
-if __name__ == '__main__':
- port = sys.argv[1]
- AI2Flask(port=port).start()