Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -161,7 +161,7 @@ MAX_SUB_DIMS = max(len(d['sub_dims']) for d in DIMENSIONS_DATA)
|
|
| 161 |
"""def start_challenge():
|
| 162 |
return gr.update(visible=False), gr.update(visible=True)"""
|
| 163 |
|
| 164 |
-
def start_challenge(user_data_state):
|
| 165 |
global QUESTION_SET, updated_count_data
|
| 166 |
|
| 167 |
# 每次点击“开始挑战”时重新抽题
|
|
@@ -175,8 +175,32 @@ def start_challenge(user_data_state):
|
|
| 175 |
|
| 176 |
# 重置 user_data 中的状态(也可以留空)
|
| 177 |
user_data_state.clear()
|
| 178 |
-
return gr.update(visible=False), gr.update(visible=True), user_data_state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
def toggle_education_other(choice):
|
| 182 |
is_other = (choice == "其他(请注明)")
|
|
|
|
| 161 |
"""def start_challenge():
|
| 162 |
return gr.update(visible=False), gr.update(visible=True)"""
|
| 163 |
|
| 164 |
+
"""def start_challenge(user_data_state):
|
| 165 |
global QUESTION_SET, updated_count_data
|
| 166 |
|
| 167 |
# 每次点击“开始挑战”时重新抽题
|
|
|
|
| 175 |
|
| 176 |
# 重置 user_data 中的状态(也可以留空)
|
| 177 |
user_data_state.clear()
|
| 178 |
+
return gr.update(visible=False), gr.update(visible=True), user_data_state"""
|
| 179 |
+
|
| 180 |
+
def start_challenge(user_data_state):
|
| 181 |
+
global QUESTION_SET
|
| 182 |
+
|
| 183 |
+
# Step 1: 读取最新 count.json
|
| 184 |
+
count_data = load_or_initialize_count_json(all_data_audio_paths)
|
| 185 |
+
|
| 186 |
+
# Step 2: 从 eligible 音频中抽题
|
| 187 |
+
selected_audio_paths, _ = sample_audio_paths(
|
| 188 |
+
audio_paths=all_data_audio_paths,
|
| 189 |
+
count_data=count_data.copy(), # 不修改原始数据
|
| 190 |
+
k=5,
|
| 191 |
+
max_count=1
|
| 192 |
+
)
|
| 193 |
|
| 194 |
+
# Step 3: 保存抽到的音频文件名在用户状态中
|
| 195 |
+
user_data_state["selected_filenames"] = [os.path.basename(p) for p in selected_audio_paths]
|
| 196 |
+
|
| 197 |
+
# Step 4: 设置题目列表
|
| 198 |
+
QUESTION_SET = [
|
| 199 |
+
{"audio": path, "desc": f"这是音频文件 {os.path.basename(path)} 的描述"}
|
| 200 |
+
for path in selected_audio_paths
|
| 201 |
+
]
|
| 202 |
+
|
| 203 |
+
return gr.update(visible=False), gr.update(visible=True), user_data_state
|
| 204 |
|
| 205 |
def toggle_education_other(choice):
|
| 206 |
is_other = (choice == "其他(请注明)")
|