Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -263,7 +263,7 @@ def update_sample_view(dimension_title):
|
|
| 263 |
if i < len(dim_data['sub_dims']):
|
| 264 |
label = dim_data['sub_dims'][i]
|
| 265 |
score = scores[i] if i < len(scores) else 0
|
| 266 |
-
sample_slider_ups.append(gr.update(visible=True, label=label, value=
|
| 267 |
ref_slider_ups.append(gr.update(visible=True, label=label, value=score))
|
| 268 |
else:
|
| 269 |
sample_slider_ups.append(gr.update(visible=False, value=0))
|
|
@@ -363,7 +363,7 @@ def navigate_dimensions(direction, q_idx, d_idx, selections, *slider_values):
|
|
| 363 |
) + tuple(slider_updates)
|
| 364 |
|
| 365 |
def submit_question_and_advance(q_idx, d_idx, selections, final_choice, all_results, user_data):
|
| 366 |
-
selections["final_choice"] = final_choice
|
| 367 |
|
| 368 |
"""final_question_result = {
|
| 369 |
"question_id": q_idx, "audio_file": QUESTION_SET[q_idx]['audio'],
|
|
@@ -371,10 +371,26 @@ def submit_question_and_advance(q_idx, d_idx, selections, final_choice, all_resu
|
|
| 371 |
}
|
| 372 |
"""
|
| 373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
final_question_result = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
"question_id": q_idx, "audio_file": user_data["question_set"][q_idx]['audio'],
|
| 376 |
"selections": selections
|
| 377 |
-
}
|
| 378 |
|
| 379 |
all_results.append(final_question_result)
|
| 380 |
|
|
@@ -465,15 +481,6 @@ def toggle_reference_view(current):
|
|
| 465 |
else:
|
| 466 |
return gr.update(visible=True), gr.update(visible=False), gr.update(value="参考")
|
| 467 |
|
| 468 |
-
def toggle_slider(null_checked, slider_value):
|
| 469 |
-
if null_checked:
|
| 470 |
-
return gr.update(interactivate=False), gr.update(value=0) # Disable slider
|
| 471 |
-
else:
|
| 472 |
-
return gr.update(interactive=True), gr.update(value=slider_value or 3) # Restore previous of default slider
|
| 473 |
-
|
| 474 |
-
def get_total_completed(count_data):
|
| 475 |
-
return sum(v for k, v in count_data.items() if isinstance(v, int) and v < 999)
|
| 476 |
-
|
| 477 |
def back_to_welcome():
|
| 478 |
return (
|
| 479 |
gr.update(visible=True), # welcome_page
|
|
@@ -536,23 +543,24 @@ with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {max-width: 960px
|
|
| 536 |
sample_audio = gr.Audio(label="样例音频", value=DIMENSIONS_DATA[0]["audio"])
|
| 537 |
with gr.Column(scale=2):
|
| 538 |
with gr.Column(visible=True) as interactive_view:
|
| 539 |
-
gr.Markdown("#### 请为以下特征打分 (
|
| 540 |
-
sample_sliders = [gr.Slider(minimum=
|
| 541 |
with gr.Column(visible=False) as reference_view:
|
| 542 |
gr.Markdown("### 参考答案解析 (1-5分。1对应机器,5对应人类)")
|
| 543 |
-
reference_sliders = [gr.Slider(minimum=
|
| 544 |
with gr.Row():
|
| 545 |
reference_btn = gr.Button("参考")
|
| 546 |
go_to_pretest_btn = gr.Button("我明白了,开始测试", variant="primary")
|
| 547 |
|
| 548 |
with pretest_page:
|
| 549 |
gr.Markdown("## 测试说明\n"
|
| 550 |
-
"- 对于每一道题,你都需要对全部 **5
|
| 551 |
"- 在每个维度下,请为出现的每个特征 **从1到5打分。\n"
|
| 552 |
"- **评分解释如下:**\n"
|
|
|
|
| 553 |
" - **1 分:极度符合机器特征**;\n"
|
| 554 |
" - **2 分:较为符合机器特征**;\n"
|
| 555 |
-
" - **3
|
| 556 |
" - **4 分:较为符合人类特征**;\n"
|
| 557 |
" - **5 分:极度符合人类特征**。\n"
|
| 558 |
"- 完成所有维度后,请根据整体印象对回应方的身份做出做出“人类”或“机器人”的 **最终判断**。\n"
|
|
@@ -564,8 +572,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {max-width: 960px
|
|
| 564 |
question_progress_text = gr.Markdown()
|
| 565 |
test_dimension_title = gr.Markdown()
|
| 566 |
test_audio = gr.Audio(label="测试音频")
|
| 567 |
-
gr.Markdown("--- \n ### 请为以下特征打分 (
|
| 568 |
-
test_sliders = [gr.Slider(minimum=
|
| 569 |
with gr.Row():
|
| 570 |
prev_dim_btn = gr.Button("上一维度")
|
| 571 |
next_dim_btn = gr.Button("下一维度", variant="primary")
|
|
@@ -688,8 +696,5 @@ if __name__ == "__main__":
|
|
| 688 |
for audio_file in set(all_files):
|
| 689 |
if not os.path.exists(audio_file):
|
| 690 |
print(f"⚠️ Warning: Audio file not found: {audio_file}")
|
| 691 |
-
|
| 692 |
-
count_data = load_or_initialize_count_json(all_data_audio_paths)
|
| 693 |
-
print(f"当前已完成的音频数量:{get_total_completed(count_data)}")
|
| 694 |
|
| 695 |
demo.launch(debug=True)
|
|
|
|
| 263 |
if i < len(dim_data['sub_dims']):
|
| 264 |
label = dim_data['sub_dims'][i]
|
| 265 |
score = scores[i] if i < len(scores) else 0
|
| 266 |
+
sample_slider_ups.append(gr.update(visible=True, label=label, value=0))
|
| 267 |
ref_slider_ups.append(gr.update(visible=True, label=label, value=score))
|
| 268 |
else:
|
| 269 |
sample_slider_ups.append(gr.update(visible=False, value=0))
|
|
|
|
| 363 |
) + tuple(slider_updates)
|
| 364 |
|
| 365 |
def submit_question_and_advance(q_idx, d_idx, selections, final_choice, all_results, user_data):
|
| 366 |
+
# selections["final_choice"] = final_choice
|
| 367 |
|
| 368 |
"""final_question_result = {
|
| 369 |
"question_id": q_idx, "audio_file": QUESTION_SET[q_idx]['audio'],
|
|
|
|
| 371 |
}
|
| 372 |
"""
|
| 373 |
|
| 374 |
+
cleaned_selections = {}
|
| 375 |
+
for dim_title, sub_scores in selections.items():
|
| 376 |
+
if dim_title == "final_choice":
|
| 377 |
+
cleaned_selections["final_choice"] = final_choice
|
| 378 |
+
continue
|
| 379 |
+
cleaned_sub_scores = {}
|
| 380 |
+
for sub_dim, score in sub_scores.items():
|
| 381 |
+
cleaned_sub_scores[sub_dim] = None if score == 0 else score
|
| 382 |
+
cleaned_selections[dim_title] = cleaned_sub_scores
|
| 383 |
+
|
| 384 |
final_question_result = {
|
| 385 |
+
"question_id": q_idx,
|
| 386 |
+
"audio_file": user_data["question_set"][q_idx]['audio'],
|
| 387 |
+
"selections": cleaned_selections
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
"""final_question_result = {
|
| 391 |
"question_id": q_idx, "audio_file": user_data["question_set"][q_idx]['audio'],
|
| 392 |
"selections": selections
|
| 393 |
+
}"""
|
| 394 |
|
| 395 |
all_results.append(final_question_result)
|
| 396 |
|
|
|
|
| 481 |
else:
|
| 482 |
return gr.update(visible=True), gr.update(visible=False), gr.update(value="参考")
|
| 483 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
def back_to_welcome():
|
| 485 |
return (
|
| 486 |
gr.update(visible=True), # welcome_page
|
|
|
|
| 543 |
sample_audio = gr.Audio(label="样例音频", value=DIMENSIONS_DATA[0]["audio"])
|
| 544 |
with gr.Column(scale=2):
|
| 545 |
with gr.Column(visible=True) as interactive_view:
|
| 546 |
+
gr.Markdown("#### 请为以下特征打分 (0-5分。0-无特征;1-机器;3-特征无偏向;5-人类)")
|
| 547 |
+
sample_sliders = [gr.Slider(minimum=0, maximum=5, step=1, label=f"Sub-dim {i+1}", visible=False, interactive=True) for i in range(MAX_SUB_DIMS)]
|
| 548 |
with gr.Column(visible=False) as reference_view:
|
| 549 |
gr.Markdown("### 参考答案解析 (1-5分。1对应机器,5对应人类)")
|
| 550 |
+
reference_sliders = [gr.Slider(minimum=0, maximum=5, step=1, label=f"Sub-dim {i+1}", visible=False, interactive=False) for i in range(MAX_SUB_DIMS)]
|
| 551 |
with gr.Row():
|
| 552 |
reference_btn = gr.Button("参考")
|
| 553 |
go_to_pretest_btn = gr.Button("我明白了,开始测试", variant="primary")
|
| 554 |
|
| 555 |
with pretest_page:
|
| 556 |
gr.Markdown("## 测试说明\n"
|
| 557 |
+
"- 对于每一道题,你都需要对全部 **5 个维度 进行评估。\n"
|
| 558 |
"- 在每个维度下,请为出现的每个特征 **从1到5打分。\n"
|
| 559 |
"- **评分解释如下:**\n"
|
| 560 |
+
" - **0 分:特征未体现;\n"
|
| 561 |
" - **1 分:极度符合机器特征**;\n"
|
| 562 |
" - **2 分:较为符合机器特征**;\n"
|
| 563 |
+
" - **3 分:无明显人类或机器倾向**;\n"
|
| 564 |
" - **4 分:较为符合人类特征**;\n"
|
| 565 |
" - **5 分:极度符合人类特征**。\n"
|
| 566 |
"- 完成所有维度后,请根据整体印象对回应方的身份做出做出“人类”或“机器人”的 **最终判断**。\n"
|
|
|
|
| 572 |
question_progress_text = gr.Markdown()
|
| 573 |
test_dimension_title = gr.Markdown()
|
| 574 |
test_audio = gr.Audio(label="测试音频")
|
| 575 |
+
gr.Markdown("--- \n ### 请为以下特征打分 (0-5分。0-无特征;1-机器;3-特征无偏向;5-人类)")
|
| 576 |
+
test_sliders = [gr.Slider(minimum=0, maximum=5, step=1, label=f"Sub-dim {i+1}", visible=False, interactive=True) for i in range(MAX_SUB_DIMS)]
|
| 577 |
with gr.Row():
|
| 578 |
prev_dim_btn = gr.Button("上一维度")
|
| 579 |
next_dim_btn = gr.Button("下一维度", variant="primary")
|
|
|
|
| 696 |
for audio_file in set(all_files):
|
| 697 |
if not os.path.exists(audio_file):
|
| 698 |
print(f"⚠️ Warning: Audio file not found: {audio_file}")
|
|
|
|
|
|
|
|
|
|
| 699 |
|
| 700 |
demo.launch(debug=True)
|