Spaces:
Sleeping
Sleeping
Truong-Phuc Nguyen
commited on
Fix KeyError: 0 :))))
Browse files
app.py
CHANGED
@@ -25,9 +25,9 @@ if 'df' not in st.session_state:
|
|
25 |
st.session_state.df = df
|
26 |
|
27 |
if 'idx' not in st.session_state:
|
28 |
-
st.session_state.idx =
|
29 |
|
30 |
-
st.markdown(f"<h3 style='text-align: center;'>Sample {st.session_state.idx}/{len(df)}</h3>", unsafe_allow_html=True)
|
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 |
|
@@ -39,9 +39,9 @@ btn_save = col_3.button(label=':heavy_check_mark: Save change', use_container_wi
|
|
39 |
if len(df) != 0:
|
40 |
index = st.session_state.idx
|
41 |
|
42 |
-
txt_context = st.text_area(height=300, label='Your context:', value=st.session_state.df
|
43 |
-
txt_question = st.text_area(height=100, label='Your question:', value=st.session_state.df
|
44 |
-
txt_answer = st.text_area(height=100, label='Your answer:', value=st.session_state.df
|
45 |
|
46 |
if txt_answer.strip() and txt_context.strip():
|
47 |
highlighted_context = re.sub(re.escape(txt_answer), "<mark>" + txt_answer + "</mark>", txt_context, flags=re.IGNORECASE)
|
@@ -49,18 +49,18 @@ if len(df) != 0:
|
|
49 |
|
50 |
|
51 |
if btn_next:
|
52 |
-
if index
|
53 |
st.session_state.idx += 1
|
54 |
st.rerun()
|
55 |
|
56 |
if btn_save:
|
57 |
-
st.session_state.df
|
58 |
-
st.session_state.df
|
59 |
-
st.session_state.df
|
60 |
csv_file = convert_df(df=st.session_state.df)
|
61 |
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")
|
62 |
|
63 |
if btn_previous:
|
64 |
-
if index
|
65 |
st.session_state.idx -= 1
|
66 |
st.rerun()
|
|
|
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"<h3 style='text-align: center;'>Sample {st.session_state.idx + 1}/{len(df)}</h3>", unsafe_allow_html=True)
|
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 |
|
|
|
39 |
if len(df) != 0:
|
40 |
index = st.session_state.idx
|
41 |
|
42 |
+
txt_context = st.text_area(height=300, label='Your context:', value=st.session_state.df['context'][index])
|
43 |
+
txt_question = st.text_area(height=100, label='Your question:', value=st.session_state.df['question'][index])
|
44 |
+
txt_answer = st.text_area(height=100, label='Your answer:', value=st.session_state.df['answer'][index])
|
45 |
|
46 |
if txt_answer.strip() and txt_context.strip():
|
47 |
highlighted_context = re.sub(re.escape(txt_answer), "<mark>" + txt_answer + "</mark>", txt_context, flags=re.IGNORECASE)
|
|
|
49 |
|
50 |
|
51 |
if btn_next:
|
52 |
+
if index < len(df) - 1:
|
53 |
st.session_state.idx += 1
|
54 |
st.rerun()
|
55 |
|
56 |
if btn_save:
|
57 |
+
st.session_state.df['context'][index] = txt_context
|
58 |
+
st.session_state.df['question'][index] = txt_question
|
59 |
+
st.session_state.df['answer'][index] = txt_answer
|
60 |
csv_file = convert_df(df=st.session_state.df)
|
61 |
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")
|
62 |
|
63 |
if btn_previous:
|
64 |
+
if index > 0:
|
65 |
st.session_state.idx -= 1
|
66 |
st.rerun()
|