sunnyzjx commited on
Commit
17b313f
·
verified ·
1 Parent(s): a4c90b2

Update task_manager.py

Browse files
Files changed (1) hide show
  1. task_manager.py +14 -31
task_manager.py CHANGED
@@ -3,10 +3,10 @@ from data_processing import load_tasks
3
  from annotation import save_annotations
4
 
5
  tasks = load_tasks()
6
- # 移除全局 current_task 变量
7
 
8
 
9
- def get_current_task_with_annotations(current_task, annotation_results):
10
  """获取当前任务信息,应用已有标注的样式(用于初始加载)"""
11
  task = tasks[current_task]
12
  current_choice = annotation_results.get(current_task) if annotation_results else None
@@ -37,7 +37,7 @@ def get_current_task_with_annotations(current_task, annotation_results):
37
  )
38
 
39
 
40
- def get_current_task(current_task=0, annotation_results=None, styled=False):
41
  """获取当前任务信息,可选择是否应用样式"""
42
  task = tasks[current_task]
43
 
@@ -100,46 +100,30 @@ def apply_selection_style(audioA, audioB, choice):
100
  )
101
 
102
 
103
- def select_audio(choice, audioA, audioB, current_task, annotation_results, username):
104
  """记录选择并更新UI高亮,自动保存标注结果"""
105
  annotation_results[current_task] = choice
106
- print(f"用户 {username} 任务 {current_task}: 选择 {choice}")
107
-
108
- # 自动保存标注结果和当前任务进度
109
- user_data = {
110
- 'annotations': annotation_results,
111
- 'current_task': current_task
112
- }
113
- save_result = save_annotations(username, user_data, tasks)
114
  print(f"自动保存结果: {save_result}")
115
 
116
  audioA_update, audioB_update = apply_selection_style(audioA, audioB, choice)
117
  return audioA_update, audioB_update, annotation_results
118
 
119
 
120
- def change_task(direction, current_task, annotation_results, username):
121
  """切换任务"""
 
122
  if direction == "prev" and current_task > 0:
123
- new_current_task = current_task - 1
124
  elif direction == "next" and current_task < len(tasks) - 1:
125
- new_current_task = current_task + 1
126
- else:
127
- new_current_task = current_task # 不改变
128
-
129
- print(f"用户 {username} 从任务 {current_task} 切换到任务 {new_current_task}")
130
-
131
- # 保存当前任务进度到用户数据中
132
- if new_current_task != current_task:
133
- user_data = {
134
- 'annotations': annotation_results,
135
- 'current_task': new_current_task
136
- }
137
- save_result = save_annotations(username, user_data, tasks)
138
- print(f"保存任务进度: {save_result}")
139
 
140
  # 使用带样式的版本
141
  inst, text, audioA_update, audioB_update, prev_disabled, next_disabled, task_num = get_current_task(
142
- new_current_task, annotation_results, styled=True)
143
 
144
  total_tasks = get_total_tasks()
145
 
@@ -153,11 +137,10 @@ def change_task(direction, current_task, annotation_results, username):
153
  gr.update(interactive=not prev_disabled),
154
  gr.update(interactive=not next_disabled),
155
  gr.update(value=combined_task_info), # 更新任务编号位置的合并信息
156
- new_current_task, # 返回新的 current_task
157
  annotation_results
158
  )
159
 
160
 
161
  def get_total_tasks():
162
  """返回总任务数"""
163
- return len(tasks)
 
3
  from annotation import save_annotations
4
 
5
  tasks = load_tasks()
6
+ current_task = 0
7
 
8
 
9
+ def get_current_task_with_annotations(annotation_results):
10
  """获取当前任务信息,应用已有标注的样式(用于初始加载)"""
11
  task = tasks[current_task]
12
  current_choice = annotation_results.get(current_task) if annotation_results else None
 
37
  )
38
 
39
 
40
+ def get_current_task(annotation_results=None, styled=False):
41
  """获取当前任务信息,可选择是否应用样式"""
42
  task = tasks[current_task]
43
 
 
100
  )
101
 
102
 
103
+ def select_audio(choice, audioA, audioB, annotation_results, username):
104
  """记录选择并更新UI高亮,自动保存标注结果"""
105
  annotation_results[current_task] = choice
106
+ print(f"任务 {current_task}: 选择 {choice}")
107
+
108
+ # 自动保存标注结果
109
+ save_result = save_annotations(username, annotation_results, tasks)
 
 
 
 
110
  print(f"自动保存结果: {save_result}")
111
 
112
  audioA_update, audioB_update = apply_selection_style(audioA, audioB, choice)
113
  return audioA_update, audioB_update, annotation_results
114
 
115
 
116
+ def change_task(direction, annotation_results, username):
117
  """切换任务"""
118
+ global current_task
119
  if direction == "prev" and current_task > 0:
120
+ current_task -= 1
121
  elif direction == "next" and current_task < len(tasks) - 1:
122
+ current_task += 1
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
  # 使用带样式的版本
125
  inst, text, audioA_update, audioB_update, prev_disabled, next_disabled, task_num = get_current_task(
126
+ annotation_results, styled=True)
127
 
128
  total_tasks = get_total_tasks()
129
 
 
137
  gr.update(interactive=not prev_disabled),
138
  gr.update(interactive=not next_disabled),
139
  gr.update(value=combined_task_info), # 更新任务编号位置的合并信息
 
140
  annotation_results
141
  )
142
 
143
 
144
  def get_total_tasks():
145
  """返回总任务数"""
146
+ return len(tasks)