350016z commited on
Commit
3ff36f9
·
verified ·
1 Parent(s): 7ff1a0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -16
app.py CHANGED
@@ -65,7 +65,7 @@ if not os.path.exists(data_path):
65
 
66
 
67
  # Loading Data-----------------------------------------------------------------------------------------------------------
68
- data = pd.read_csv(data_path)
69
 
70
  current_index = 0
71
  def get_all_ids():
@@ -99,7 +99,7 @@ def save_current(source, target, rater_selector, error_span, category, subcatego
99
  system = data.loc[current_index, "system"]
100
  lp = data.loc[current_index, "lp"]
101
  doc = data.loc[current_index, "doc"]
102
- id = int(data.loc[current_index, "id"]) # 確保 id 為標準 Python int
103
  reference = data.loc[current_index, "reference"]
104
 
105
 
@@ -136,7 +136,7 @@ def save_and_next(source, target, score, rater_selector):
136
  system = data.loc[current_index, "system"]
137
  lp = data.loc[current_index, "lp"]
138
  doc = data.loc[current_index, "doc"]
139
- id = int(data.loc[current_index, "id"]) # 確保 id 為標準 Python int
140
  reference = data.loc[current_index, "reference"]
141
 
142
  new_entry = {
@@ -163,7 +163,7 @@ def update_file_selection(selected_file):
163
  global data_path, data, current_index, annotations_file, score_file
164
  data_path = os.path.join(current_dir, selected_file)
165
  data = pd.read_csv(data_path)
166
- current_index = 0
167
 
168
  file_base_name = os.path.splitext(selected_file)[0]
169
  annotations_file = DATASET_DIR / f"{file_base_name}_annotations-{uuid4()}.json"
@@ -180,16 +180,6 @@ def update_index_selection(selected_index):
180
  return get_current_text() + (str(current_index), f"已跳轉至 id: {selected_index}")
181
  except:
182
  return "錯誤", "錯誤", str(current_index), "選擇的索引無效,請重新選擇"
183
- def update_index_selection(selected_index):
184
- global current_index, data
185
- try:
186
- selected_index = int(selected_index)
187
- if selected_index in data["id"].values:
188
- current_index = data.index[data["id"] == selected_index].tolist()[0]
189
- return get_current_text() + (str(current_index), f"已跳轉至 id: {selected_index}")
190
- except:
191
- return "錯誤", "錯誤", str(current_index), "選擇的索引無效,請重新選擇"
192
-
193
 
194
 
195
  categories = {
@@ -228,9 +218,9 @@ with gr.Blocks() as demo:
228
  index_selector = gr.Dropdown(label="選擇索引", choices=get_all_ids(), value="0")
229
  current_index_display = gr.Textbox(label="當前索引", value=str(current_index), interactive=False)
230
  with gr.Column(scale=6):
231
- source = gr.Textbox(label="原始文本", lines=10, interactive=False)
232
  with gr.Column(scale=6):
233
- target = gr.Textbox(label="翻譯文本", lines=10, interactive=False)
234
 
235
  with gr.Row(variant='panel', equal_height=True):
236
  with gr.Column(scale=1):
 
65
 
66
 
67
  # Loading Data-----------------------------------------------------------------------------------------------------------
68
+ data = pd.read_csv(data_path, dtype={"id": "Int64"}) # 確保 id 為標準 Python int
69
 
70
  current_index = 0
71
  def get_all_ids():
 
99
  system = data.loc[current_index, "system"]
100
  lp = data.loc[current_index, "lp"]
101
  doc = data.loc[current_index, "doc"]
102
+ id = data.loc[current_index, "id"]
103
  reference = data.loc[current_index, "reference"]
104
 
105
 
 
136
  system = data.loc[current_index, "system"]
137
  lp = data.loc[current_index, "lp"]
138
  doc = data.loc[current_index, "doc"]
139
+ id = data.loc[current_index, "id"]
140
  reference = data.loc[current_index, "reference"]
141
 
142
  new_entry = {
 
163
  global data_path, data, current_index, annotations_file, score_file
164
  data_path = os.path.join(current_dir, selected_file)
165
  data = pd.read_csv(data_path)
166
+ current_index = int(data["id"].min()) # 每個檔案的最小id不一定由0開始
167
 
168
  file_base_name = os.path.splitext(selected_file)[0]
169
  annotations_file = DATASET_DIR / f"{file_base_name}_annotations-{uuid4()}.json"
 
180
  return get_current_text() + (str(current_index), f"已跳轉至 id: {selected_index}")
181
  except:
182
  return "錯誤", "錯誤", str(current_index), "選擇的索引無效,請重新選擇"
 
 
 
 
 
 
 
 
 
 
183
 
184
 
185
  categories = {
 
218
  index_selector = gr.Dropdown(label="選擇索引", choices=get_all_ids(), value="0")
219
  current_index_display = gr.Textbox(label="當前索引", value=str(current_index), interactive=False)
220
  with gr.Column(scale=6):
221
+ source = gr.Textbox(label="原始文本", lines=15, interactive=False)
222
  with gr.Column(scale=6):
223
+ target = gr.Textbox(label="翻譯文本", lines=15, interactive=False)
224
 
225
  with gr.Row(variant='panel', equal_height=True):
226
  with gr.Column(scale=1):