Ashmi Banerjee commited on
Commit
0960577
·
1 Parent(s): 29cc4c5

css fixed but buttons broken

Browse files
app.py CHANGED
@@ -7,7 +7,7 @@ from views.intro_screen import welcome_screen
7
  from views.questions_screen import questions_screen, survey_completed
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()
 
7
  from views.questions_screen import questions_screen, survey_completed
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()
css/layout.py CHANGED
@@ -32,4 +32,4 @@ def custom_css():
32
  max-width: 600px;
33
  }
34
  </style>
35
- """, unsafe_allow_html=True)
 
32
  max-width: 600px;
33
  }
34
  </style>
35
+ """, unsafe_allow_html=True)
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- streamlit==1.37.1
2
  pandas
3
  python-dotenv
4
  firebase-admin
5
- pydantic
 
1
+ streamlit
2
  pandas
3
  python-dotenv
4
  firebase-admin
5
+ pydantic
views/intro_screen.py CHANGED
@@ -19,18 +19,20 @@ def validate_code(input_code: str) -> bool:
19
 
20
  def welcome_screen():
21
  """Display the welcome screen and direct users accordingly."""
22
- st.title("Welcome to the Feedback Survey")
23
-
24
- username_input = st.text_input("Enter your First name and press TAB:")
25
- validation_code_input = st.text_input("Enter the validation code to proceed and press ENTER:")
26
-
27
- next_button = st.button("Next")
28
-
29
- if (username_input and validation_code_input) or next_button:
30
- if validate_username(username_input) and validate_code(validation_code_input):
31
- st.session_state.username = username_input
32
- else:
33
- if not validate_username(username_input):
34
- st.warning("Invalid Prolific ID. Please check and try again.")
35
- if not validate_code(validation_code_input):
36
- st.warning("Invalid validation code. Please check and try again.")
 
 
 
19
 
20
  def welcome_screen():
21
  """Display the welcome screen and direct users accordingly."""
22
+ with st.container():
23
+ st.markdown("""<style> .st-emotion-cache-1jicfl2 {width: 50%;} </style>""", unsafe_allow_html=True)
24
+ st.title("Welcome to the Feedback Survey")
25
+
26
+ username_input = st.text_input("Enter your First name and press TAB:")
27
+ validation_code_input = st.text_input("Enter the validation code to proceed and press ENTER:")
28
+
29
+ next_button = st.button("Next")
30
+
31
+ if (username_input and validation_code_input) or next_button:
32
+ if validate_username(username_input) and validate_code(validation_code_input):
33
+ st.session_state.username = username_input
34
+ else:
35
+ if not validate_username(username_input):
36
+ st.warning("Invalid username. Please check and try again.")
37
+ if not validate_code(validation_code_input):
38
+ st.warning("Invalid validation code. Please check and try again.")
views/nav_buttons.py CHANGED
@@ -25,16 +25,18 @@ def submit_feedback(current_index):
25
  st.error(f"An error occurred while submitting feedback: {e}")
26
 
27
 
28
- def any_value_zero(response):
29
- return any(
30
- any(value == 0 for value in query.values())
31
- for query in [response.query_v, response.query_p0, response.query_p1]
32
- )
 
 
33
 
34
 
35
  def navigation_buttons(data, response: Response):
36
  """Display navigation buttons."""
37
- #TODO change the function to accept the response object
38
  current_index = st.session_state.current_index
39
 
40
  col1, col2, col3 = st.columns([1, 1, 2])
@@ -45,13 +47,8 @@ def navigation_buttons(data, response: Response):
45
  st.rerun()
46
 
47
  with col2: # Next button
48
- all_ratings = []
49
- for model_ratings in response.model_ratings.values():
50
- all_ratings.extend(model_ratings.query_v_ratings.values())
51
- all_ratings.extend(model_ratings.query_p0_ratings.values())
52
- all_ratings.extend(model_ratings.query_p1_ratings.values())
53
-
54
  if st.button("Next"):
 
55
  if any(rating == 0 for rating in all_ratings):
56
  st.warning("Please provide a rating before proceeding.")
57
  else:
@@ -64,9 +61,9 @@ def navigation_buttons(data, response: Response):
64
  with col3: # Save & Resume Later button
65
  if st.button("Exit & Resume Later"):
66
  last_response = st.session_state.responses[-1]
67
- if not any_value_zero(last_response):
 
68
  submit_feedback(current_index)
69
  else:
70
  st.session_state.completed = True
71
  st.rerun()
72
- # submit_feedback(current_index)
 
25
  st.error(f"An error occurred while submitting feedback: {e}")
26
 
27
 
28
+ def flatten_ratings(response):
29
+ all_ratings = []
30
+ for model_ratings in response.model_ratings.values():
31
+ all_ratings.extend(model_ratings.query_v_ratings.values())
32
+ all_ratings.extend(model_ratings.query_p0_ratings.values())
33
+ all_ratings.extend(model_ratings.query_p1_ratings.values())
34
+ return all_ratings
35
 
