Ashmi Banerjee commited on
Commit
2b2f0d1
·
1 Parent(s): 29a4bc9

somewhat hacky fix but hopefully buttons work as expected

Browse files
README.md CHANGED
@@ -29,7 +29,9 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
29
  [x] Dataset linking HF
30
  [x] prettify the context field with new lines and highlighting popularity etc. keywords in bold
31
  [x] Doing it for two models - combine datasets
 
32
  [ ] Add check for ratings should not be 0 for Exit & Resume Later
33
  [x] Check the firebase DB rules
34
  [x] Add more descriptive titles for the queries
35
- [ ] Randomize the ordering
 
 
29
  [x] Dataset linking HF
30
  [x] prettify the context field with new lines and highlighting popularity etc. keywords in bold
31
  [x] Doing it for two models - combine datasets
32
+ [ ] Exit & Resume later does not work
33
  [ ] Add check for ratings should not be 0 for Exit & Resume Later
34
  [x] Check the firebase DB rules
35
  [x] Add more descriptive titles for the queries
36
+ [ ] Randomize the ordering
37
+ [ ] Bug: In the DB config_id is always medium_easy
app.py CHANGED
@@ -6,11 +6,10 @@ from dotenv import load_dotenv
6
  from views.intro_screen import welcome_screen
7
  from views.questions_screen import questions_screen
8
  from views.continue_survey import continue_survey_screen
9
- from views.ui_helpers import exit_screen, display_completion_message
10
  from css.layout import custom_css
11
-
12
  st.set_page_config(layout="wide")
13
 
 
14
  load_dotenv()
15
  VALIDATION_CODE = os.getenv("VALIDATION_CODE")
16
 
@@ -29,14 +28,34 @@ def initialization():
29
  st.session_state.show_questions = False
30
  if "survey_continued" not in st.session_state:
31
  st.session_state.survey_continued = None
32
- # if "start_new_survey" not in st.session_state:
33
- # st.session_state.start_new_survey = False
34
  if 'ratings' not in st.session_state:
35
  st.session_state.ratings = {}
36
  if 'previous_ratings' not in st.session_state:
37
  st.session_state.previous_ratings = {}
38
- if 'screen' not in st.session_state:
39
- st.session_state.screen = 'welcome'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
 
42
  def ui():
@@ -45,12 +64,11 @@ def ui():
45
  data = load_data()
46
  initialization()
47
 
48
- if st.session_state.completed: \
49
- # and not st.session_state.start_new_survey:
50
  exit_screen()
51
  return
52
 
53
- if st.session_state.username is None and st.session_state.screen == 'welcome':
54
  welcome_screen()
55
  else:
56
  # Check if user progress exists in Firebase
@@ -63,7 +81,7 @@ def ui():
63
  if st.session_state.current_index >= len(data):
64
  # If all questions have been answered, show the exit screen
65
  print("survey completed")
66
- display_completion_message()
67
  # Otherwise, show questions from where they left off
68
  questions_screen(data)
69
  else:
 
6
  from views.intro_screen import welcome_screen
7
  from views.questions_screen import questions_screen
8
  from views.continue_survey import continue_survey_screen
 
9
  from css.layout import custom_css
 
10
  st.set_page_config(layout="wide")
11
 
12
+
13
  load_dotenv()
14
  VALIDATION_CODE = os.getenv("VALIDATION_CODE")
15
 
 
28
  st.session_state.show_questions = False
29
  if "survey_continued" not in st.session_state:
30
  st.session_state.survey_continued = None
31
+ if "start_new_survey" not in st.session_state:
32
+ st.session_state.start_new_survey = False
33
  if 'ratings' not in st.session_state:
34
  st.session_state.ratings = {}
35
  if 'previous_ratings' not in st.session_state:
36
  st.session_state.previous_ratings = {}
