NghiTran1009 commited on
Commit
03ea370
·
verified ·
1 Parent(s): f2ec44a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -18,7 +18,7 @@ def extract_features(sentence):
18
  df_test = pd.read_csv("vi-chunk-test.csv")
19
 
20
  # Nhóm dữ liệu theo câu
21
- sentences = [group.drop(columns=["Chunk"]) for _, group in df_test.groupby("Sentence_ID")] # Xóa cột `Chunk`
22
 
23
  # Giao diện Annotator
24
  st.title("📝 Tool Annotator - Chỉnh sửa dữ liệu chunking")
@@ -33,7 +33,7 @@ y_pred = crf.predict(X_test)[0]
33
 
34
  # Thêm nhãn dự đoán vào dataframe
35
  sentence["Predicted_Chunk"] = y_pred
36
- sentence["Is_Correct"] = sentence["Predicted_Chunk"] == sentence["Predicted_Chunk"] # Kiểm tra dự đoán
37
 
38
  # Highlight lỗi: Màu đỏ nếu `Predicted_Chunk` sai
39
  def highlight_errors(row):
@@ -45,13 +45,14 @@ num_wrong = len(sentence) - num_correct
45
  st.write(f"✅ **Số token đúng**: {num_correct} / {len(sentence)}")
46
  st.write(f"❌ **Số token sai**: {num_wrong}")
47
 
48
- # **🔹 Bảng hiển thị với highlight lỗi**
49
- st.write("🔹 **Câu gốc**")
50
- st.dataframe(sentence.style.apply(highlight_errors, axis=1))
 
51
 
52
  # **🔹 Annotator chỉnh sửa `Predicted_Chunk`**
53
  edited_df = st.data_editor(
54
- sentence[["Token", "POS", "Predicted_Chunk"]], # Chỉ hiển thị 3 cột
55
  num_rows="dynamic", # Cho phép thêm hàng ở bất kỳ đâu
56
  key=f"edit_table_{sentence_id}"
57
  )
@@ -61,7 +62,8 @@ if os.path.exists("corrected_data.csv"):
61
  with open("corrected_data.csv", "rb") as file:
62
  st.download_button("📥 Tải xuống corrected_data.csv", file, "corrected_data.csv")
63
 
64
- # Lưu lại dữ liệu chỉnh sửa
65
  if st.button("Lưu chỉnh sửa"):
66
- edited_df.to_csv("corrected_data.csv", index=False, encoding="utf-8")
 
67
  st.success("✅ Dữ liệu đã được lưu thành corrected_data.csv!")
 
18
  df_test = pd.read_csv("vi-chunk-test.csv")
19
 
20
  # Nhóm dữ liệu theo câu
21
+ sentences = [group for _, group in df_test.groupby("Sentence_ID")]
22
 
23
  # Giao diện Annotator
24
  st.title("📝 Tool Annotator - Chỉnh sửa dữ liệu chunking")
 
33
 
34
  # Thêm nhãn dự đoán vào dataframe
35
  sentence["Predicted_Chunk"] = y_pred
36
+ sentence["Is_Correct"] = sentence["Chunk"] == sentence["Predicted_Chunk"] # Kiểm tra dự đoán
37
 
38
  # Highlight lỗi: Màu đỏ nếu `Predicted_Chunk` sai
39
  def highlight_errors(row):
 
45
  st.write(f"✅ **Số token đúng**: {num_correct} / {len(sentence)}")
46
  st.write(f"❌ **Số token sai**: {num_wrong}")
47
 
48
+ # **🔹 Hiển thị bảng đầy đủ (bao gồm `Chunk` nhưng không hiển thị trong Annotator)**
49
+ sentence_display = sentence.copy()
50
+ st.write("🔹 **Câu gốc (Highlight lỗi màu đỏ)**")
51
+ st.dataframe(sentence_display.style.apply(highlight_errors, axis=1))
52
 
53
  # **🔹 Annotator chỉnh sửa `Predicted_Chunk`**
54
  edited_df = st.data_editor(
55
+ sentence_display.drop(columns=["Chunk"]), # Ẩn cột `Chunk`
56
  num_rows="dynamic", # Cho phép thêm hàng ở bất kỳ đâu
57
  key=f"edit_table_{sentence_id}"
58
  )
 
62
  with open("corrected_data.csv", "rb") as file:
63
  st.download_button("📥 Tải xuống corrected_data.csv", file, "corrected_data.csv")
64
 
65
+ # Lưu lại dữ liệu chỉnh sửa (bao gồm `Chunk`, nhưng không hiển thị)
66
  if st.button("Lưu chỉnh sửa"):
67
+ sentence_display.update(edited_df) # Cập nhật lại dữ liệu chỉnh sửa
68
+ sentence_display.to_csv("corrected_data.csv", index=False, encoding="utf-8")
69
  st.success("✅ Dữ liệu đã được lưu thành corrected_data.csv!")