Spaces:
Sleeping
Sleeping
Ashmi Banerjee
commited on
Commit
·
4f7c053
1
Parent(s):
0960577
back button somewhat works
Browse files- README.md +2 -2
- app.py +6 -0
- views/continue_survey.py +0 -1
- views/nav_buttons.py +17 -7
- views/questions_screen.py +36 -11
README.md
CHANGED
@@ -25,8 +25,8 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
|
|
25 |
[x] Implement save and continue later button
|
26 |
[x] Implement questions with proper buttons (with text)
|
27 |
[ ] Back button
|
28 |
-
[
|
29 |
[x] prettify the context field with new lines and highlighting popularity etc. keywords in bold
|
30 |
-
[
|
31 |
[ ] Add check for ratings should not be 0 for Exit & Resume Later
|
32 |
[ ] Check the firebase DB rules
|
|
|
25 |
[x] Implement save and continue later button
|
26 |
[x] Implement questions with proper buttons (with text)
|
27 |
[ ] Back button
|
28 |
+
[x] Dataset linking HF
|
29 |
[x] prettify the context field with new lines and highlighting popularity etc. keywords in bold
|
30 |
+
[x] Doing it for two models - combine datasets
|
31 |
[ ] Add check for ratings should not be 0 for Exit & Resume Later
|
32 |
[ ] Check the firebase DB rules
|
app.py
CHANGED
@@ -30,6 +30,12 @@ def initialization():
|
|
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 |
|
34 |
|
35 |
def exit_screen():
|
|
|
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_gemini_ratings' not in st.session_state:
|
36 |
+
st.session_state.previous_gemini_ratings = {}
|
37 |
+
if 'previous_llama_ratings' not in st.session_state:
|
38 |
+
st.session_state.previous_llama_ratings = {}
|
39 |
|
40 |
|
41 |
def exit_screen():
|
views/continue_survey.py
CHANGED
@@ -35,7 +35,6 @@ def continue_survey_screen(data):
|
|
35 |
st.success("Resuming your survey!")
|
36 |
# Set survey_continued flag to True only when there's saved progress
|
37 |
st.session_state.survey_continued = True
|
38 |
-
print(st.session_state.current_index)
|
39 |
st.rerun()
|
40 |
# questions_screen(data)
|
41 |
|
|
|
35 |
st.success("Resuming your survey!")
|
36 |
# Set survey_continued flag to True only when there's saved progress
|
37 |
st.session_state.survey_continued = True
|
|
|
38 |
st.rerun()
|
39 |
# questions_screen(data)
|
40 |
|
views/nav_buttons.py
CHANGED
@@ -41,16 +41,24 @@ def navigation_buttons(data, response: Response):
|
|
41 |
|
42 |
col1, col2, col3 = st.columns([1, 1, 2])
|
43 |
|
44 |
-
with col1: # Back button #TODO fix
|
45 |
-
if st.button("Back")
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
54 |
else:
|
55 |
if current_index < len(data) - 1:
|
56 |
st.session_state.current_index += 1
|
@@ -63,7 +71,9 @@ def navigation_buttons(data, response: Response):
|
|
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.
|
69 |
-
st.
|
|
|
|
41 |
|
42 |
col1, col2, col3 = st.columns([1, 1, 2])
|
43 |
|
44 |
+
with col1: # Back button #TODO fix: only gets ratings for the session, not from previous session
|
45 |
+
if st.button("Back"):
|
46 |
+
if current_index > 0:
|
47 |
+
st.session_state.current_index -= 1
|
48 |
+
previous_ratings = st.session_state.ratings.get(st.session_state.current_index, {})
|
49 |
+
st.session_state.previous_ratings = previous_ratings
|
50 |
+
# st.session_state.previous_gemini_ratings = previous_ratings.get("gemini", {})
|
51 |
+
# st.session_state.previous_llama_ratings = previous_ratings.get("llama", {})
|
52 |
+
st.rerun()
|
53 |
+
else:
|
54 |
+
st.warning("You are at the beginning of the survey, can't go back.")
|
55 |
+
# st.rerun()
|
56 |
|
57 |
with col2: # Next button
|
58 |
if st.button("Next"):
|
59 |
all_ratings = flatten_ratings(response)
|
60 |
if any(rating == 0 for rating in all_ratings):
|
61 |
+
st.warning("Please provide all ratings before proceeding.")
|
62 |
else:
|
63 |
if current_index < len(data) - 1:
|
64 |
st.session_state.current_index += 1
|
|
|
71 |
last_response = st.session_state.responses[-1]
|
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()
|
views/questions_screen.py
CHANGED
@@ -48,6 +48,25 @@ def display_ratings_row(model_name, config, current_index):
|
|
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:
|
@@ -69,19 +88,25 @@ def render_query_ratings(model_name, query_label, config, query_key, current_ind
|
|
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(
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
79 |
with columns[2]:
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
85 |
return {
|
86 |
"clarity": clarity_rating,
|
87 |
"relevance": relevance_rating,
|
@@ -135,7 +160,7 @@ def questions_screen(data):
|
|
135 |
comment=comment,
|
136 |
timestamp=datetime.now().isoformat()
|
137 |
)
|
138 |
-
|
139 |
if len(st.session_state.responses) > current_index:
|
140 |
st.session_state.responses[current_index] = response
|
141 |
else:
|
|
|
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 |
+
# Get stored ratings if they exist
|
52 |
+
previous_ratings = st.session_state.get("previous_ratings", {}).get(model_name, {})
|
53 |
+
stored_query_ratings = {}
|
54 |
+
if previous_ratings:
|
55 |
+
if "query_v" in query_key:
|
56 |
+
stored_query_ratings = previous_ratings.query_v_ratings
|
57 |
+
elif "query_p0" in query_key:
|
58 |
+
stored_query_ratings = previous_ratings.query_p0_ratings
|
59 |
+
elif "query_p1" in query_key:
|
60 |
+
stored_query_ratings = previous_ratings.query_p1_ratings
|
61 |
+
else:
|
62 |
+
stored_query_ratings = {}
|
63 |
+
# Extract individual stored values, or default to None
|
64 |
+
# stored_query_ratings = previous_ratings.get(f"query_{query_key}_ratings", {})
|
65 |
+
|
66 |
+
stored_relevance = stored_query_ratings.get("relevance", 0)
|
67 |
+
stored_clarity = stored_query_ratings.get("clarity", 0)
|
68 |
+
stored_persona_alignment = stored_query_ratings.get("persona_alignment", 0) if has_persona_alignment else None
|
69 |
+
|
70 |
if model_name == "gemini":
|
71 |
bg_color = "#e0f7fa"
|
72 |
else:
|
|
|
88 |
"Persona Alignment:", options=[0, 1, 2, 3, 4],
|
89 |
format_func=lambda x: ["N/A", "Not Aligned", "Partially Aligned", "Aligned", "Unclear"][x],
|
90 |
key=f"rating_{query_key}_persona_alignment_{current_index}",
|
91 |
+
index=stored_persona_alignment if stored_persona_alignment is not None else 0
|
92 |
)
|
|
|
93 |
with columns[1]:
|
94 |
+
relevance_rating = st.radio(
|
95 |
+
"Relevance:",
|
96 |
+
options,
|
97 |
+
key=f"rating_{query_key}_relevance_{current_index}",
|
98 |
+
format_func=lambda x: ["N/A", "Not Relevant", "Somewhat Relevant", "Relevant", "Unclear"][x],
|
99 |
+
index=stored_relevance if stored_relevance is not None else 0
|
100 |
+
)
|
101 |
with columns[2]:
|
102 |
+
with columns[2]:
|
103 |
+
clarity_rating = st.radio(
|
104 |
+
"Clarity:",
|
105 |
+
options=[0, 1, 2, 3],
|
106 |
+
key=f"rating_{query_key}_clarity_{current_index}",
|
107 |
+
format_func=lambda x: ["N/A", "Not Clear", "Somewhat Clear", "Very Clear"][x],
|
108 |
+
index=stored_clarity if stored_clarity is not None else 0
|
109 |
+
)
|
110 |
return {
|
111 |
"clarity": clarity_rating,
|
112 |
"relevance": relevance_rating,
|
|
|
160 |
comment=comment,
|
161 |
timestamp=datetime.now().isoformat()
|
162 |
)
|
163 |
+
st.session_state.ratings[current_index] = response.model_ratings
|
164 |
if len(st.session_state.responses) > current_index:
|
165 |
st.session_state.responses[current_index] = response
|
166 |
else:
|