37
+
38
+
39
+ def exit_screen():
40
+ """Display exit screen"""
41
+ st.markdown("""
42
+ <div class='exit-container'>
43
+ <h1>Thank you for participating!</h1>
44
+ <p>Your responses have been saved successfully.</p>
45
+ <p>You can safely close this window or start a new survey.</p>
46
+ </div>
47
+ """, unsafe_allow_html=True)
48
+
49
+ # if st.button("Resume Survey"):
50
+ # reset_survey()
51
+ # st.rerun()
52
+
53
+
54
+ def reset_survey():
55
+ """Reset the survey state to start over."""
56
+ st.session_state.responses = []
57
+ st.session_state.completed = True
58
+ st.session_state.start_new_survey = True
59
 
60
 
61
  def ui():
 
64
  data = load_data()
65
  initialization()
66
 
67
+ if st.session_state.completed and not st.session_state.start_new_survey:
 
68
  exit_screen()
69
  return
70
 
71
+ if st.session_state.username is None:
72
  welcome_screen()
73
  else:
74
  # Check if user progress exists in Firebase
 
81
  if st.session_state.current_index >= len(data):
82
  # If all questions have been answered, show the exit screen
83
  print("survey completed")
84
+ survey_completed()
85
  # Otherwise, show questions from where they left off
86
  questions_screen(data)
87
  else:
views/continue_survey.py CHANGED
@@ -34,8 +34,7 @@ def continue_survey_screen(data):
34
  # Set session state values based on saved progress
35
  st.session_state.current_index = saved_state.get("current_index", 0)
36
  st.session_state.responses = saved_state.get("responses", [])
37
- if len(st.session_state.responses) == len(data):
38
- st.session_state.completed = True
39
  # Find the last answered config_id in responses
40
  last_config_id = None
41
  if st.session_state.responses:
 
34
  # Set session state values based on saved progress
35
  st.session_state.current_index = saved_state.get("current_index", 0)
36
  st.session_state.responses = saved_state.get("responses", [])
37
+
 
38
  # Find the last answered config_id in responses
39
  last_config_id = None
40
  if st.session_state.responses:
views/intro_screen.py CHANGED
@@ -1,6 +1,8 @@
1
  import streamlit as st
2
  import os
3
  from dotenv import load_dotenv
 
 
4
 
5
  load_dotenv()
6
  VALIDATION_CODE = os.getenv("VALIDATION_CODE")
@@ -33,7 +35,6 @@ def welcome_screen():
33
  if (username_input and validation_code_input) or next_button:
34
  if validate_username(username_input) and validate_code(validation_code_input):
35
  st.session_state.username = username_input
36
- st.session_state.screen = "questions"
37
  else:
38
  if not validate_username(username_input):
39
  st.warning("Invalid username. Please check and try again.")
 
1
  import streamlit as st
2
  import os
3
  from dotenv import load_dotenv
4
+ from views.continue_survey import continue_survey_screen
5
+ from db.crud import read
6
 
7
  load_dotenv()
8
  VALIDATION_CODE = os.getenv("VALIDATION_CODE")
 
35
  if (username_input and validation_code_input) or next_button:
36
  if validate_username(username_input) and validate_code(validation_code_input):
37
  st.session_state.username = username_input
 
38
  else:
39
  if not validate_username(username_input):
40
  st.warning("Invalid username. Please check and try again.")
views/nav_buttons.py CHANGED
@@ -5,30 +5,24 @@ from datetime import datetime
5
  import os
6
  from dotenv import load_dotenv
7
 
8
- from views.ui_helpers import display_completion_message, exit_screen
9
-
10
  load_dotenv()
11
  VALIDATION_CODE = os.getenv("VALIDATION_CODE")
12
 
13
 
14
- def submit_feedback(current_index, all_ratings):
15
  """Handles feedback submission to the database."""
16
- if any(rating == 0 for rating in all_ratings):
17
- st.warning("Please provide all ratings before exiting.")
18
- st.session_state.show_exit_screen = True
19
- else:
20
- feedback = Feedback(
21
- id=current_index + 1,
22
- user_id=st.session_state.username,
23
- time_stamp=datetime.now().isoformat(),
24
- responses=st.session_state.responses,
25
- )
26
- try:
27
- save_feedback(feedback)
28
- st.session_state.completed = True
29
- st.session_state.screen = "exit"
30
- except Exception as e:
31
- st.error(f"An error occurred while submitting feedback: {e}")
32
 
