Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_icon='🍃', page_title='[ViLegal] MRC Dataset Labeling Tool', layout='wide', initial_sidebar_state="collapsed")
|
| 6 |
+
|
| 7 |
+
st.markdown("<h2 style='text-align: center;'>MRC Dataset Labeling Tool</h2>", unsafe_allow_html=True)
|
| 8 |
+
|
| 9 |
+
df = pd.read_csv(filepath_or_buffer='./dup_non-span.csv')
|
| 10 |
+
|
| 11 |
+
if 'idx' not in st.session_state:
|
| 12 |
+
st.session_state.idx = 0
|
| 13 |
+
|
| 14 |
+
st.markdown(f"<h4 style='text-align: center;'>Bản ghi {st.session_state.idx + 1}/{len(df)}</h4>", unsafe_allow_html=True)
|
| 15 |
+
|
| 16 |
+
col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9, col_10 = st.columns([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
|
| 17 |
+
|
| 18 |
+
btn_previous = col_1.button(label=':arrow_backward: Bản ghi trước', use_container_width=True)
|
| 19 |
+
btn_next = col_2.button(label='Bản ghi sau :arrow_forward:', use_container_width=True)
|
| 20 |
+
btn_save = col_3.button(label=':heavy_check_mark: Lưu thay đổi', use_container_width=True)
|
| 21 |
+
txt_goto = col_5.selectbox(label='Sample', label_visibility='collapsed', options=list(range(1, len(df) + 1)))
|
| 22 |
+
btn_goto = col_6.button(label=':fast_forward: Chuyển đến', use_container_width=True)
|
| 23 |
+
|
| 24 |
+
if len(df) != 0:
|
| 25 |
+
txt_context = st.text_area(height=300, label='Ngữ cảnh:', value=df['context'][st.session_state.idx])
|
| 26 |
+
txt_question = st.text_area(height=100, label='Câu hỏi:', value=df['question'][st.session_state.idx])
|
| 27 |
+
txt_answer = st.text_area(height=100, label='Câu trả lời:', value=df['answer'][st.session_state.idx])
|
| 28 |
+
|
| 29 |
+
if txt_answer.strip() and txt_context.strip():
|
| 30 |
+
highlighted_context = re.sub(re.escape(txt_answer), "<mark>" + txt_answer + "</mark>", txt_context, flags=re.IGNORECASE)
|
| 31 |
+
st.markdown(highlighted_context, unsafe_allow_html=True)
|
| 32 |
+
|
| 33 |
+
if btn_previous:
|
| 34 |
+
if st.session_state.idx > 0:
|
| 35 |
+
st.session_state.idx -= 1
|
| 36 |
+
st.rerun()
|
| 37 |
+
else:
|
| 38 |
+
pass
|
| 39 |
+
|
| 40 |
+
if btn_next:
|
| 41 |
+
if st.session_state.idx <= (len(df) - 1):
|
| 42 |
+
st.session_state.idx += 1
|
| 43 |
+
st.rerun()
|
| 44 |
+
else:
|
| 45 |
+
pass
|
| 46 |
+
|
| 47 |
+
if btn_save:
|
| 48 |
+
df['context'][st.session_state.idx] = txt_context
|
| 49 |
+
df['question'][st.session_state.idx] = txt_question
|
| 50 |
+
df['answer'][st.session_state.idx] = txt_answer
|
| 51 |
+
|
| 52 |
+
btn_download = col_4.download_button(data=df.to_csv(), label=':arrow_down_small: Tải file', use_container_width=True, file_name="checked.csv", mime="text/csv")
|
| 53 |
+
df.to_csv(path_or_buf='./LegalAbstractiveA_checked.csv', index=None)
|
| 54 |
+
|
| 55 |
+
if btn_goto:
|
| 56 |
+
st.session_state.idx = txt_goto - 1
|
| 57 |
+
st.rerun()
|