Spaces:
Sleeping
Sleeping
Truong-Phuc Nguyen
commited on
Delete Upload function :))
Browse files
app.py
CHANGED
|
@@ -1,67 +1,50 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
import re
|
| 4 |
|
| 5 |
st.set_page_config(page_icon='🍃', page_title='MRC for Legal Document Dataset checker', layout='wide', initial_sidebar_state="collapsed")
|
| 6 |
|
| 7 |
-
|
| 8 |
-
def load_data(file_uploader):
|
| 9 |
-
if file_uploader is not None:
|
| 10 |
-
return pd.read_csv(file_uploader)
|
| 11 |
-
else:
|
| 12 |
-
return pd.DataFrame(columns=['context', 'question', 'answer'])
|
| 13 |
-
|
| 14 |
-
def convert_df(df):
|
| 15 |
-
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
| 16 |
-
return df.to_csv().encode("utf-8")
|
| 17 |
-
# end processing events
|
| 18 |
-
|
| 19 |
-
st.markdown("<h1 style='text-align: center;'>Investigation Legal Dataset checker for Machine Reading Comprehension</h1>", unsafe_allow_html=True)
|
| 20 |
-
|
| 21 |
-
file = st.file_uploader(label='Upload your file here:', type=['csv'], accept_multiple_files=False, label_visibility='hidden')
|
| 22 |
-
df = load_data(file_uploader=file)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
st.session_state.df = df
|
| 26 |
|
| 27 |
if 'idx' not in st.session_state:
|
| 28 |
st.session_state.idx = 0
|
| 29 |
|
| 30 |
-
st.markdown(f"<
|
| 31 |
|
| 32 |
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])
|
| 33 |
|
| 34 |
btn_previous = col_1.button(label=':arrow_backward: Previous sample', use_container_width=True)
|
| 35 |
btn_next = col_2.button(label='Next sample :arrow_forward:', use_container_width=True)
|
| 36 |
btn_save = col_3.button(label=':heavy_check_mark: Save change', use_container_width=True)
|
| 37 |
-
# txt_goto = col_4.selectbox(label='None', options=[np.array(range(len(df)))], label_visibility='collapsed')
|
| 38 |
|
| 39 |
if len(df) != 0:
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
txt_context = st.text_area(height=300, label='Your context:', value=st.session_state.df['context'][index])
|
| 44 |
-
txt_question = st.text_area(height=100, label='Your question:', value=st.session_state.df['question'][index])
|
| 45 |
-
txt_answer = st.text_area(height=100, label='Your answer:', value=st.session_state.df['answer'][index])
|
| 46 |
|
| 47 |
if txt_answer.strip() and txt_context.strip():
|
| 48 |
highlighted_context = re.sub(re.escape(txt_answer), "<mark>" + txt_answer + "</mark>", txt_context, flags=re.IGNORECASE)
|
| 49 |
st.markdown(highlighted_context, unsafe_allow_html=True)
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
if btn_next:
|
| 53 |
-
if
|
| 54 |
st.session_state.idx += 1
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
if btn_save:
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
csv_file = convert_df(df=st.session_state.df)
|
| 62 |
-
btn_download = col_4.download_button(data=csv_file, label=':arrow_down_small: Download file', use_container_width=True, file_name="large_df.csv", mime="text/csv")
|
| 63 |
|
| 64 |
-
|
| 65 |
-
if index > 0:
|
| 66 |
-
st.session_state.idx -= 1
|
| 67 |
-
# st.rerun()
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
+
import streamlit as st
|
| 3 |
import re
|
| 4 |
|
| 5 |
st.set_page_config(page_icon='🍃', page_title='MRC for Legal Document Dataset checker', layout='wide', initial_sidebar_state="collapsed")
|
| 6 |
|
| 7 |
+
st.markdown("<h2 style='text-align: center;'>Investigation Legal Dataset checker for Machine Reading Comprehension</h2>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
df = pd.read_csv(filepath_or_buffer='D:\KNOWLEDGES FUNDAMENTAL\YEAR 3\[NLP] INVESTIGATION LEGAL DOCUMENTS\Datasets\Legal_AbstractiveA.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;'>Sample {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: Previous sample', use_container_width=True)
|
| 19 |
btn_next = col_2.button(label='Next sample :arrow_forward:', use_container_width=True)
|
| 20 |
btn_save = col_3.button(label=':heavy_check_mark: Save change', use_container_width=True)
|
|
|
|
| 21 |
|
| 22 |
if len(df) != 0:
|
| 23 |
+
txt_context = st.text_area(height=300, label='Your context:', value=df['context'][st.session_state.idx])
|
| 24 |
+
txt_question = st.text_area(height=100, label='Your question:', value=df['question'][st.session_state.idx])
|
| 25 |
+
txt_answer = st.text_area(height=100, label='Your answer:', value=df['answer'][st.session_state.idx])
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
if txt_answer.strip() and txt_context.strip():
|
| 28 |
highlighted_context = re.sub(re.escape(txt_answer), "<mark>" + txt_answer + "</mark>", txt_context, flags=re.IGNORECASE)
|
| 29 |
st.markdown(highlighted_context, unsafe_allow_html=True)
|
| 30 |
|
| 31 |
+
if btn_previous:
|
| 32 |
+
if st.session_state.idx > 0:
|
| 33 |
+
st.session_state.idx -= 1
|
| 34 |
+
st.rerun()
|
| 35 |
+
else:
|
| 36 |
+
pass
|
| 37 |
|
| 38 |
if btn_next:
|
| 39 |
+
if st.session_state.idx <= (len(df) - 1):
|
| 40 |
st.session_state.idx += 1
|
| 41 |
+
st.rerun()
|
| 42 |
+
else:
|
| 43 |
+
pass
|
| 44 |
+
|
| 45 |
if btn_save:
|
| 46 |
+
df['context'][st.session_state.idx] = txt_context
|
| 47 |
+
df['question'][st.session_state.idx] = txt_question
|
| 48 |
+
df['answer'][st.session_state.idx] = txt_answer
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
df.to_csv(path_or_buf='D:\KNOWLEDGES FUNDAMENTAL\YEAR 3\[NLP] INVESTIGATION LEGAL DOCUMENTS\Datasets\Legal_AbstractiveA.csv', index=None)
|
|
|
|
|
|
|
|
|