You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.7 KiB
116 lines
3.7 KiB
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
@Time : 2023/3/2 19:31
|
|
@Author :
|
|
@FileName:
|
|
@Software:
|
|
@Describe:
|
|
"""
|
|
#
|
|
# import redis
|
|
#
|
|
# redis_pool = redis.ConnectionPool(host='127.0.0.1', port=6379, password='', db=0)
|
|
# redis_conn = redis.Redis(connection_pool=redis_pool)
|
|
#
|
|
#
|
|
# name_dict = {
|
|
# 'name_4' : 'Zarten_4',
|
|
# 'name_5' : 'Zarten_5'
|
|
# }
|
|
# redis_conn.mset(name_dict)
|
|
|
|
import flask
|
|
import redis
|
|
import uuid
|
|
import json
|
|
from threading import Thread
|
|
import time
|
|
|
|
app = flask.Flask(__name__)
|
|
pool = redis.ConnectionPool(host='localhost', port=63179, max_connections=100, db=7, password="zhicheng123*")
|
|
redis_ = redis.Redis(connection_pool=pool, decode_responses=True)
|
|
|
|
db_key_query = 'query'
|
|
db_key_querying = 'querying'
|
|
|
|
@app.route("/search", methods=["POST"])
|
|
def handle_query():
|
|
try:
|
|
id_ = flask.request.json['id'] # 获取用户query中的文本 例如"I love you"
|
|
result = redis_.get(id_) # 获取该query的模型结果
|
|
if result is not None:
|
|
# redis_.delete(id_)
|
|
result_path = result.decode('UTF-8')
|
|
with open(result_path, encoding='utf8') as f1:
|
|
# 加载文件的对象
|
|
result_dict = json.load(f1)
|
|
resilt = result_dict["resilt"]
|
|
result_text = {'status': 9,
|
|
'resilt': resilt,
|
|
'reportId': "",
|
|
'downloadurl': "",
|
|
'similarity': ""
|
|
}
|
|
else:
|
|
querying_list = list(redis_.smembers("querying"))
|
|
querying_set = set()
|
|
for i in querying_list:
|
|
querying_set.add(i.decode())
|
|
|
|
querying_bool = False
|
|
if id_ in querying_set:
|
|
querying_bool = True
|
|
|
|
query_list_json = redis_.lrange(db_key_query, 0, -1)
|
|
query_set_ids = set()
|
|
for i in query_list_json:
|
|
data_dict = json.loads(i)
|
|
query_id = data_dict['id']
|
|
query_set_ids.add(query_id)
|
|
|
|
query_bool = False
|
|
if id_ in query_set_ids:
|
|
query_bool = True
|
|
|
|
if querying_bool == True and query_bool == True:
|
|
result_text = {'status': 1,
|
|
'resilt': "",
|
|
'reportId': "",
|
|
'downloadurl': "",
|
|
'similarity': ""
|
|
}
|
|
elif querying_bool == True and query_bool == False:
|
|
result_text = {'status': 1,
|
|
'resilt': "",
|
|
'reportId': "",
|
|
'downloadurl': "",
|
|
'similarity': ""
|
|
}
|
|
else:
|
|
result_text = {'status': 1,
|
|
'resilt': "",
|
|
'reportId': "",
|
|
'downloadurl': "",
|
|
'similarity': ""
|
|
}
|
|
load_request_path = './request_data_logs_203/{}.json'.format(id_)
|
|
with open(load_request_path, 'w', encoding='utf8') as f2:
|
|
# ensure_ascii=False才能输入中文,否则是Unicode字符
|
|
# indent=2 JSON数据的缩进,美观
|
|
json.dump(result_text, f2, ensure_ascii=False, indent=4)
|
|
|
|
result = {'code':0,
|
|
"msg": "请求成功",
|
|
"data": result_text}
|
|
except:
|
|
result = {'code':1,
|
|
"msg": "请求失败"
|
|
}
|
|
|
|
|
|
return flask.jsonify(result) # 返回结果
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug=False, host='0.0.0.0', port=16002)
|