Spaces:
Sleeping
Sleeping
Ashmi Banerjee
commited on
Commit
·
a2b3c97
1
Parent(s):
b7a713a
some more cleanups
Browse files- README.md +4 -2
- views/continue_survey.py +17 -3
- views/nav_buttons.py +1 -9
- views/questions_screen.py +33 -23
README.md
CHANGED
@@ -24,10 +24,12 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
|
|
24 |
[x] Check if user_id in database, then resume where they left off
|
25 |
[x] Implement save and continue later button
|
26 |
[x] Implement questions with proper buttons (with text)
|
27 |
-
[
|
28 |
[ ] Next button + overall state management
|
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
|
|
|
|
|
|
24 |
[x] Check if user_id in database, then resume where they left off
|
25 |
[x] Implement save and continue later button
|
26 |
[x] Implement questions with proper buttons (with text)
|
27 |
+
[x] Back button
|
28 |
[ ] Next button + overall state management
|
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
|
views/continue_survey.py
CHANGED
@@ -7,8 +7,22 @@ def continue_survey_screen(data):
|
|
7 |
"""Screen for existing users to continue or restart their survey."""
|
8 |
st.title("Resume Your Survey")
|
9 |
|
10 |
-
st.
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Fetch user progress from Firebase
|
13 |
saved_state = read(st.session_state.username)
|
14 |
|
@@ -30,7 +44,7 @@ def continue_survey_screen(data):
|
|
30 |
if last_config_id is not None:
|
31 |
matching_index = data[data["config_id"] == last_config_id].index
|
32 |
if not matching_index.empty:
|
33 |
-
st.session_state.current_index = matching_index[0]
|
34 |
|
35 |
st.success("Resuming your survey!")
|
36 |
# Set survey_continued flag to True only when there's saved progress
|
|
|
7 |
"""Screen for existing users to continue or restart their survey."""
|
8 |
st.title("Resume Your Survey")
|
9 |
|
10 |
+
st.markdown(
|
11 |
+
f"""
|
12 |
+
<div style="padding:1rem;">
|
13 |
+
<h3 style="text-align:left;">
|
14 |
+
Welcome back
|
15 |
+
{st.session_state.username.capitalize()}!
|
16 |
+
</h3>
|
17 |
+
<p style="text-align:left;">
|
18 |
+
Would you like to continue from where you left off
|
19 |
+
or restart the survey?
|
20 |
+
<br><b>Note that restarting will delete your previous progress.</b>
|
21 |
+
</p>
|
22 |
+
</div>
|
23 |
+
""",
|
24 |
+
unsafe_allow_html=True,
|
25 |
+
)
|
26 |
# Fetch user progress from Firebase
|
27 |
saved_state = read(st.session_state.username)
|
28 |
|
|
|
44 |
if last_config_id is not None:
|
45 |
matching_index = data[data["config_id"] == last_config_id].index
|
46 |
if not matching_index.empty:
|
47 |
+
st.session_state.current_index = matching_index[0]
|
48 |
|
49 |
st.success("Resuming your survey!")
|
50 |
# Set survey_continued flag to True only when there's saved progress
|
views/nav_buttons.py
CHANGED
@@ -68,12 +68,4 @@ def navigation_buttons(data, response: Response):
|
|
68 |
|
69 |
with col3: # Save & Resume Later button
|
70 |
if st.button("Exit & Resume Later"):
|
71 |
-
|
72 |
-
all_last_ratings = flatten_ratings(last_response)
|
73 |
-
if not any(rating == 0 for rating in all_last_ratings):
|
74 |
-
print("Submitting feedback")
|
75 |
-
submit_feedback(current_index)
|
76 |
-
else:
|
77 |
-
st.warning("Please provide ratings before exiting.")
|
78 |
-
# st.session_state.completed = True
|
79 |
-
# st.rerun()
|
|
|
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,6 +3,7 @@ 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 |
|
@@ -29,7 +30,7 @@ def get_previous_ratings(model_name, query_key, current_index):
|
|
29 |
previous_ratings = {}
|
30 |
|
31 |
if current_index < st.session_state.current_index and len(
|
32 |
-
|
33 |
) > current_index:
|
34 |
if st.session_state.previous_ratings:
|
35 |
previous_ratings = st.session_state.previous_ratings.get(
|
@@ -69,12 +70,12 @@ def get_previous_ratings(model_name, query_key, current_index):
|
|
69 |
|
70 |
|
71 |
def render_single_rating(
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
):
|
79 |
"""Renders a single rating widget (radio)."""
|
80 |
with col:
|
@@ -87,13 +88,21 @@ def render_single_rating(
|
|
87 |
)
|
88 |
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
def render_query_ratings(
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
has_persona_alignment=False,
|
97 |
):
|
98 |
"""Helper function to render ratings for a given query."""
|
99 |
stored_query_ratings = get_previous_ratings(model_name, query_key, current_index)
|
@@ -106,13 +115,16 @@ def render_query_ratings(
|
|
106 |
bg_color = "#e0f7fa"
|
107 |
else:
|
108 |
bg_color = "#f0f4c3"
|
109 |
-
|
110 |
with st.container():
|
111 |
st.markdown(
|
112 |
f"""
|
113 |
-
<div style="background-color:{bg_color}; padding:1rem;">
|
114 |
-
<h3 style="
|
115 |
-
|
|
|
|
|
|
|
116 |
</div>
|
117 |
""",
|
118 |
unsafe_allow_html=True,
|
@@ -161,13 +173,14 @@ def render_query_ratings(
|
|
161 |
|
162 |
|
163 |
def display_ratings_row(model_name, config, current_index):
|
164 |
-
st.markdown(f"## {model_name.capitalize()} Ratings")
|
165 |
|
166 |
cols = st.columns(3)
|
|
|
|
|
167 |
with cols[0]:
|
168 |
query_v_ratings = render_query_ratings(
|
169 |
model_name,
|
170 |
-
"Query_v",
|
171 |
config,
|
172 |
"query_v",
|
173 |
current_index,
|
@@ -176,7 +189,6 @@ def display_ratings_row(model_name, config, current_index):
|
|
176 |
with cols[1]:
|
177 |
query_p0_ratings = render_query_ratings(
|
178 |
model_name,
|
179 |
-
"Query_p0",
|
180 |
config,
|
181 |
"query_p0",
|
182 |
current_index,
|
@@ -185,7 +197,6 @@ def display_ratings_row(model_name, config, current_index):
|
|
185 |
with cols[2]:
|
186 |
query_p1_ratings = render_query_ratings(
|
187 |
model_name,
|
188 |
-
"Query_p1",
|
189 |
config,
|
190 |
"query_p1",
|
191 |
current_index,
|
@@ -211,7 +222,7 @@ def questions_screen(data):
|
|
211 |
progress = (current_index + 1) / len(data)
|
212 |
st.progress(progress)
|
213 |
st.write(f"Question {current_index + 1} of {len(data)}")
|
214 |
-
st.subheader(f"Config ID: {config['config_id']}")
|
215 |
|
216 |
# Context information
|
217 |
st.markdown("### Context Information")
|
@@ -260,4 +271,3 @@ def questions_screen(data):
|
|
260 |
navigation_buttons(data, response)
|
261 |
except IndexError:
|
262 |
print("Survey completed!")
|
263 |
-
|
|
|
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 |
|
|
|
30 |
previous_ratings = {}
|
31 |
|
32 |
if current_index < st.session_state.current_index and len(
|
33 |
+
st.session_state.responses
|
34 |
) > current_index:
|
35 |
if st.session_state.previous_ratings:
|
36 |
previous_ratings = st.session_state.previous_ratings.get(
|
|
|
70 |
|
71 |
|
72 |
def render_single_rating(
|
73 |
+
label,
|
74 |
+
options,
|
75 |
+
format_func,
|
76 |
+
key_prefix,
|
77 |
+
stored_rating,
|
78 |
+
col,
|
79 |
):
|
80 |
"""Renders a single rating widget (radio)."""
|
81 |
with col:
|
|
|
88 |
)
|
89 |
|
90 |
|
91 |
+
def clean_query_text(query_text):
|
92 |
+
"""Clean the query text for display."""
|
93 |
+
if query_text.startswith('"') or query_text.startswith("'") or query_text.endswith('"') or query_text.endswith("'"):
|
94 |
+
query_text = query_text.replace('"', '').replace("'", "")
|
95 |
+
if query_text[-1] not in [".", "?", "!", "\n"]:
|
96 |
+
query_text += "."
|
97 |
+
return query_text.capitalize()
|
98 |
+
|
99 |
+
|
100 |
def render_query_ratings(
|
101 |
+
model_name,
|
102 |
+
config,
|
103 |
+
query_key,
|
104 |
+
current_index,
|
105 |
+
has_persona_alignment=False,
|
|
|
106 |
):
|
107 |
"""Helper function to render ratings for a given query."""
|
108 |
stored_query_ratings = get_previous_ratings(model_name, query_key, current_index)
|
|
|
115 |
bg_color = "#e0f7fa"
|
116 |
else:
|
117 |
bg_color = "#f0f4c3"
|
118 |
+
query_text = clean_query_text(config[model_name + "_" + query_key])
|
119 |
with st.container():
|
120 |
st.markdown(
|
121 |
f"""
|
122 |
+
<div style="background-color:{bg_color}; padding:1rem;">
|
123 |
+
<h3 style="text-align:left;">
|
124 |
+
{config.index.get_loc(model_name + "_" + query_key) - 5}
|
125 |
+
</h3>
|
126 |
+
<p style="text-align:left;">
|
127 |
+
{query_text}</p>
|
128 |
</div>
|
129 |
""",
|
130 |
unsafe_allow_html=True,
|
|
|
173 |
|
174 |
|
175 |
def display_ratings_row(model_name, config, current_index):
|
176 |
+
# st.markdown(f"## {model_name.capitalize()} Ratings")
|
177 |
|
178 |
cols = st.columns(3)
|
179 |
+
# combinations = ["query_v", "query_p0", "query_p1"]
|
180 |
+
# random.shuffle(combinations)
|
181 |
with cols[0]:
|
182 |
query_v_ratings = render_query_ratings(
|
183 |
model_name,
|
|
|
184 |
config,
|
185 |
"query_v",
|
186 |
current_index,
|
|
|
189 |
with cols[1]:
|
190 |
query_p0_ratings = render_query_ratings(
|
191 |
model_name,
|
|
|
192 |
config,
|
193 |
"query_p0",
|
194 |
current_index,
|
|
|
197 |
with cols[2]:
|
198 |
query_p1_ratings = render_query_ratings(
|
199 |
model_name,
|
|
|
200 |
config,
|
201 |
"query_p1",
|
202 |
current_index,
|
|
|
222 |
progress = (current_index + 1) / len(data)
|
223 |
st.progress(progress)
|
224 |
st.write(f"Question {current_index + 1} of {len(data)}")
|
225 |
+
# st.subheader(f"Config ID: {config['config_id']}")
|
226 |
|
227 |
# Context information
|
228 |
st.markdown("### Context Information")
|
|
|
271 |
navigation_buttons(data, response)
|
272 |
except IndexError:
|
273 |
print("Survey completed!")
|
|