ijundi commited on
Commit
f02d9bc
1 Parent(s): da185bf

fix messed up navigation

Browse files
Files changed (2) hide show
  1. app.py +28 -25
  2. requirements.txt +0 -2
app.py CHANGED
@@ -7,6 +7,8 @@ import streamlit as st
7
 
8
  from huggingface_hub import HfFileSystem
9
 
 
 
10
 
11
  # Function to get user ID from URL
12
  def get_user_id_from_url():
@@ -32,12 +34,22 @@ hf_fs = HfFileSystem(token=HF_TOKEN)
32
  def save_data(data):
33
  user_file_path = f"datasets/ijundi/mod-gen-eval-test/{data['user_id']}"
34
  hf_fs.mkdir(user_file_path)
35
- with hf_fs.open(f"{user_file_path}/{data['COMMENT ID']}.json", "w") as f:
36
  f.write(json.dumps(data))
37
 
38
 
39
  #################################### Streamlit App ####################################
40
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  # Title of the app
43
  st.title("Moderation Feedback Collection")
@@ -51,28 +63,17 @@ if 'current_index' not in st.session_state:
51
  st.session_state.current_index = -1
52
 
53
 
54
- # Function to navigate rows
55
- def navigate(index_change):
56
- st.session_state.current_index += index_change
57
- print(st.session_state.current_index)
58
- # Loop around if navigating beyond the start or end
59
- if st.session_state.current_index < 0:
60
- st.session_state.current_index = len(st.session_state.data) - 1
61
- elif st.session_state.current_index >= len(st.session_state.data):
62
- st.session_state.current_index = 0
63
-
64
 
65
- # Retrieve user ID from URL
66
- user_id = get_user_id_from_url()
67
  if st.session_state.current_index == -1:
68
- st.session_state.user_id = st.text_input('Please enter your user ID to proceed', value=user_id)
69
- else:
70
- # Display current row data
71
- st.write(f"Data for row {st.session_state.current_index + 1}:")
72
- st.dataframe(st.session_state.data.iloc[[st.session_state.current_index]])
73
 
74
- # Creating the form
 
75
  with st.form("feedback_form"):
 
 
 
76
  st.write("Please provide your feedback:")
77
 
78
  q1_reply_comment = st.selectbox("Is the reply comment fitting and does it make sense as a reply to the preceding comment? (0-4)", options=[0, 1, 2, 3, 4])
@@ -83,14 +84,13 @@ else:
83
  q6_actions_clear = st.selectbox("Does the reply make it clear what actions need to be done? (0-4)", options=[0, 1, 2, 3, 4])
84
  other_comments = st.text_area("Other: free text?")
85
 
86
- submitted = st.form_submit_button("Submit")
87
-
88
- if submitted:
89
- # Save the feedback
90
  data = {
91
- 'user_id': st.session_state,
92
  'index': st.session_state.current_index,
93
- 'COMMENT ID': st.session_state.data.iloc[st.session_state.current_index]['COMMENT ID'],
94
  'q1_reply_comment': q1_reply_comment,
95
  'q2_moderator_function': q2_moderator_function,
96
  'q3_issues_in_comment': q3_issues_in_comment,
@@ -102,6 +102,9 @@ else:
102
  save_data(data)
103
  st.success("Feedback submitted successfully!")
104
 
 
 
 
105
  # Navigation buttons
106
  col1, col2 = st.columns(2)
107
  # with col1:
 
7
 
8
  from huggingface_hub import HfFileSystem
9
 
10
+ COMMENT_ID_COL = 'COMMENT ID'
11
+
12
 
13
  # Function to get user ID from URL
14
  def get_user_id_from_url():
 
34
  def save_data(data):
35
  user_file_path = f"datasets/ijundi/mod-gen-eval-test/{data['user_id']}"
36
  hf_fs.mkdir(user_file_path)
37
+ with hf_fs.open(f"{user_file_path}/{data[COMMENT_ID_COL]}.json", "w") as f:
38
  f.write(json.dumps(data))
39
 
40
 
41
  #################################### Streamlit App ####################################
42
 
43
+ # Function to navigate rows
44
+ def navigate(index_change):
45
+ st.session_state.current_index += index_change
46
+ print(st.session_state.current_index)
47
+ # Loop around if navigating beyond the start or end
48
+ if st.session_state.current_index < 0:
49
+ st.session_state.current_index = len(st.session_state.data) - 1
50
+ elif st.session_state.current_index >= len(st.session_state.data):
51
+ st.session_state.current_index = 0
52
+
53
 
54
  # Title of the app
55
  st.title("Moderation Feedback Collection")
 
63
  st.session_state.current_index = -1
64
 
65
 
66
+ st.write(f"Page {st.session_state.current_index + 1} out of {len(st.session_state.data)}")
 
 
 
 
 
 
 
 
 
67
 
 
 
68
  if st.session_state.current_index == -1:
69
+ st.session_state.user_id = st.text_input('Please enter your user ID to proceed', value=get_user_id_from_url())
 
 
 
 
70
 
71
+ elif st.session_state.current_index <= len(st.session_state.data):
72
+ # Creating the form
73
  with st.form("feedback_form"):
74
+ # Display current row data
75
+ st.dataframe(st.session_state.data.iloc[[st.session_state.current_index]])
76
+
77
  st.write("Please provide your feedback:")
78
 
79
  q1_reply_comment = st.selectbox("Is the reply comment fitting and does it make sense as a reply to the preceding comment? (0-4)", options=[0, 1, 2, 3, 4])
 
84
  q6_actions_clear = st.selectbox("Does the reply make it clear what actions need to be done? (0-4)", options=[0, 1, 2, 3, 4])
85
  other_comments = st.text_area("Other: free text?")
86
 
87
+ # https://discuss.streamlit.io/t/run-streamlit-from-pycharm/21624/10
88
+ # st.form_submit_button("Submit", on_click=lambda: navigate(1))
89
+ if st.form_submit_button("Submit"):
 
90
  data = {
91
+ 'user_id': st.session_state.user_id,
92
  'index': st.session_state.current_index,
93
+ COMMENT_ID_COL: st.session_state.data.iloc[st.session_state.current_index][COMMENT_ID_COL],
94
  'q1_reply_comment': q1_reply_comment,
95
  'q2_moderator_function': q2_moderator_function,
96
  'q3_issues_in_comment': q3_issues_in_comment,
 
102
  save_data(data)
103
  st.success("Feedback submitted successfully!")
104
 
105
+ else:
106
+ st.write("Finished all data points!")
107
+
108
  # Navigation buttons
109
  col1, col2 = st.columns(2)
110
  # with col1:
requirements.txt CHANGED
@@ -1,4 +1,2 @@
1
  huggingface_hub==0.21.4
2
- requests==2.31.0
3
- datasets==2.18.0
4
  streamlit==1.32.0
 
1
  huggingface_hub==0.21.4
 
 
2
  streamlit==1.32.0