intersteller2887 commited on
Commit
5a2951e
·
verified ·
1 Parent(s): 01f55b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -38
app.py CHANGED
@@ -10,25 +10,18 @@ dataset = load_dataset("intersteller2887/Turing-test-dataset", split="train")
10
 
11
  print(dataset[0])
12
 
13
- """all_data_audio_paths = [
14
  item["audio"]["path"]
15
  for item in dataset
16
  if item["audio"] and "path" in item["audio"]
17
- ]"""
18
-
19
- all_data_audio_data = [
20
- (item["audio"]["array"], item["audio"]["sampling_rate"])
21
- for item in dataset
22
- if item["audio"] and "array" in item["audio"]
23
  ]
24
 
25
  """valid_audio_paths = [path for path in all_data_audio_paths if os.path.exists(path)]
26
  print(f"Total valid audio files: {len(valid_audio_paths)}")"""
27
 
28
 
29
- sample1_audio_data = all_data_audio_data[0]
30
- # sample1_audio_path = next((p for p in all_data_audio_paths if p.endswith("/home/user/.cache/huggingface/hub/datasets--intersteller2887--Turing-test-dataset/snapshots/5cd5dd6c5badbbce22a66b3b49c4224751b10375/data/bf_train_L2_T01_1_glm.wav")), None)
31
- # print(sample1_audio_path)
32
 
33
  # ==============================================================================
34
  # 数据定义 (Data Definition)
