Spaces:
Sleeping
Sleeping
Liu Yiwen
commited on
Commit
·
0d31272
1
Parent(s):
405fabd
更新打分逻辑
Browse files- .gitignore +1 -0
- __pycache__/comm_utils.cpython-311.pyc +0 -0
- app.py +4 -2
- comm_utils.py +20 -7
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
scores/
|
__pycache__/comm_utils.cpython-311.pyc
CHANGED
Binary files a/__pycache__/comm_utils.cpython-311.pyc and b/__pycache__/comm_utils.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -280,6 +280,7 @@ with gr.Blocks() as demo:
|
|
280 |
with gr.Row():
|
281 |
with gr.Column(scale=2):
|
282 |
user_submit_button = gr.Button("submit", interactive=True)
|
|
|
283 |
with gr.Column(scale=1):
|
284 |
submit_info_box = gr.Textbox(label="submit_info", interactive=False)
|
285 |
with gr.Row():
|
@@ -381,7 +382,7 @@ with gr.Blocks() as demo:
|
|
381 |
}
|
382 |
except AppError as err:
|
383 |
return show_error(str(err))
|
384 |
-
|
385 |
all_outputs = [cp_config, cp_split,
|
386 |
cp_page, cp_goto_page, cp_goto_next_page,
|
387 |
cp_result, cp_info, cp_error,
|
@@ -392,12 +393,13 @@ with gr.Blocks() as demo:
|
|
392 |
user_input_box, user_output_box,
|
393 |
submit_info_box,
|
394 |
question_info_textbox]
|
|
|
395 |
cp_go.click(show_dataset, inputs=[cp_dataset], outputs=all_outputs)
|
396 |
cp_config.change(show_dataset_at_config, inputs=[cp_dataset, cp_config], outputs=all_outputs)
|
397 |
cp_split.change(show_dataset_at_config_and_split, inputs=[cp_dataset, cp_config, cp_split], outputs=all_outputs)
|
398 |
cp_goto_page.click(show_dataset_at_config_and_split_and_page, inputs=[cp_dataset, cp_config, cp_split, cp_page], outputs=all_outputs)
|
399 |
cp_goto_next_page.click(show_dataset_at_config_and_split_and_next_page, inputs=[cp_dataset, cp_config, cp_split, cp_page], outputs=all_outputs)
|
400 |
-
user_submit_button.click(save_score, inputs=[
|
401 |
# select_buttom.click(show_dataset_at_config_and_split_and_page, inputs=[cp_dataset, cp_config, cp_split, select_sample_box, select_subtarget_box], outputs=all_outputs)
|
402 |
|
403 |
|
|
|
280 |
with gr.Row():
|
281 |
with gr.Column(scale=2):
|
282 |
user_submit_button = gr.Button("submit", interactive=True)
|
283 |
+
user_name_box = gr.Textbox(label="user_name", placeholder="Enter your name first", interactive=True)
|
284 |
with gr.Column(scale=1):
|
285 |
submit_info_box = gr.Textbox(label="submit_info", interactive=False)
|
286 |
with gr.Row():
|
|
|
382 |
}
|
383 |
except AppError as err:
|
384 |
return show_error(str(err))
|
385 |
+
|
386 |
all_outputs = [cp_config, cp_split,
|
387 |
cp_page, cp_goto_page, cp_goto_next_page,
|
388 |
cp_result, cp_info, cp_error,
|
|
|
393 |
user_input_box, user_output_box,
|
394 |
submit_info_box,
|
395 |
question_info_textbox]
|
396 |
+
|
397 |
cp_go.click(show_dataset, inputs=[cp_dataset], outputs=all_outputs)
|
398 |
cp_config.change(show_dataset_at_config, inputs=[cp_dataset, cp_config], outputs=all_outputs)
|
399 |
cp_split.change(show_dataset_at_config_and_split, inputs=[cp_dataset, cp_config, cp_split], outputs=all_outputs)
|
400 |
cp_goto_page.click(show_dataset_at_config_and_split_and_page, inputs=[cp_dataset, cp_config, cp_split, cp_page], outputs=all_outputs)
|
401 |
cp_goto_next_page.click(show_dataset_at_config_and_split_and_next_page, inputs=[cp_dataset, cp_config, cp_split, cp_page], outputs=all_outputs)
|
402 |
+
user_submit_button.click(save_score, inputs=[user_name_box, cp_config, qusetion_id_box, score_slider], outputs=[submit_info_box])
|
403 |
# select_buttom.click(show_dataset_at_config_and_split_and_page, inputs=[cp_dataset, cp_config, cp_split, select_sample_box, select_subtarget_box], outputs=all_outputs)
|
404 |
|
405 |
|
comm_utils.py
CHANGED
@@ -9,25 +9,38 @@ def save_to_file(user_input):
|
|
9 |
with open("user_input.txt", "w") as file:
|
10 |
file.write(user_input)
|
11 |
|
12 |
-
def save_score(user_id, question_id, score):
|
|
|
|
|
|
|
13 |
score_data = {
|
14 |
-
"
|
15 |
"question_id": question_id,
|
16 |
"score": score
|
17 |
}
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
data = json.load(file)
|
22 |
else:
|
23 |
data = []
|
24 |
|
|
|
25 |
data.append(score_data)
|
26 |
|
27 |
-
|
28 |
-
|
|
|
29 |
|
30 |
-
|
31 |
|
32 |
def send_msg_to_server(input_text):
|
33 |
try:
|
|
|
9 |
with open("user_input.txt", "w") as file:
|
10 |
file.write(user_input)
|
11 |
|
12 |
+
def save_score(user_id, subset_name, question_id, score):
|
13 |
+
if user_id.strip() == '':
|
14 |
+
raise ValueError("User ID cannot be empty.")
|
15 |
+
|
16 |
score_data = {
|
17 |
+
"subset_name": subset_name,
|
18 |
"question_id": question_id,
|
19 |
"score": score
|
20 |
}
|
21 |
|
22 |
+
# 创建用户目录路径
|
23 |
+
user_dir = os.path.join("scores", user_id)
|
24 |
+
os.makedirs(user_dir, exist_ok=True)
|
25 |
+
|
26 |
+
# JSON 文件路径
|
27 |
+
json_file_path = os.path.join(user_dir, "score.json")
|
28 |
+
|
29 |
+
# 读取现有数据或初始化为空列表
|
30 |
+
if os.path.exists(json_file_path):
|
31 |
+
with open(json_file_path, "r", encoding="utf-8") as file:
|
32 |
data = json.load(file)
|
33 |
else:
|
34 |
data = []
|
35 |
|
36 |
+
# 添加新的分数数据
|
37 |
data.append(score_data)
|
38 |
|
39 |
+
# 保存数据到 JSON 文件
|
40 |
+
with open(json_file_path, "w", encoding="utf-8") as file:
|
41 |
+
json.dump(data, file, ensure_ascii=False, indent=4)
|
42 |
|
43 |
+
return f'Time {time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} UCT-8, score submitted successfully. User ID: {user_id}, Subset: {subset_name}, Question ID: {question_id}, Score: {score}'
|
44 |
|
45 |
def send_msg_to_server(input_text):
|
46 |
try:
|