Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -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 = data.loc[current_index, "id"]
|
103 |
reference = data.loc[current_index, "reference"]
|
104 |
|
105 |
|
@@ -138,7 +138,7 @@ def save_and_next(source, target, score, rater_selector):
|
|
138 |
system = data.loc[current_index, "system"]
|
139 |
lp = data.loc[current_index, "lp"]
|
140 |
doc = data.loc[current_index, "doc"]
|
141 |
-
id = data.loc[current_index, "id"]
|
142 |
reference = data.loc[current_index, "reference"]
|
143 |
|
144 |
new_entry = {
|
@@ -166,18 +166,19 @@ def save_and_next(source, target, score, rater_selector):
|
|
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 |
-
return get_current_text() + ("",
|
179 |
|
180 |
-
|
181 |
|
182 |
def update_index_selection(selected_index):
|
183 |
global current_index, data
|
@@ -258,6 +259,7 @@ with gr.Blocks() as demo:
|
|
258 |
else:
|
259 |
return gr.update(choices=[], value=None)
|
260 |
|
|
|
261 |
file_selector.change(update_file_selection, inputs=[file_selector], outputs=[source, target, error_span, index_selector, current_index_display, status])
|
262 |
index_selector.change(update_index_selection, inputs=[index_selector], outputs=[source, target, current_index_display, status])
|
263 |
category.change(update_subcategories, inputs=[category], outputs=[subcategory])
|
|
|
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"])
|
103 |
reference = data.loc[current_index, "reference"]
|
104 |
|
105 |
|
|
|
138 |
system = data.loc[current_index, "system"]
|
139 |
lp = data.loc[current_index, "lp"]
|
140 |
doc = data.loc[current_index, "doc"]
|
141 |
+
id = int(data.loc[current_index, "id"])
|
142 |
reference = data.loc[current_index, "reference"]
|
143 |
|
144 |
new_entry = {
|
|
|
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 |
+
id_list = [str(id) for id in sorted(data["id"].unique())] # 轉為字串,確保 Gradio Dropdown 兼容
|
172 |
+
min_id = id_list[0] # 取得最小的 ID
|
173 |
+
|
174 |
+
current_index = data.index[data["id"] == int(min_id)].tolist()[0] # 設定 current_index
|
175 |
+
|
176 |
file_base_name = os.path.splitext(selected_file)[0]
|
177 |
annotations_file = DATASET_DIR / f"{file_base_name}_annotations-{uuid4()}.json"
|
178 |
score_file = DATASET_DIR / f"{file_base_name}_score-{uuid4()}.json"
|
179 |
|
180 |
+
return get_current_text() + ("", gr.update(choices=id_list, value=min_id), str(current_index), f"已加載檔案:{selected_file}")
|
181 |
|
|
|
182 |
|
183 |
def update_index_selection(selected_index):
|
184 |
global current_index, data
|
|
|
259 |
else:
|
260 |
return gr.update(choices=[], value=None)
|
261 |
|
262 |
+
|
263 |
file_selector.change(update_file_selection, inputs=[file_selector], outputs=[source, target, error_span, index_selector, current_index_display, status])
|
264 |
index_selector.change(update_index_selection, inputs=[index_selector], outputs=[source, target, current_index_display, status])
|
265 |
category.change(update_subcategories, inputs=[category], outputs=[subcategory])
|