@@ -36,8 +29,7 @@ sample1_audio_data = all_data_audio_data[0]
36
  DIMENSIONS_DATA = [
37
  {
38
  "title": "语义和语用特征",
39
- "audio": sample1_audio_data[0],
40
- "rate": sample1_audio_data[1],
41
  "desc": "这是“语义和语用特征”维度的文本描述示例。",
42
  "sub_dims": [
43
  "记忆一致性:回应者是否能够正确并正确并延续并记忆并延续对话信息?是否存在对上下文的误解或不自洽?", "逻辑连贯性:回应者在语义与对话结构上保持前后一致、合乎逻辑?是否存在前后矛盾的情况?",
@@ -57,8 +49,7 @@ DIMENSIONS_DATA = [
57
  },
58
  {
59
  "title": "非生理性副语言特征",
60
- "audio": sample1_audio_data[0],
61
- "rate": sample1_audio_data[1],
62
  "desc": "这是“非生理性副语言特征”维度的文本描述示例。",
63
  "sub_dims": [
64
  "节奏:回应者是否存在自然的停顿?语速是否存在自然、流畅的变化?", "语调:在表达疑问、惊讶、强调时,回应者的音调是否会自然上扬或下降?是否表现出符合语境的变化?",
@@ -73,8 +64,7 @@ DIMENSIONS_DATA = [
73
  },
74
  {
75
  "title": "生理性副语言特征",
76
- "audio": sample1_audio_data[0],
77
- "rate": sample1_audio_data[1],
78
  "desc": "这是“生理性副语言特征”维度的文本描述示例。",
79
  "sub_dims": [
80
  "微生理杂音:回应中是否出现如呼吸声、口水音、气泡音等无意识发声?这些发声是否自然地穿插在恰当的语流节奏当中?",
@@ -88,8 +78,7 @@ DIMENSIONS_DATA = [
88
  },
89
  {
90
  "title": "机械人格",
91
- "audio": sample1_audio_data[0],
92
- "rate": sample1_audio_data[1],
93
  "desc": "这是“机械人格”维度的文本描述示例。",
94
  "sub_dims": [
95
  "谄媚现象:回应者是否频繁地赞同用户、重复用户的说法、不断表示感谢或道歉?是否存在“无论用户说什么都肯定或支持”的语气模式?",
@@ -102,8 +91,7 @@ DIMENSIONS_DATA = [
102
  },
103
  {
104
  "title": "情感表达",
105
- "audio": sample1_audio_data[0],
106
- "rate": sample1_audio_data[1],
107
  "desc": "这是“情感表达”维度的文本描述示例。",
108
  "sub_dims": [
109
  "语义层面:回应者的语言内容是否体现出符合上下文的情绪反应?是否表达了人类对某些情境应有的情感态度?",
@@ -119,19 +107,12 @@ DIMENSIONS_DATA = [
119
  DIMENSION_TITLES = [d["title"] for d in DIMENSIONS_DATA]
120
 
121
  random.seed()
122
-
123
- selected_audio_data = random.sample(all_data_audio_data, 5)
124
-
125
- QUESTION_SET = [
126
- {"audio": data[0], "rate": data[1], "desc": f"这是一个测试音频"}
127
- for data in selected_audio_data
128
- ]
129
- """selected_audio_paths = random.sample(all_data_audio_paths, 5)
130
 
131
  QUESTION_SET = [
132
  {"audio": path, "desc": f"这是音频文件 {os.path.basename(path)} 的描述"}
133
  for path in selected_audio_paths
134
- ]"""
135
 
136
  """QUESTION_SET = [
137
  {"audio": "data/Ses02F_impro01.wav", "desc": "这是第一个测试文件的描述",},
@@ -168,8 +149,7 @@ def update_sample_view(dimension_title):
168
  dim_data = next((d for d in DIMENSIONS_DATA if d["title"] == dimension_title), None)
169
  if dim_data:
170
  return (
171
- # gr.update(value=dim_data["audio"]),
172
- gr.update(value=(dim_data["audio"], dim_data["rate"])),
173
  gr.update(value=dim_data["desc"]),
174
  gr.update(choices=dim_data["sub_dims"], value=[], interactive=True),
175
  gr.update(value=dim_data["reference"])
@@ -216,8 +196,7 @@ def init_test_question(user_data, q_idx):
216
  q_idx, d_idx, {},
217
  gr.update(value=progress_q),
218
  dim_title_update,
219
- gr.update(value=(question['audio'], question['rate'])),
220
- # gr.update(value=question['audio']),
221
  gr.update(value=question['desc']),
222
  prev_btn_update,
223
  next_btn_update,
@@ -270,9 +249,7 @@ def submit_question_and_advance(q_idx, d_idx, selections, final_choice, all_resu
270
  selections["final_choice"] = final_choice
271
 
272
  final_question_result = {
273
- "question_id": q_idx,
274
- "audio_array": QUESTION_SET[q_idx]['audio'].tolist(), # numpy -> list
275
- "sampling_rate": QUESTION_SET[q_idx]['rate'],
276
  "user_data": user_data, "selections": selections
277
  }
278
  all_results.append(final_question_result)
@@ -285,8 +262,7 @@ def submit_question_and_advance(q_idx, d_idx, selections, final_choice, all_resu
285
  else:
286
  result_str = "### 测试全部完成!\n\n你的提交结果概览:\n"
287
  for res in all_results:
288
- result_str += f"\n#### 题目: 音频 {res['question_id']}({len(res['audio_array'])} samples @ {res['sampling_rate']} Hz)\n"
289
- # result_str += f"\n#### 题目: {res['audio_file']}\n"
290
  result_str += f"##### 最终判断: **{res['selections'].get('final_choice', '未选择')}**\n"
291
  for dim_title, dim_data in res['selections'].items():
292
  if dim_title == 'final_choice': continue
 
10
 
11
  print(dataset[0])
12
 
13
+ all_data_audio_paths = [
14
  item["audio"]["path"]
15
  for item in dataset
16
  if item["audio"] and "path" in item["audio"]
 
 
 
 
 
 
17
  ]
18
 
19
  """valid_audio_paths = [path for path in all_data_audio_paths if os.path.exists(path)]
20
  print(f"Total valid audio files: {len(valid_audio_paths)}")"""
21
 
22
 
23
+ sample1_audio_path = next((p for p in all_data_audio_paths if p.endswith("/home/user/.cache/huggingface/hub/datasets--intersteller2887--Turing-test-dataset/snapshots/5cd5dd6c5badbbce22a66b3b49c4224751b10375/data/bf_train_L2_T01_1_glm.wav")), None)
24
+ print(sample1_audio_path)
 
25
 
26
  # ==============================================================================
27
  # 数据定义 (Data Definition)
 
29
  DIMENSIONS_DATA = [
30
  {
31
  "title": "语义和语用特征",
32
+ "audio": sample1_audio_path,
 
33
  "desc": "这是“语义和语用特征”维度的文本描述示例。",
34
  "sub_dims": [
35
  "记忆一致性:回应者是否能够正确并正确并延续并记忆并延续对话信息?是否存在对上下文的误解或不自洽?", "逻辑连贯性:回应者在语义与对话结构上保持前后一致、合乎逻辑?是否存在前后矛盾的情况?",
 
49
  },
50
  {
51
  "title": "非生理性副语言特征",
52
+ "audio": sample1_audio_path,
 
53
  "desc": "这是“非生理性副语言特征”维度的文本描述示例。",
54
  "sub_dims": [
55
  "节奏:回应者是否存在自然的停顿?语速是否存在自然、流畅的变化?", "语调:在表达疑问、惊讶、强调时,回应者的音调是否会自然上扬或下降?是否表现出符合语境的变化?",
 
64
  },
65
  {
66
  "title": "生理性副语言特征",
67
+ "audio": sample1_audio_path,
 
68
  "desc": "这是“生理性副语言特征”维度的文本描述示例。",
69
  "sub_dims": [
70
  "微生理杂音:回应中是否出现如呼吸声、口水音、气泡音等无意识发声?这些发声是否自然地穿插在恰当的语流节奏当中?",
 
78
  },
79
  {
80
  "title": "机械人格",
81
+ "audio": sample1_audio_path,
 
82
  "desc": "这是“机械人格”维度的文本描述示例。",
83
  "sub_dims": [
84
  "谄媚现象:回应者是否频繁地赞同用户、重复用户的说法、不断表示感谢或道歉?是否存在“无论用户说什么都肯定或支持”的语气模式?",
 
91
  },
92
  {
93
  "title": "情感表达",
94
+ "audio": sample1_audio_path,
 
95
  "desc": "这是“情感表达”维度的文本描述示例。",
96
  "sub_dims": [
97
  "语义层面:回应者的语言内容是否体现出符合上下文的情绪反应?是否表达了人类对某些情境应有的情感态度?",
 
107
  DIMENSION_TITLES = [d["title"] for d in DIMENSIONS_DATA]
108
 
109
  random.seed()
110
+ selected_audio_paths = random.sample(all_data_audio_paths, 5)
 
 
 
 
 
 
 
111
 
112
  QUESTION_SET = [
113
  {"audio": path, "desc": f"这是音频文件 {os.path.basename(path)} 的描述"}
114
  for path in selected_audio_paths
115
+ ]
116
 
117
  """QUESTION_SET = [
118
  {"audio": "data/Ses02F_impro01.wav", "desc": "这是第一个测试文件的描述",},
 
149
  dim_data = next((d for d in DIMENSIONS_DATA if d["title"] == dimension_title), None)
150
  if dim_data:
151
  return (
152
+ gr.update(value=dim_data["audio"]),
 
153
  gr.update(value=dim_data["desc"]),
154
  gr.update(choices=dim_data["sub_dims"], value=[], interactive=True),
155
  gr.update(value=dim_data["reference"])
 
196
  q_idx, d_idx, {},
197
  gr.update(value=progress_q),
198
  dim_title_update,
199
+ gr.update(value=question['audio']),
 
200
  gr.update(value=question['desc']),
201
  prev_btn_update,
202
  next_btn_update,
 
249
  selections["final_choice"] = final_choice
250
 
251
  final_question_result = {
252
+ "question_id": q_idx, "audio_file": QUESTION_SET[q_idx]['audio'],
 
 
253
  "user_data": user_data, "selections": selections
254
  }
255
  all_results.append(final_question_result)
 
262
  else:
263
  result_str = "### 测试全部完成!\n\n你的提交结果概览:\n"
264
  for res in all_results:
265
+ result_str += f"\n#### 题目: {res['audio_file']}\n"
 
266
  result_str += f"##### 最终判断: **{res['selections'].get('final_choice', '未选择')}**\n"
267
  for dim_title, dim_data in res['selections'].items():
268
  if dim_title == 'final_choice': continue