33
 
34
  def flatten_ratings(response):
@@ -65,18 +59,13 @@ def navigation_buttons(data, response: Response):
65
  st.warning("Please provide all ratings before proceeding.")
66
  else:
67
  if current_index < len(data) - 1:
68
- st.session_state.previous_ratings[
69
- data.iloc[st.session_state.current_index]['config_id']] = response.model_ratings
70
  st.session_state.current_index += 1
71
  st.rerun()
72
-
73
- if st.button("Finish", disabled=st.session_state.current_index != len(data) - 1):
74
- st.session_state.screen = "exit"
75
- submit_feedback(current_index, all_ratings)
76
 
77
  with col3: # Save & Resume Later button
78
  if st.button("Exit & Resume Later"):
79
- all_ratings = flatten_ratings(response)
80
- submit_feedback(current_index, all_ratings)
81
- st.session_state.screen = "exit"
82
- # st.rerun()
 
5
  import os
6
  from dotenv import load_dotenv
7
 
 
 
8
  load_dotenv()
9
  VALIDATION_CODE = os.getenv("VALIDATION_CODE")
10
 
11
 
12
+ def submit_feedback(current_index):
13
  """Handles feedback submission to the database."""
14
+ feedback = Feedback(
15
+ id=current_index + 1,
16
+ user_id=st.session_state.username,
17
+ time_stamp=datetime.now().isoformat(),
18
+ responses=st.session_state.responses,
19
+ )
20
+ try:
21
+ save_feedback(feedback)
22
+ st.session_state.completed = True
23
+ st.rerun()
24
+ except Exception as e:
25
+ st.error(f"An error occurred while submitting feedback: {e}")
 
 
 
 
26
 
27
 
28
  def flatten_ratings(response):
 
59
  st.warning("Please provide all ratings before proceeding.")
60
  else:
61
  if current_index < len(data) - 1:
62
+ st.session_state.previous_ratings[data.iloc[st.session_state.current_index]['config_id']] = response.model_ratings
 
63
  st.session_state.current_index += 1
64
  st.rerun()
65
+ else:
66
+ if st.button("Finish"):
67
+ submit_feedback(current_index)
 
68
 
69
  with col3: # Save & Resume Later button
70
  if st.button("Exit & Resume Later"):
71
+ submit_feedback(current_index)
 
 
 
views/questions_screen.py CHANGED
@@ -3,10 +3,28 @@ import streamlit as st
3
  from datetime import datetime
4
  from dotenv import load_dotenv
5
  from views.nav_buttons import navigation_buttons
 
6
 
7
  load_dotenv()
8
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def get_previous_ratings(model_name, query_key, current_index):
11
  """Retrieve previous ratings from session state."""
12
  previous_ratings = {}
@@ -27,8 +45,7 @@ def get_previous_ratings(model_name, query_key, current_index):
27
  response_from_session = st.session_state.responses[current_index]
28
  try:
29
  previous_ratings = response_from_session.model_ratings.get(model_name, {})
30
- except (AttributeError, KeyError):
31
- print("Error in getting previous ratings from session state.")
32
  previous_ratings = response_from_session["model_ratings"].get(model_name, {})
33
 
34
  stored_query_ratings = {}
@@ -36,17 +53,17 @@ def get_previous_ratings(model_name, query_key, current_index):
36
  if "query_v" in query_key:
37
  try:
38
  stored_query_ratings = previous_ratings.query_v_ratings
39
- except (AttributeError, KeyError):
40
  stored_query_ratings = previous_ratings["query_v_ratings"]
41
  elif "query_p0" in query_key:
42
  try:
43
  stored_query_ratings = previous_ratings.query_p0_ratings
44
- except (AttributeError, KeyError):
45
  stored_query_ratings = previous_ratings["query_p0_ratings"]
