|
|
@ -20,7 +20,7 @@ pool = redis.ConnectionPool(host='localhost', port=6379, max_connections=50, db= |
|
|
|
redis_ = redis.Redis(connection_pool=pool, decode_responses=True) |
|
|
|
|
|
|
|
db_key_query = 'query' |
|
|
|
db_key_result = 'result' |
|
|
|
db_key_querying = 'querying' |
|
|
|
batch_size = 32 |
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
@ -58,7 +58,6 @@ def get_dialogs_index(line: str): |
|
|
|
def chulichangju_1(text, snetence_id, chulipangban_return_list, short_num): |
|
|
|
fuhao = [",","?","!","…"] |
|
|
|
dialogs_text, dialogs_index, other_index = get_dialogs_index(text) |
|
|
|
print(len(text)) |
|
|
|
text_1 = text[:120] |
|
|
|
text_2 = text[120:] |
|
|
|
text_1_new = "" |
|
|
@ -263,7 +262,6 @@ def sentence(): |
|
|
|
texts_list = main(texts) |
|
|
|
if text_type == 'chapter': |
|
|
|
texts_list = main(texts) |
|
|
|
|
|
|
|
return_text = {"texts": texts_list, "probabilities": None, "status_code": True} |
|
|
|
else: |
|
|
|
return_text = {"texts":"输入格式应该为list", "probabilities": None, "status_code":False} |
|
|
@ -288,11 +286,12 @@ def classify(): # 调用模型,设置最大batch_size |
|
|
|
texts_list = main(texts) |
|
|
|
if text_type == 'chapter': |
|
|
|
texts_list = main(texts) |
|
|
|
|
|
|
|
return_text = {"texts": texts_list, "probabilities": None, "status_code": 200} |
|
|
|
else: |
|
|
|
return_text = {"texts": "输入格式应该为字典", "probabilities": None, "status_code": 401} |
|
|
|
redis_.set(query_id, json.dumps(return_text, ensure_ascii=False)) |
|
|
|
|
|
|
|
redis_.srem(db_key_querying, query_id) |
|
|
|
redis_.set(query_id, json.dumps(return_text, ensure_ascii=False), 28800) |
|
|
|
|
|
|
|
|
|
|
|
@app.route("/predict", methods=["POST"]) |
|
|
@ -300,11 +299,19 @@ def handle_query(): |
|
|
|
print(request.remote_addr) |
|
|
|
texts = request.json["texts"] |
|
|
|
text_type = request.json["text_type"] |
|
|
|
id_ = str(uuid.uuid1()) # 为query生成唯一标识 |
|
|
|
d = {'id': id_, 'text': texts, "text_type": text_type} # 绑定文本和query id |
|
|
|
redis_.rpush(db_key_query, json.dumps(d, ensure_ascii=False)) # 加入redis |
|
|
|
result_text = d |
|
|
|
return jsonify(result_text) # 返回结果 |
|
|
|
if texts is None: |
|
|
|
return_text = {"texts": "输入了空值", "probabilities": None, "status_code": False} |
|
|
|
return jsonify(return_text) |
|
|
|
if isinstance(texts, dict): |
|
|
|
id_ = str(uuid.uuid1()) # 为query生成唯一标识 |
|
|
|
d = {'id': id_, 'text': texts, "text_type": text_type} # 绑定文本和query id |
|
|
|
redis_.rpush(db_key_query, json.dumps(d, ensure_ascii=False)) # 加入redis |
|
|
|
redis_.sadd(db_key_querying, id_) |
|
|
|
return_text = d |
|
|
|
print("ok") |
|
|
|
else: |
|
|
|
return_text = {"texts": "输入格式应该为字典", "probabilities": None, "status_code": 401} |
|
|
|
return jsonify(return_text) # 返回结果 |
|
|
|
|
|
|
|
|
|
|
|
t = Thread(target=classify) |
|
|
|