350016z commited on
Commit
8695fdb
·
verified ·
1 Parent(s): 0734b79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -155,25 +155,29 @@ def save_and_next(source, target, score, rater_selector):
155
  save_to_json(new_entry, score_file)
156
 
157
  current_index += 1
158
- if current_index < len(data):
159
- next_source, next_target = get_current_text()
160
- # [source, target, error_span, current_index_display, status]
161
- return next_source, next_target, "", str(current_index), f"分數已保存到 {score_file.name},請繼續下一筆!"
162
- else:
163
- return "已完成所有文本標註", "已完成所有文本標註", "", "", f"所有標記已完成並保存到 {score_file.name}"
 
164
 
165
  def update_file_selection(selected_file):
166
  global data_path, data, current_index, annotations_file, score_file
167
  data_path = os.path.join(current_dir, selected_file)
168
  data = pd.read_csv(data_path)
169
- current_index = int(data["id"].min()) # 每個檔案的最小id不一定由0開始
170
-
 
 
171
  file_base_name = os.path.splitext(selected_file)[0]
172
  annotations_file = DATASET_DIR / f"{file_base_name}_annotations-{uuid4()}.json"
173
  score_file = DATASET_DIR / f"{file_base_name}_score-{uuid4()}.json"
174
 
175
  # 刷新index的選項
176
- return get_current_text() + ("", get_all_ids(), str(current_index), f"已加載檔案:{selected_file}")
 
177
 
178
  def update_index_selection(selected_index):
179
  global current_index, data
 
155
  save_to_json(new_entry, score_file)
156
 
157
  current_index += 1
158
+ if current_index >= len(data):
159
+ return "已完成所有文本標記", "已完成所有文本標記", "", "", f"所有標記已完成並保存到 {score_file.name}!"
160
+
161
+ next_source, next_target = get_current_text()
162
+ # [source, target, error_span, current_index_display, status]
163
+ return next_source, next_target, "", str(current_index), f"分數已保存到 {score_file.name},請繼續下一筆!"
164
+
165
 
166
  def update_file_selection(selected_file):
167
  global data_path, data, current_index, annotations_file, score_file
168
  data_path = os.path.join(current_dir, selected_file)
169
  data = pd.read_csv(data_path)
170
+
171
+ all_ids = get_all_ids()
172
+ current_index = int(all_ids[0]) # 設定起始 index 為最小的 id
173
+
174
  file_base_name = os.path.splitext(selected_file)[0]
175
  annotations_file = DATASET_DIR / f"{file_base_name}_annotations-{uuid4()}.json"
176
  score_file = DATASET_DIR / f"{file_base_name}_score-{uuid4()}.json"
177
 
178
  # 刷新index的選項
179
+ return get_current_text() + ("", all_ids, str(current_index), f"已加載檔案:{selected_file}")
180
+
181
 
182
  def update_index_selection(selected_index):
183
  global current_index, data