46
  elif "query_p1" in query_key:
47
  try:
48
  stored_query_ratings = previous_ratings.query_p1_ratings
49
- except (AttributeError, KeyError):
50
  stored_query_ratings = previous_ratings["query_p1_ratings"]
51
 
52
  return stored_query_ratings if stored_query_ratings else {}
 
3
  from datetime import datetime
4
  from dotenv import load_dotenv
5
  from views.nav_buttons import navigation_buttons
6
+ import random
7
 
8
  load_dotenv()
9
 
10
 
11
+ def display_completion_message():
12
+ """Display a standardized survey completion message."""
13
+ st.markdown(
14
+ """
15
+ <div class='exit-container'>
16
+ <h1>You have already completed the survey! Thank you for participating!</h1>
17
+ <p>Your responses have been saved successfully.</p>
18
+ <p>You can safely close this window or start a new survey.</p>
19
+ </div>
20
+ """,
21
+ unsafe_allow_html=True,
22
+ )
23
+ st.session_state.show_questions = False
24
+ st.session_state.completed = True
25
+ st.session_state.start_new_survey = True
26
+
27
+
28
  def get_previous_ratings(model_name, query_key, current_index):
29
  """Retrieve previous ratings from session state."""
30
  previous_ratings = {}
 
45
  response_from_session = st.session_state.responses[current_index]
46
  try:
47
  previous_ratings = response_from_session.model_ratings.get(model_name, {})
48
+ except AttributeError:
 
49
  previous_ratings = response_from_session["model_ratings"].get(model_name, {})
50
 
51
  stored_query_ratings = {}
 
53
  if "query_v" in query_key:
54
  try:
55
  stored_query_ratings = previous_ratings.query_v_ratings
56
+ except AttributeError:
57
  stored_query_ratings = previous_ratings["query_v_ratings"]
58
  elif "query_p0" in query_key:
59
  try:
60
  stored_query_ratings = previous_ratings.query_p0_ratings
61
+ except AttributeError:
62
  stored_query_ratings = previous_ratings["query_p0_ratings"]
63
  elif "query_p1" in query_key:
64
  try:
65
  stored_query_ratings = previous_ratings.query_p1_ratings
66
+ except AttributeError:
67
  stored_query_ratings = previous_ratings["query_p1_ratings"]
68
 
69
  return stored_query_ratings if stored_query_ratings else {}
views/ui_helpers.py DELETED
@@ -1,48 +0,0 @@
1
- import streamlit as st
2
-
3
- from views.intro_screen import welcome_screen
4
-
5
-
6
- def exit_screen():
7
- """Display exit screen"""
8
- st.markdown("""
9
- <div class='exit-container'>
10
- <h1>Thank you for participating!</h1>
11
- <p>Your responses have been saved successfully.</p>
12
- <p>You can safely close this window or start a new survey.</p>
13
- </div>
14
- """, unsafe_allow_html=True)
15
- st.session_state.completed = True
16
- st.session_state.show_exit_screen = True
17
- # btn = st.button("Resume Survey")
18
- # if btn:
19
- # reset_survey()
20
- # st.session_state.screen ="welcome"
21
- # st.rerun()
22
-
23
-
24
- def reset_survey():
25
- """Reset the survey state to start over."""
26
- st.session_state.responses = []
27
- st.session_state.completed = True
28
- # st.session_state.start_new_survey = True
29
- st.show_exit_screen = False
30
-
31
-
32
- def display_completion_message():
33
- """Display a standardized survey completion message."""
34
- st.markdown(
35
- """
36
- <div class='exit-container'>
37
- <h1>You have already completed the survey! Thank you for participating!</h1>
38
- <p>Your responses have been saved successfully.</p>
39
- <p>You can safely close this window or start a new survey.</p>
40
- </div>
41
- """,
42
- unsafe_allow_html=True,
43
- )
44
- print("trying to show completion message agian")
45
- st.session_state.show_questions = False
46
- st.session_state.completed = True
47
- st.session_state.start_new_survey = True
48
- st.rerun()