Spaces:
Sleeping
Sleeping
Ashmi Banerjee
commited on
Commit
·
876e6bb
1
Parent(s):
330482c
somewhat works
Browse files- README.md +5 -4
- app.py +1 -28
- css/layout.py +3 -1
- views/questions_screen.py +53 -92
README.md
CHANGED
|
@@ -23,9 +23,10 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
|
|
| 23 |
### TODO List (Human Eval)
|
| 24 |
[x] Check if user_id in database, then resume where they left off
|
| 25 |
[x] Implement save and continue later button
|
| 26 |
-
[
|
| 27 |
[ ] Back button
|
| 28 |
[ ] Dataset linking HF
|
| 29 |
-
[
|
| 30 |
-
[ ] Doing it for two models
|
| 31 |
-
[ ] Add check for ratings should not be 0 for Exit & Resume Later
|
|
|
|
|
|
| 23 |
### TODO List (Human Eval)
|
| 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 |
[ ] Back button
|
| 28 |
[ ] Dataset linking HF
|
| 29 |
+
[x] prettify the context field with new lines and highlighting popularity etc. keywords in bold
|
| 30 |
+
[ ] 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
|
@@ -18,31 +18,6 @@ from css.layout import custom_css
|
|
| 18 |
load_dotenv()
|
| 19 |
VALIDATION_CODE = os.getenv("VALIDATION_CODE")
|
| 20 |
|
| 21 |
-
|
| 22 |
-
# class SurveyState:
|
| 23 |
-
# """Class to handle survey state management"""
|
| 24 |
-
#
|
| 25 |
-
# def __init__(self):
|
| 26 |
-
# pass
|
| 27 |
-
#
|
| 28 |
-
# def save_state(self, username: str, current_state: Dict) -> None:
|
| 29 |
-
# """Save current state to Firebase"""
|
| 30 |
-
# try:
|
| 31 |
-
# """Handles feedback submission to the database."""
|
| 32 |
-
# feedback = Feedback(
|
| 33 |
-
# id=st.session_state.current_index + 1,
|
| 34 |
-
# user_id=st.session_state.username,
|
| 35 |
-
# time_stamp=datetime.now().isoformat(),
|
| 36 |
-
# responses=st.session_state.responses,
|
| 37 |
-
# )
|
| 38 |
-
# save_feedback(feedback)
|
| 39 |
-
# st.success("Your progress has been saved! You can continue later.")
|
| 40 |
-
# st.session_state.completed = True
|
| 41 |
-
# st.rerun()
|
| 42 |
-
# except Exception as e:
|
| 43 |
-
# st.error(f"An error occurred while submitting feedback: {e}")
|
| 44 |
-
#
|
| 45 |
-
|
| 46 |
def initialization():
|
| 47 |
"""Initialize session state variables."""
|
| 48 |
if "current_index" not in st.session_state:
|
|
@@ -59,8 +34,6 @@ def initialization():
|
|
| 59 |
st.session_state.survey_continued = None
|
| 60 |
if "start_new_survey" not in st.session_state:
|
| 61 |
st.session_state.start_new_survey = False
|
| 62 |
-
# if "survey_state" not in st.session_state:
|
| 63 |
-
# st.session_state.survey_state = SurveyState()
|
| 64 |
|
| 65 |
|
| 66 |
def exit_screen():
|
|
@@ -73,7 +46,7 @@ def exit_screen():
|
|
| 73 |
</div>
|
| 74 |
""", unsafe_allow_html=True)
|
| 75 |
|
| 76 |
-
if st.button("
|
| 77 |
reset_survey()
|
| 78 |
st.rerun()
|
| 79 |
|
|
|
|
| 18 |
load_dotenv()
|
| 19 |
VALIDATION_CODE = os.getenv("VALIDATION_CODE")
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def initialization():
|
| 22 |
"""Initialize session state variables."""
|
| 23 |
if "current_index" not in st.session_state:
|
|
|
|
| 34 |
st.session_state.survey_continued = None
|
| 35 |
if "start_new_survey" not in st.session_state:
|
| 36 |
st.session_state.start_new_survey = False
|
|
|
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
def exit_screen():
|
|
|
|
| 46 |
</div>
|
| 47 |
""", unsafe_allow_html=True)
|
| 48 |
|
| 49 |
+
if st.button("Resume Survey"):
|
| 50 |
reset_survey()
|
| 51 |
st.rerun()
|
| 52 |
|
css/layout.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
def custom_css():
|
| 3 |
"""Add custom CSS for layout"""
|
| 4 |
st.markdown("""
|
|
@@ -30,4 +32,4 @@ def custom_css():
|
|
| 30 |
max-width: 600px;
|
| 31 |
}
|
| 32 |
</style>
|
| 33 |
-
""", unsafe_allow_html=True)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
|
| 3 |
+
|
| 4 |
def custom_css():
|
| 5 |
"""Add custom CSS for layout"""
|
| 6 |
st.markdown("""
|
|
|
|
| 32 |
max-width: 600px;
|
| 33 |
}
|
| 34 |
</style>
|
| 35 |
+
""", unsafe_allow_html=True)
|
views/questions_screen.py
CHANGED
|
@@ -24,11 +24,47 @@ def survey_completed():
|
|
| 24 |
st.session_state.show_questions = False
|
| 25 |
st.session_state.completed = True
|
| 26 |
st.session_state.start_new_survey = True
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
def questions_screen(data):
|
| 31 |
-
# TODO: refactor to avoid code duplication
|
| 32 |
"""Display the questions screen with split layout"""
|
| 33 |
current_index = st.session_state.current_index
|
| 34 |
try:
|
|
@@ -42,111 +78,36 @@ def questions_screen(data):
|
|
| 42 |
|
| 43 |
# Context information
|
| 44 |
st.markdown("### Context Information")
|
| 45 |
-
|
| 46 |
with st.expander("Persona", expanded=True):
|
| 47 |
st.write(config['persona'])
|
| 48 |
-
|
| 49 |
with st.expander("Filters & Cities", expanded=True):
|
| 50 |
st.write("**Filters:**", config['filters'])
|
| 51 |
st.write("**Cities:**", config['city'])
|
| 52 |
-
|
| 53 |
with st.expander("Full Context", expanded=False):
|
| 54 |
-
st.
|
| 55 |
-
|
| 56 |
-
# Split layout for questions and ratings
|
| 57 |
-
col11, col12, col13, col14 = st.columns([1, 1, 1, 1]) # Sub-columns for query ratings
|
| 58 |
-
options = [0, 1, 2, 3, 4, 5]
|
| 59 |
-
|
| 60 |
-
# Query_v and its ratings
|
| 61 |
-
st.markdown("### Query_v")
|
| 62 |
-
st.write(config['query_v'])
|
| 63 |
-
col_v_1, col_v_2, col_v_3 = st.columns(3)
|
| 64 |
-
with col_v_1:
|
| 65 |
-
clarity_rating = st.radio("Clarity:", options, key=f"rating_v_clarity_{current_index}")
|
| 66 |
-
|
| 67 |
-
with col_v_2:
|
| 68 |
-
relevance_rating = st.radio("Relevance:", options, key=f"rating_v_relevance_{current_index}")
|
| 69 |
-
|
| 70 |
-
with col_v_3:
|
| 71 |
-
coverage_rating = st.radio("Coverage:", options, key=f"rating_v_coverage_{current_index}")
|
| 72 |
-
|
| 73 |
-
query_v_ratings = {
|
| 74 |
-
"clarity": clarity_rating,
|
| 75 |
-
"relevance": relevance_rating,
|
| 76 |
-
"coverage": coverage_rating,
|
| 77 |
-
}
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
with col_p0_2:
|
| 88 |
-
relevance_rating = st.radio("Relevance:", options, key=f"rating_p0_relevance_{current_index}")
|
| 89 |
-
|
| 90 |
-
with col_p0_3:
|
| 91 |
-
coverage_rating = st.radio("Coverage:", options, key=f"rating_p0_coverage_{current_index}")
|
| 92 |
-
|
| 93 |
-
with col_p0_4:
|
| 94 |
-
persona_alignment_rating = st.radio(
|
| 95 |
-
"Persona Alignment:", options=[0, 1, 2, 3, 4], # These are the values
|
| 96 |
-
format_func=lambda x: ["N/A", "Not Aligned", "Partially Aligned", "Aligned", "Unclear"][x],
|
| 97 |
-
key=f"rating_p0_persona_alignment_{current_index}"
|
| 98 |
-
)
|
| 99 |
-
|
| 100 |
-
# Collecting the ratings for query_p0
|
| 101 |
-
query_p0_ratings = {
|
| 102 |
-
"clarity": clarity_rating,
|
| 103 |
-
"relevance": relevance_rating,
|
| 104 |
-
"coverage": coverage_rating,
|
| 105 |
-
"persona_alignment": persona_alignment_rating
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
# Query_p1 and its ratings
|
| 109 |
-
st.markdown("### Query_p1")
|
| 110 |
-
st.write(config['query_p1'])
|
| 111 |
-
# Split the layout into 4 columns for query_p1 ratings
|
| 112 |
-
col_p1_1, col_p1_2, col_p1_3, col_p1_4 = st.columns(4)
|
| 113 |
-
|
| 114 |
-
with col_p1_1:
|
| 115 |
-
clarity_rating_p1 = st.radio("Clarity:", options, key=f"rating_p1_clarity_{current_index}")
|
| 116 |
-
|
| 117 |
-
with col_p1_2:
|
| 118 |
-
relevance_rating_p1 = st.radio("Relevance:", options, key=f"rating_p1_relevance_{current_index}")
|
| 119 |
-
|
| 120 |
-
with col_p1_3:
|
| 121 |
-
coverage_rating_p1 = st.radio("Coverage:", options, key=f"rating_p1_coverage_{current_index}")
|
| 122 |
-
|
| 123 |
-
with col_p1_4:
|
| 124 |
-
persona_alignment_rating_p1 = st.radio(
|
| 125 |
-
"Persona Alignment:", options=[0, 1, 2, 3, 4], # These are the values
|
| 126 |
-
format_func=lambda x: ["N/A", "Not Aligned", "Partially Aligned", "Aligned", "Unclear"][x],
|
| 127 |
-
key=f"rating_p1_persona_alignment_{current_index}"
|
| 128 |
-
)
|
| 129 |
-
|
| 130 |
-
# Collecting the ratings for query_p1
|
| 131 |
-
query_p1_ratings = {
|
| 132 |
-
"clarity": clarity_rating_p1,
|
| 133 |
-
"relevance": relevance_rating_p1,
|
| 134 |
-
"coverage": coverage_rating_p1,
|
| 135 |
-
"persona_alignment": persona_alignment_rating_p1
|
| 136 |
-
}
|
| 137 |
|
| 138 |
# Additional comments
|
| 139 |
comment = st.text_area("Additional Comments (Optional):")
|
| 140 |
-
|
|
|
|
| 141 |
# Collecting the response data
|
| 142 |
response = Response(
|
| 143 |
config_id=config["config_id"],
|
| 144 |
-
query_v=query_v_ratings,
|
| 145 |
-
query_p0=query_p0_ratings,
|
| 146 |
-
query_p1=query_p1_ratings,
|
| 147 |
comment=comment,
|
| 148 |
timestamp=datetime.now().isoformat()
|
| 149 |
)
|
|
|
|
| 150 |
if len(st.session_state.responses) > current_index:
|
| 151 |
st.session_state.responses[current_index] = response
|
| 152 |
else:
|
|
@@ -156,4 +117,4 @@ def questions_screen(data):
|
|
| 156 |
navigation_buttons(data, query_v_ratings["clarity"], query_p0_ratings["clarity"], query_p1_ratings["clarity"])
|
| 157 |
except IndexError:
|
| 158 |
print("Survey completed!")
|
| 159 |
-
|
|
|
|
| 24 |
st.session_state.show_questions = False
|
| 25 |
st.session_state.completed = True
|
| 26 |
st.session_state.start_new_survey = True
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def render_query_ratings(query_label, config, query_key, current_index, has_persona_alignment=False):
|
| 30 |
+
"""Helper function to render ratings for a given query."""
|
| 31 |
+
st.markdown(f"### {query_label}")
|
| 32 |
+
st.write(config[query_key])
|
| 33 |
+
columns = st.columns(3 if has_persona_alignment else 2)
|
| 34 |
+
columns = st.columns(3)
|
| 35 |
+
options = [0, 1, 2, 3, 4]
|
| 36 |
+
|
| 37 |
+
persona_alignment_rating = None
|
| 38 |
+
if has_persona_alignment:
|
| 39 |
+
with columns[0]:
|
| 40 |
+
persona_alignment_rating = st.radio(
|
| 41 |
+
"Persona Alignment:", options=[0, 1, 2, 3, 4],
|
| 42 |
+
format_func=lambda x: ["N/A", "Not Aligned", "Partially Aligned", "Aligned", "Unclear"][x],
|
| 43 |
+
key=f"rating_{query_key}_persona_alignment_{current_index}"
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
with columns[1]:
|
| 47 |
+
relevance_rating = st.radio("Relevance:",
|
| 48 |
+
options, key=f"rating_{query_key}_relevance_{current_index}",
|
| 49 |
+
format_func=lambda x:
|
| 50 |
+
["N/A", "Not Relevant", "Somewhat Relevant", "Relevant", "Unclear"][x],)
|
| 51 |
+
with columns[2]:
|
| 52 |
+
clarity_rating = st.radio("Clarity:",
|
| 53 |
+
options = [0, 1, 2, 3],
|
| 54 |
+
key=f"rating_{query_key}_clarity_{current_index}",
|
| 55 |
+
format_func=lambda x: ["N/A", "Not Clear", "Somewhat Clear", "Very Clear"][x])
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
return {
|
| 61 |
+
"clarity": clarity_rating,
|
| 62 |
+
"relevance": relevance_rating,
|
| 63 |
+
"persona_alignment": persona_alignment_rating if has_persona_alignment else None
|
| 64 |
+
}
|
| 65 |
|
| 66 |
|
| 67 |
def questions_screen(data):
|
|
|
|
| 68 |
"""Display the questions screen with split layout"""
|
| 69 |
current_index = st.session_state.current_index
|
| 70 |
try:
|
|
|
|
| 78 |
|
| 79 |
# Context information
|
| 80 |
st.markdown("### Context Information")
|
|
|
|
| 81 |
with st.expander("Persona", expanded=True):
|
| 82 |
st.write(config['persona'])
|
|
|
|
| 83 |
with st.expander("Filters & Cities", expanded=True):
|
| 84 |
st.write("**Filters:**", config['filters'])
|
| 85 |
st.write("**Cities:**", config['city'])
|
|
|
|
| 86 |
with st.expander("Full Context", expanded=False):
|
| 87 |
+
st.text_area("", config['context'], height=300, disabled=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
+
# Render queries and collect ratings
|
| 90 |
+
query_v_ratings = render_query_ratings("Query_v", config, "query_v", current_index)
|
| 91 |
+
query_p0_ratings = render_query_ratings("Query_p0",
|
| 92 |
+
config, "query_p0", current_index, has_persona_alignment=True)
|
| 93 |
+
query_p1_ratings = render_query_ratings("Query_p1",
|
| 94 |
+
config, "query_p1",
|
| 95 |
+
current_index, has_persona_alignment=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
# Additional comments
|
| 98 |
comment = st.text_area("Additional Comments (Optional):")
|
| 99 |
+
if "persona_alignment" in query_v_ratings:
|
| 100 |
+
query_v_ratings.pop("persona_alignment")
|
| 101 |
# Collecting the response data
|
| 102 |
response = Response(
|
| 103 |
config_id=config["config_id"],
|
| 104 |
+
query_v=query_v_ratings,
|
| 105 |
+
query_p0=query_p0_ratings,
|
| 106 |
+
query_p1=query_p1_ratings,
|
| 107 |
comment=comment,
|
| 108 |
timestamp=datetime.now().isoformat()
|
| 109 |
)
|
| 110 |
+
|
| 111 |
if len(st.session_state.responses) > current_index:
|
| 112 |
st.session_state.responses[current_index] = response
|
| 113 |
else:
|
|
|
|
| 117 |
navigation_buttons(data, query_v_ratings["clarity"], query_p0_ratings["clarity"], query_p1_ratings["clarity"])
|
| 118 |
except IndexError:
|
| 119 |
print("Survey completed!")
|
| 120 |
+
|