36
 
37
  def navigation_buttons(data, response: Response):
38
  """Display navigation buttons."""
39
+
40
  current_index = st.session_state.current_index
41
 
42
  col1, col2, col3 = st.columns([1, 1, 2])
 
47
  st.rerun()
48
 
49
  with col2: # Next button
 
 
 
 
 
 
50
  if st.button("Next"):
51
+ all_ratings = flatten_ratings(response)
52
  if any(rating == 0 for rating in all_ratings):
53
  st.warning("Please provide a rating before proceeding.")
54
  else:
 
61
  with col3: # Save & Resume Later button
62
  if st.button("Exit & Resume Later"):
63
  last_response = st.session_state.responses[-1]
64
+ all_last_ratings = flatten_ratings(last_response)
65
+ if not any(rating == 0 for rating in all_last_ratings):
66
  submit_feedback(current_index)
67
  else:
68
  st.session_state.completed = True
69
  st.rerun()
 
views/questions_screen.py CHANGED
@@ -1,11 +1,9 @@
1
  from db.schema import Response, ModelRatings
2
  import streamlit as st
3
  from datetime import datetime
4
- import os
5
  from dotenv import load_dotenv
6
  from views.nav_buttons import navigation_buttons
7
 
8
- st.set_page_config(layout="wide")
9
  load_dotenv()
10
 
11
 
@@ -23,34 +21,67 @@ def survey_completed():
23
  st.session_state.start_new_survey = True
24
 
25
 
