Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import json
|
|
| 4 |
import pandas as pd
|
| 5 |
import random
|
| 6 |
import shutil
|
|
|
|
| 7 |
from datasets import load_dataset
|
| 8 |
from huggingface_hub import HfApi
|
| 9 |
|
|
@@ -106,13 +107,19 @@ def load_or_initialize_count_json(audio_paths):
|
|
| 106 |
|
| 107 |
return count_data
|
| 108 |
|
|
|
|
|
|
|
|
|
|
| 109 |
def sample_audio_paths(audio_paths, count_data, k=5, max_count=3):
|
| 110 |
eligible_paths = [p for p in audio_paths if count_data.get(os.path.basename(p), 0) < max_count]
|
| 111 |
|
| 112 |
if len(eligible_paths) < k:
|
| 113 |
raise ValueError(f"⚠️ 可用音频数量不足(只剩 {len(eligible_paths)} 条 count<{max_count} 的音频),无法抽取 {k} 条")
|
| 114 |
|
|
|
|
|
|
|
| 115 |
selected = random.sample(eligible_paths, k)
|
|
|
|
| 116 |
for path in selected:
|
| 117 |
filename = os.path.basename(path)
|
| 118 |
count_data[filename] += 1
|
|
@@ -135,12 +142,6 @@ QUESTION_SET = [
|
|
| 135 |
for path in selected_audio_paths
|
| 136 |
]
|
| 137 |
|
| 138 |
-
"""QUESTION_SET = [
|
| 139 |
-
{"audio": "data/Ses02F_impro01.wav", "desc": "这是第一个测试文件的描述",},
|
| 140 |
-
{"audio": "data/Ses02F_impro02.wav", "desc": "这是第二个测试文件的描述",},
|
| 141 |
-
{"audio": "data/Ses02F_impro03.wav", "desc": "这是第三个测试文件的描述",},
|
| 142 |
-
]"""
|
| 143 |
-
|
| 144 |
MAX_SUB_DIMS = max(len(d['sub_dims']) for d in DIMENSIONS_DATA)
|
| 145 |
|
| 146 |
# ==============================================================================
|
|
@@ -174,7 +175,8 @@ def show_sample_page_and_init(age, gender, education, education_other, user_data
|
|
| 174 |
def update_sample_view(dimension_title):
|
| 175 |
dim_data = next((d for d in DIMENSIONS_DATA if d["title"] == dimension_title), None)
|
| 176 |
if dim_data:
|
| 177 |
-
audio_up = gr.update(value=dim_data["audio"])
|
|
|
|
| 178 |
interactive_view_up = gr.update(visible=True)
|
| 179 |
reference_view_up = gr.update(visible=False)
|
| 180 |
reference_btn_up = gr.update(value="参考")
|
|
@@ -236,7 +238,8 @@ def init_test_question(user_data, q_idx):
|
|
| 236 |
q_idx, d_idx, {},
|
| 237 |
gr.update(value=progress_q),
|
| 238 |
dim_title_update,
|
| 239 |
-
gr.update(value=question['audio']),
|
|
|
|
| 240 |
prev_btn_update,
|
| 241 |
next_btn_update,
|
| 242 |
gr.update(value=None), # BUG FIX: Changed from "" to None to correctly clear the radio button
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
import random
|
| 6 |
import shutil
|
| 7 |
+
import time
|
| 8 |
from datasets import load_dataset
|
| 9 |
from huggingface_hub import HfApi
|
| 10 |
|
|
|
|
| 107 |
|
| 108 |
return count_data
|
| 109 |
|
| 110 |
+
def append_cache_buster(audio_path):
|
| 111 |
+
return f"{audio_path}?t={int(time.time() * 1000)}"
|
| 112 |
+
|
| 113 |
def sample_audio_paths(audio_paths, count_data, k=5, max_count=3):
|
| 114 |
eligible_paths = [p for p in audio_paths if count_data.get(os.path.basename(p), 0) < max_count]
|
| 115 |
|
| 116 |
if len(eligible_paths) < k:
|
| 117 |
raise ValueError(f"⚠️ 可用音频数量不足(只剩 {len(eligible_paths)} 条 count<{max_count} 的音频),无法抽取 {k} 条")
|
| 118 |
|
| 119 |
+
# selected = random.sample(eligible_paths, k)
|
| 120 |
+
random.shuffle(eligible_paths)
|
| 121 |
selected = random.sample(eligible_paths, k)
|
| 122 |
+
|
| 123 |
for path in selected:
|
| 124 |
filename = os.path.basename(path)
|
| 125 |
count_data[filename] += 1
|
|
|
|
| 142 |
for path in selected_audio_paths
|
| 143 |
]
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
MAX_SUB_DIMS = max(len(d['sub_dims']) for d in DIMENSIONS_DATA)
|
| 146 |
|
| 147 |
# ==============================================================================
|
|
|
|
| 175 |
def update_sample_view(dimension_title):
|
| 176 |
dim_data = next((d for d in DIMENSIONS_DATA if d["title"] == dimension_title), None)
|
| 177 |
if dim_data:
|
| 178 |
+
# audio_up = gr.update(value=dim_data["audio"])
|
| 179 |
+
audio_up = gr.update(value=append_cache_buster(dim_data["audio"]))
|
| 180 |
interactive_view_up = gr.update(visible=True)
|
| 181 |
reference_view_up = gr.update(visible=False)
|
| 182 |
reference_btn_up = gr.update(value="参考")
|
|
|
|
| 238 |
q_idx, d_idx, {},
|
| 239 |
gr.update(value=progress_q),
|
| 240 |
dim_title_update,
|
| 241 |
+
# gr.update(value=question['audio']),
|
| 242 |
+
gr.update(value=append_cache_buster(question['audio'])),
|
| 243 |
prev_btn_update,
|
| 244 |
next_btn_update,
|
| 245 |
gr.update(value=None), # BUG FIX: Changed from "" to None to correctly clear the radio button
|