@app.route('/Subjective_scoring', methods=['GET', 'POST'])
def subjective_scoring():
# args = request.form
# print(request.json)
import uuid
parent_task_uuid="5de8b01e7e0411eea20ba4dcbe1b9a90"
remote_ip = request.remote_addr
with DBOperate() as fp:
data = fp.select("select task_uuid from evaluate_score_info where parent_task_uuid='%s' and remote_ip='%s';" % (parent_task_uuid,remote_ip))
if not data:
with DBOperate() as fp:
res_data = fp.select("select task_cnt,total_json from evaluate_task_info where task_uuid='%s';" % parent_task_uuid)
if res_data:
task_cnt_total,total_json = res_data[0]
task_uuid = uuid.uuid1().hex
task_start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
timestamp = str(int(time.time()))
task_timestamp = timestamp + "_" + request.remote_addr
score_total_json_path = os.path.join(static_path,"evaluate",parent_task_uuid,"task_info",task_timestamp+".json")
with DBOperate() as fp:
fp.insert(
"insert into evaluate_score_info (task_uuid,status,cur_cnt,task_cnt,parent_task_uuid,task_start_time,task_end_time,tiemstamp_ip,score_total_json,remote_ip) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" % (
task_uuid,"PROCESSING",'0',task_cnt_total,parent_task_uuid,task_start_time,task_start_time, task_timestamp,score_total_json_path,remote_ip))
data_res = fp.select("select task_cnt,total_json from evaluate_task_info where task_uuid='%s';" % parent_task_uuid)
if data_res:
task_cnt, json_file = data_res[0]
res = {}
with open(json_file, 'r', encoding="utf-8") as f:
res_tmp = json.load(f)
for prompt,value in res_tmp.items():
if str(value.get("index")) == "0":
res.update({prompt:value})
break
return render_template("Subjective_scoring.html", data=res, count=int(task_cnt))
#return render_template("Subjective_scoring1.html", data=res,count=int(task_cnt))
else:
with DBOperate() as fp:
res_data = fp.select(
"select a.cur_cnt,a.task_cnt,a.score_total_json,b.total_json from evaluate_score_info a,evaluate_task_info b where a.parent_task_uuid='%s' and a.remote_ip='%s' and a.parent_task_uuid=b.task_uuid;" % (parent_task_uuid,remote_ip))
if res_data:
cur_cnt, task_cnt, score_total_json,total_json = res_data[0]
with open(total_json, 'r', encoding="utf-8") as f:
res_tmp = json.load(f)
target_cnt = int(cur_cnt) + 1
res = {}
for prompt,value in res_tmp.items():
if str(value.get("index")) == str(target_cnt):
res.update({prompt:value})
break
# data={
# '2个柔顺的玩具车': {
# 'index': 0,
# 'test1108_1': {
# '5.png': {
# 'image_name': '1',
# 'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_1/img/5.png',
# 'split_word': {
# '柔顺的': 'other',
# '玩具车': 'object',
# '2个': 'other',
# '瘦瘦的': 'other'
# }
# }
# },
# 'test1108_2': {
# '1.png': {
# 'image_name': '1',
# 'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_2/img/1.png',
# 'split_word': {
# '柔顺的': 'other',
# '玩具车': 'object',
# '2个': 'other',
# '瘦瘦的': 'other'
# }
# }
# },
# 'test1108_3': {
# '0.png': {
# 'image_name': '1',
# 'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_3/img/0.png',
# 'split_word': {
# '柔顺的': 'other',
# '玩具车': 'object',
# '2个': 'other',
# '瘦瘦的': 'other'
# }
# }
# }
# },
# '2个可爱的花瓣': {
# 'index': 1,
# 'test1108_1': {
# '7.png': {
# 'image_name': '2',
# 'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_1/img/7.png',
# 'split_word': {
# '2个': 'other',
# '花瓣': 'object',
# '可爱的': 'other'
# }
# }
# },
# 'test1108_2': {
# '3.png': {
# 'image_name': '2',
# 'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_2/img/3.png',
# 'split_word': {
# '2个': 'other',
# '花瓣': 'object',
# '可爱的': 'other'
# }
# }
# },
# 'test1108_3': {
# '1.png': {
# 'image_name': '2',
# 'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_3/img/1.png',
# 'split_word': {
# '2个': 'other',
# '花瓣': 'object',
# '可爱的': 'other'
# }
# }
# }
# },
# '黑色香蕉': {
# 'index': 2,
# 'test1108_1': {
# '8.png': {
# 'image_name': '3',
# 'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_1/img/8.png',
# 'split_word': {
# '黑色': 'other',
# '香蕉': 'object'
# }
# }
# },
# 'test1108_2': {
# '4.png': {
# 'image_name': '3',
# 'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_2/img/4.png',
# 'split_word': {
# '黑色': 'other',
# '香蕉': 'object'
# }
# }
# },
# 'test1108_3': {
# '2.png': {
# 'image_name': '3',
# 'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_3/img/2.png',
# 'split_word': {
# '黑色': 'other',
# '香蕉': 'object'
# }
# }
# }
# }
# }
return render_template("Subjective_scoring1.html", data=res, count=int(task_cnt),task_uuid=task_uuid)
@app.route('/Subjective_scoring_data', methods=['GET', 'POST'])
def Subjective_scoring_data():
print(request.json)
import uuid
parent_task_uuid="5de8b01e7e0411eea20ba4dcbe1b9a90"
remote_ip = request.remote_addr
with DBOperate() as fp:
data = fp.select("select task_uuid from evaluate_score_info where parent_task_uuid='%s' and remote_ip='%s';" % (parent_task_uuid,remote_ip))
if not data:
with DBOperate() as fp:
res_data = fp.select("select task_cnt,total_json from evaluate_task_info where task_uuid='%s';" % parent_task_uuid)
if res_data:
task_cnt_total,total_json = res_data[0]
task_uuid = uuid.uuid1().hex
task_start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
timestamp = str(int(time.time()))
task_timestamp = timestamp + "_" + request.remote_addr
score_total_json_path = os.path.join(static_path,"evaluate",parent_task_uuid,"task_info",task_timestamp+".json")
with DBOperate() as fp:
fp.insert(
"insert into evaluate_score_info (task_uuid,status,cur_cnt,task_cnt,parent_task_uuid,task_start_time,task_end_time,tiemstamp_ip,score_total_json,remote_ip) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" % (
task_uuid,"PROCESSING",'0',task_cnt_total,parent_task_uuid,task_start_time,task_start_time, task_timestamp,score_total_json_path,remote_ip))
data_res = fp.select("select task_cnt,total_json from evaluate_task_info where task_uuid='%s';" % parent_task_uuid)
if data_res:
task_cnt, json_file = data_res[0]
res = {}
with open(json_file, 'r', encoding="utf-8") as f:
res_tmp = json.load(f)
for prompt,value in res_tmp.items():
if str(value.get("index")) == "0":
res.update({prompt:value})
break
return jsonify({"code": 0, "msg": "", "data": res})
#return render_template("Subjective_scoring1.html", data=res,count=int(task_cnt))
else:
with DBOperate() as fp:
res_data = fp.select(
"select a.cur_cnt,a.task_cnt,a.score_total_json,b.total_json from evaluate_score_info a,evaluate_task_info b where a.parent_task_uuid='%s' and a.remote_ip='%s' and a.parent_task_uuid=b.task_uuid;" % (parent_task_uuid,remote_ip))
if res_data:
cur_cnt, task_cnt, score_total_json,total_json = res_data[0]
with open(total_json, 'r', encoding="utf-8") as f:
res_tmp = json.load(f)
target_cnt = int(cur_cnt) + 1
res = {}
for prompt,value in res_tmp.items():
if str(value.get("index")) == str(target_cnt):
res.update({prompt:value})
break
return jsonify({"code": 0, "msg": "", "data": res})
【疑惑】打分页
于 2023-11-09 12:07:18 首次发布