26
- def render_query_ratings(query_label, config, query_key, current_index, has_persona_alignment=False):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  """Helper function to render ratings for a given query."""
28
- st.markdown(f"### {query_label}")
29
- st.write(config[query_key])
30
- # columns = st.columns(3 if has_persona_alignment else 2)
31
- columns = st.columns(3)
32
- options = [0, 1, 2, 3, 4]
33
-
34
- persona_alignment_rating = None
35
- if has_persona_alignment:
36
- with columns[0]:
37
- persona_alignment_rating = st.radio(
38
- "Persona Alignment:", options=[0, 1, 2, 3, 4],
39
- format_func=lambda x: ["N/A", "Not Aligned", "Partially Aligned", "Aligned", "Unclear"][x],
40
- key=f"rating_{query_key}_persona_alignment_{current_index}"
41
- )
42
-
43
- with columns[1]:
44
- relevance_rating = st.radio("Relevance:",
45
- options, key=f"rating_{query_key}_relevance_{current_index}",
46
- format_func=lambda x:
47
- ["N/A", "Not Relevant", "Somewhat Relevant", "Relevant", "Unclear"][x], )
48
- with columns[2]:
49
- clarity_rating = st.radio("Clarity:",
50
- options=[0, 1, 2, 3],
51
- key=f"rating_{query_key}_clarity_{current_index}",
52
- format_func=lambda x: ["N/A", "Not Clear", "Somewhat Clear", "Very Clear"][x])
53
 
 
 
 
 
 
 
 
 
 
 
 
54
  return {
55
  "clarity": clarity_rating,
56
  "relevance": relevance_rating,
@@ -80,39 +111,25 @@ def questions_screen(data):
80
  with st.expander("Full Context", expanded=False):
81
  st.text_area("", config['context'], height=300, disabled=False)
82
 
83
- # Render queries and collect ratings
84
- g_query_v_ratings = render_query_ratings("Query_v", config, "gemini_query_v", current_index)
85
- g_query_p0_ratings = render_query_ratings("Query_p0",
86
- config, "gemini_query_p0", current_index, has_persona_alignment=True)
87
- g_query_p1_ratings = render_query_ratings("Query_p1",
88
- config, "gemini_query_p1",
89
- current_index, has_persona_alignment=True)
90
-
91
- l_query_v_ratings = render_query_ratings("Query_v", config, "llama_query_v", current_index)
92
- l_query_p0_ratings = render_query_ratings("Query_p0",
93
- config, "llama_query_p0", current_index, has_persona_alignment=True)
94
- l_query_p1_ratings = render_query_ratings("Query_p1",
95
- config, "llama_query_p1",
96
- current_index, has_persona_alignment=True)
97
 
98
  # Additional comments
99
  comment = st.text_area("Additional Comments (Optional):")
100
- if "persona_alignment" in g_query_v_ratings or "persona_alignment" in l_query_v_ratings:
101
- g_query_v_ratings.pop("persona_alignment")
102
- l_query_v_ratings.pop("persona_alignment")
103
  # Collecting the response data
104
  response = Response(
105
  config_id=config["config_id"],
106
  model_ratings={
107
  "gemini": ModelRatings(
108
- query_v_ratings=g_query_v_ratings,
109
- query_p0_ratings=g_query_p0_ratings,
110
- query_p1_ratings=g_query_p1_ratings,
111
  ),
112
  "llama": ModelRatings(
113
- query_v_ratings=l_query_v_ratings,
114
- query_p0_ratings=l_query_p0_ratings,
115
- query_p1_ratings=l_query_p1_ratings,
116
  )
117
  },
118
  comment=comment,
 
1
  from db.schema import Response, ModelRatings
2
  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
 
 
21
  st.session_state.start_new_survey = True
22
 
23
 
24
+ def display_ratings_row(model_name, config, current_index):
25
+ st.markdown(f"## {model_name.capitalize()} Ratings")
26
+
27
+ cols = st.columns(3)
28
+ with cols[0]:
29
+ query_v_ratings = render_query_ratings(model_name, "Query_v",
30
+ config, f"{model_name}_query_v", current_index,
31
+ has_persona_alignment=False)
32
+ with cols[1]:
33
+ query_p0_ratings = render_query_ratings(model_name, "Query_p0",
34
+ config, f"{model_name}_query_p0", current_index,
35
+ has_persona_alignment=True)
36
+ with cols[2]:
37
+ query_p1_ratings = render_query_ratings(model_name, "Query_p1",
38
+ config, f"{model_name}_query_p1",
39
+ current_index, has_persona_alignment=True)
40
+ if "persona_alignment" in query_v_ratings:
41
+ query_v_ratings.pop("persona_alignment")
42
+ return {
43
+ "query_v_ratings": query_v_ratings,
44
+ "query_p0_ratings": query_p0_ratings,
45
+ "query_p1_ratings": query_p1_ratings,
46
+ }
47
+
48
+
49
+ def render_query_ratings(model_name, query_label, config, query_key, current_index, has_persona_alignment=False):
50
  """Helper function to render ratings for a given query."""
51
+ if model_name == "gemini":
52
+ bg_color = "#e0f7fa"
53
+ else:
54
+ bg_color = "#f0f4c3"
55
+ with st.container():
56
+ st.markdown(f"""
57
+ <div style="background-color:{bg_color}; padding:1rem;">
58
+ <h3 style="color:blue;"> {query_label} </h3>
59
+ <p style="text-align:left;">{config[query_key]}</p>
60
+ </div>
61
+ """, unsafe_allow_html=True)
62
+ columns = st.columns(3)
63
+ options = [0, 1, 2, 3, 4]
64
+
65
+ persona_alignment_rating = None
66
+ if has_persona_alignment:
67
+ with columns[0]:
68
+ persona_alignment_rating = st.radio(
69
+ "Persona Alignment:", options=[0, 1, 2, 3, 4],
70
+ format_func=lambda x: ["N/A", "Not Aligned", "Partially Aligned", "Aligned", "Unclear"][x],
71
+ key=f"rating_{query_key}_persona_alignment_{current_index}",
72
+ )
 
 
 
73
 
74
+ with columns[1]:
75
+ relevance_rating = st.radio("Relevance:",
76
+ options, key=f"rating_{query_key}_relevance_{current_index}",
77
+ format_func=lambda x:
78
+ ["N/A", "Not Relevant", "Somewhat Relevant", "Relevant", "Unclear"][x], )
79
+ with columns[2]:
80
+ clarity_rating = st.radio("Clarity:",
81
+ options=[0, 1, 2, 3],
82
+ key=f"rating_{query_key}_clarity_{current_index}",
83
+ format_func=lambda x: ["N/A", "Not Clear", "Somewhat Clear", "Very Clear"][x],
84
+ )
85
  return {
86
  "clarity": clarity_rating,
87
  "relevance": relevance_rating,
 
111
  with st.expander("Full Context", expanded=False):
112
  st.text_area("", config['context'], height=300, disabled=False)
113
 
114
+ g_ratings = display_ratings_row("gemini", config, current_index)
115
+ l_ratings = display_ratings_row("llama", config, current_index)
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  # Additional comments
118
  comment = st.text_area("Additional Comments (Optional):")
119
+
 
 
120
  # Collecting the response data
121
  response = Response(
122
  config_id=config["config_id"],
123
  model_ratings={
124
  "gemini": ModelRatings(
125
+ query_v_ratings=g_ratings["query_v_ratings"],
126
+ query_p0_ratings=g_ratings["query_p0_ratings"],
127
+ query_p1_ratings=g_ratings["query_p1_ratings"],
128
  ),
129
  "llama": ModelRatings(
130
+ query_v_ratings=l_ratings["query_v_ratings"],
131
+ query_p0_ratings=l_ratings["query_p0_ratings"],
132
+ query_p1_ratings=l_ratings["query_p1_ratings"],
133
  )
134
  },
135
  comment=comment,