接收请求函数:
@app.route('/predict', methods=['POST'])
def get_result():
q_data = request.get_data() # 接收json数据
q_dict = json.loads(q_data) # json数据解析
name = q_dict["name"]
degree = q_dict['degree']
judge = {}
result = []
with graph.as_default():
set_session(sess)
for item in name:
sim = most_similar(item)[0]
print(sim)
if sim[2] >= degree:
sim_item = {
'oldName': item,
'code': sim[0],
'name': sim[1],
'match': sim[2]
}
else:
sim_item = {
'oldName': item,
'code': "",
'name': "",
'match': 0
}
result.append(sim_item)
judge['result'] = result
return json.dumps(judge, ensure_ascii=False)