Spaces:
Runtime error
Runtime error
Update app.py
Browse files- removed q9 from phq (suicidality)
- increased scenario loop to 16
- added attention checks after vignette 5 & 12
app.py
CHANGED
|
@@ -38,7 +38,7 @@ if not os.path.exists(excel_file):
|
|
| 38 |
'Initial Relevance Rating', 'Final Relevance Rating', 'Emotional Relevance',
|
| 39 |
'Positive Valence', 'Negative Valence', 'Likelihood of Change', "Ease of Use",
|
| 40 |
"Clarity of Instructions", "Engagement Level", "Satisfaction with Assessment",
|
| 41 |
-
"Cognitive Load", "Additional Comments", 'PHQ-9 Score', 'GAD-7 Score'
|
| 42 |
]).to_excel(excel_file, index=False, engine="openpyxl")
|
| 43 |
|
| 44 |
|
|
@@ -52,7 +52,7 @@ if not os.path.exists(pickle_file):
|
|
| 52 |
'Initial Relevance Rating', 'Final Relevance Rating', 'Emotional Relevance',
|
| 53 |
'Positive Valence', 'Negative Valence', 'Likelihood of Change', "Ease of Use",
|
| 54 |
"Clarity of Instructions", "Engagement Level", "Satisfaction with Assessment",
|
| 55 |
-
"Cognitive Load", "Additional Comments", 'PHQ-9 Score', 'GAD-7 Score'
|
| 56 |
]).to_pickle(pickle_file)
|
| 57 |
|
| 58 |
##############################################################################
|
|
@@ -65,6 +65,8 @@ def get_default_app_state():
|
|
| 65 |
"phq_score": 0,
|
| 66 |
"gad_score": 0,
|
| 67 |
"eligible": False,
|
|
|
|
|
|
|
| 68 |
"standardized_data": {
|
| 69 |
"Prolific ID": None,
|
| 70 |
"Raw Age": None,
|
|
@@ -484,7 +486,9 @@ def new_chat_input(chat_history, user_state, user_input, *args, **kwargs):
|
|
| 484 |
"Cognitive Load": user_state["standardized_data"].get("Cognitive Load", None),
|
| 485 |
"Additional Comments": user_state["standardized_data"].get("Additional Comments", None),
|
| 486 |
'PHQ-9 Score': user_state["phq_score"],
|
| 487 |
-
'GAD-7 Score': user_state["gad_score"]
|
|
|
|
|
|
|
| 488 |
}, user_state)
|
| 489 |
finalize_and_save_to_space(user_state)
|
| 490 |
|
|
@@ -586,7 +590,9 @@ def new_chat_input(chat_history, user_state, user_input, *args, **kwargs):
|
|
| 586 |
"Cognitive Load": user_state["standardized_data"].get("Cognitive Load", None),
|
| 587 |
"Additional Comments": user_state["standardized_data"].get("Additional Comments", None),
|
| 588 |
'PHQ-9 Score': user_state["phq_score"],
|
| 589 |
-
'GAD-7 Score': user_state["gad_score"]
|
|
|
|
|
|
|
| 590 |
}, user_state)
|
| 591 |
finalize_and_save_to_space(user_state)
|
| 592 |
|
|
@@ -1142,10 +1148,10 @@ def slider_input(chat_history, user_state, attribution_slider, *args, **kwargs):
|
|
| 1142 |
gr.update(visible=False), # Hide the textbox
|
| 1143 |
gr.update(visible=True, value=1), # Show the slider
|
| 1144 |
gr.update(visible=True) # Show the Confirm button
|
| 1145 |
-
|
| 1146 |
-
|
| 1147 |
elif user_state["stage"] == "internal_external_reassessment":
|
| 1148 |
-
#
|
| 1149 |
user_state["standardized_data"]['Raw Reassessment'] = attribution_slider
|
| 1150 |
user_state["assessment_internal_external_response"] = '1' if attribution_slider <= 5 else '2'
|
| 1151 |
if user_state["assessment_internal_external_response"] == '1':
|
|
@@ -1154,11 +1160,45 @@ def slider_input(chat_history, user_state, attribution_slider, *args, **kwargs):
|
|
| 1154 |
else:
|
| 1155 |
user_state["standardized_data"]['Reassessment Internal'] = 0
|
| 1156 |
user_state["standardized_data"]['Reassessment External'] = 1
|
| 1157 |
-
|
| 1158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1159 |
|
| 1160 |
# If all vignettes are complete, transition to usability feedback
|
| 1161 |
-
if user_state["vignette_counter"] >
|
| 1162 |
print("All vignettes completed. Moving to usability feedback.")
|
| 1163 |
# save_to_pickle(user_state["standardized_data"])
|
| 1164 |
save_partial_data_to_excel({
|
|
@@ -1197,7 +1237,9 @@ def slider_input(chat_history, user_state, attribution_slider, *args, **kwargs):
|
|
| 1197 |
"Cognitive Load": user_state["standardized_data"].get("Cognitive Load", None),
|
| 1198 |
"Additional Comments": user_state["standardized_data"].get("Additional Comments", None),
|
| 1199 |
'PHQ-9 Score': user_state["phq_score"],
|
| 1200 |
-
'GAD-7 Score': user_state["gad_score"]
|
|
|
|
|
|
|
| 1201 |
}, user_state)
|
| 1202 |
user_state["stage"] = "usability_feedback"
|
| 1203 |
user_state["usability_question_counter"] = 0
|
|
@@ -1251,7 +1293,9 @@ def slider_input(chat_history, user_state, attribution_slider, *args, **kwargs):
|
|
| 1251 |
"Cognitive Load": user_state["standardized_data"].get("Cognitive Load", None),
|
| 1252 |
"Additional Comments": user_state["standardized_data"].get("Additional Comments", None),
|
| 1253 |
'PHQ-9 Score': user_state["phq_score"],
|
| 1254 |
-
'GAD-7 Score': user_state["gad_score"]
|
|
|
|
|
|
|
| 1255 |
}, user_state)
|
| 1256 |
response = f"Thank you! We are now finished with scene {user_state['vignette_counter'] - 1}. In total you will be seeing 2 scenes.\n\nWhat would you like for your next round?\n1. A situation related to your profession.\n2. A situation related to your personal interests.\n3. Something else about me. (Add another activity or interest that is important to you by saying 'I also like...')"
|
| 1257 |
chat_history[-1] = (str(attribution_slider), response)
|
|
@@ -1382,7 +1426,7 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
|
|
| 1382 |
q6 = gr.Radio(choices=["0", "1", "2", "3"], label="Feeling bad about yourself?", value = "0")
|
| 1383 |
q7 = gr.Radio(choices=["0", "1", "2", "3"], label="Trouble concentrating?", value = "0")
|
| 1384 |
q8 = gr.Radio(choices=["0", "1", "2", "3"], label="Moving or speaking so slowly people noticed?", value = "0")
|
| 1385 |
-
q9 = gr.Radio(choices=["0", "1", "2", "3"], label="Thoughts that you would be better off dead?", value = "0")
|
| 1386 |
phq_result = gr.Markdown()
|
| 1387 |
next_button = gr.Button("Next")
|
| 1388 |
|
|
@@ -1503,7 +1547,7 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
|
|
| 1503 |
)
|
| 1504 |
|
| 1505 |
# 2) After finishing PHQ-9, go to GAD-7
|
| 1506 |
-
def process_phq9_and_show_gad7(q1, q2, q3, q4, q5, q6, q7, q8,
|
| 1507 |
q1 = int(q1) if q1 is not None else 0
|
| 1508 |
q2 = int(q2) if q2 is not None else 0
|
| 1509 |
q3 = int(q3) if q3 is not None else 0
|
|
@@ -1512,10 +1556,10 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
|
|
| 1512 |
q6 = int(q6) if q6 is not None else 0
|
| 1513 |
q7 = int(q7) if q7 is not None else 0
|
| 1514 |
q8 = int(q8) if q8 is not None else 0
|
| 1515 |
-
|
| 1516 |
|
| 1517 |
# Store ID & compute PHQ-9
|
| 1518 |
-
user_state["phq_score"] = q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8
|
| 1519 |
|
| 1520 |
# On success, hide Page 2 & show Page 3
|
| 1521 |
return (
|
|
@@ -1527,7 +1571,7 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
|
|
| 1527 |
|
| 1528 |
next_button.click(
|
| 1529 |
fn=process_phq9_and_show_gad7,
|
| 1530 |
-
inputs=[q1, q2, q3, q4, q5, q6, q7, q8,
|
| 1531 |
outputs=[
|
| 1532 |
phq_result,
|
| 1533 |
page_2, # hide page_2 (PHQ-9)
|
|
|
|
| 38 |
'Initial Relevance Rating', 'Final Relevance Rating', 'Emotional Relevance',
|
| 39 |
'Positive Valence', 'Negative Valence', 'Likelihood of Change', "Ease of Use",
|
| 40 |
"Clarity of Instructions", "Engagement Level", "Satisfaction with Assessment",
|
| 41 |
+
"Cognitive Load", "Additional Comments", 'PHQ-9 Score', 'GAD-7 Score', "Attention Check 1", "Attention Check 2"
|
| 42 |
]).to_excel(excel_file, index=False, engine="openpyxl")
|
| 43 |
|
| 44 |
|
|
|
|
| 52 |
'Initial Relevance Rating', 'Final Relevance Rating', 'Emotional Relevance',
|
| 53 |
'Positive Valence', 'Negative Valence', 'Likelihood of Change', "Ease of Use",
|
| 54 |
"Clarity of Instructions", "Engagement Level", "Satisfaction with Assessment",
|
| 55 |
+
"Cognitive Load", "Additional Comments", 'PHQ-9 Score', 'GAD-7 Score', "Attention Check 1", "Attention Check 2"
|
| 56 |
]).to_pickle(pickle_file)
|
| 57 |
|
| 58 |
##############################################################################
|
|
|
|
| 65 |
"phq_score": 0,
|
| 66 |
"gad_score": 0,
|
| 67 |
"eligible": False,
|
| 68 |
+
"Attention Check 1": False,
|
| 69 |
+
"Attention Check 2": False,
|
| 70 |
"standardized_data": {
|
| 71 |
"Prolific ID": None,
|
| 72 |
"Raw Age": None,
|
|
|
|
| 486 |
"Cognitive Load": user_state["standardized_data"].get("Cognitive Load", None),
|
| 487 |
"Additional Comments": user_state["standardized_data"].get("Additional Comments", None),
|
| 488 |
'PHQ-9 Score': user_state["phq_score"],
|
| 489 |
+
'GAD-7 Score': user_state["gad_score"],
|
| 490 |
+
"Attention Check 1": user_state.get("Attention Check 1", None),
|
| 491 |
+
"Attention Check 2": user_state.get("Attention Check 2", None)
|
| 492 |
}, user_state)
|
| 493 |
finalize_and_save_to_space(user_state)
|
| 494 |
|
|
|
|
| 590 |
"Cognitive Load": user_state["standardized_data"].get("Cognitive Load", None),
|
| 591 |
"Additional Comments": user_state["standardized_data"].get("Additional Comments", None),
|
| 592 |
'PHQ-9 Score': user_state["phq_score"],
|
| 593 |
+
'GAD-7 Score': user_state["gad_score"],
|
| 594 |
+
"Attention Check 1": user_state.get("Attention Check 1", None),
|
| 595 |
+
"Attention Check 2": user_state.get("Attention Check 2", None)
|
| 596 |
}, user_state)
|
| 597 |
finalize_and_save_to_space(user_state)
|
| 598 |
|
|
|
|
| 1148 |
gr.update(visible=False), # Hide the textbox
|
| 1149 |
gr.update(visible=True, value=1), # Show the slider
|
| 1150 |
gr.update(visible=True) # Show the Confirm button
|
| 1151 |
+
)
|
| 1152 |
+
|
| 1153 |
elif user_state["stage"] == "internal_external_reassessment":
|
| 1154 |
+
# store Reassessment
|
| 1155 |
user_state["standardized_data"]['Raw Reassessment'] = attribution_slider
|
| 1156 |
user_state["assessment_internal_external_response"] = '1' if attribution_slider <= 5 else '2'
|
| 1157 |
if user_state["assessment_internal_external_response"] == '1':
|
|
|
|
| 1160 |
else:
|
| 1161 |
user_state["standardized_data"]['Reassessment Internal'] = 0
|
| 1162 |
user_state["standardized_data"]['Reassessment External'] = 1
|
| 1163 |
+
|
| 1164 |
+
# Next vignette
|
| 1165 |
+
user_state["vignette_counter"] += 1
|
| 1166 |
+
|
| 1167 |
+
# --- Attention Check triggers here ---
|
| 1168 |
+
# If we’re at vignette #5, do attention_check_1 (unless it's already done)
|
| 1169 |
+
if user_state["vignette_counter"] == 5 and user_state["Attention Check 1"] is None:
|
| 1170 |
+
user_state["stage"] = "Attention Check 1"
|
| 1171 |
+
response = (
|
| 1172 |
+
"ATTENTION CHECK: \n\n"
|
| 1173 |
+
"Please set the slider to 10 (option on the very right) to show you're paying attention."
|
| 1174 |
+
)
|
| 1175 |
+
chat_history[-1] = (str(attribution_slider), response)
|
| 1176 |
+
return (
|
| 1177 |
+
chat_history,
|
| 1178 |
+
user_state,
|
| 1179 |
+
gr.update(visible=False),
|
| 1180 |
+
gr.update(visible=True, value=1), # reset slider to 1
|
| 1181 |
+
gr.update(visible=True) # show confirm button
|
| 1182 |
+
)
|
| 1183 |
+
|
| 1184 |
+
# If we’re at vignette #12, do attention_check_2 (unless it's already done)
|
| 1185 |
+
if user_state["vignette_counter"] == 12 and user_state["Attention Check 2"] is None:
|
| 1186 |
+
user_state["stage"] = "Attention Check 2"
|
| 1187 |
+
response = (
|
| 1188 |
+
"ATTENTION CHECK: \n\n"
|
| 1189 |
+
"Once again, please set the slider to 10 (option on the very right) to confirm you're paying attention."
|
| 1190 |
+
)
|
| 1191 |
+
chat_history[-1] = (str(attribution_slider), response)
|
| 1192 |
+
return (
|
| 1193 |
+
chat_history,
|
| 1194 |
+
user_state,
|
| 1195 |
+
gr.update(visible=False),
|
| 1196 |
+
gr.update(visible=True, value=1),
|
| 1197 |
+
gr.update(visible=True)
|
| 1198 |
+
)
|
| 1199 |
|
| 1200 |
# If all vignettes are complete, transition to usability feedback
|
| 1201 |
+
if user_state["vignette_counter"] > 16:
|
| 1202 |
print("All vignettes completed. Moving to usability feedback.")
|
| 1203 |
# save_to_pickle(user_state["standardized_data"])
|
| 1204 |
save_partial_data_to_excel({
|
|
|
|
| 1237 |
"Cognitive Load": user_state["standardized_data"].get("Cognitive Load", None),
|
| 1238 |
"Additional Comments": user_state["standardized_data"].get("Additional Comments", None),
|
| 1239 |
'PHQ-9 Score': user_state["phq_score"],
|
| 1240 |
+
'GAD-7 Score': user_state["gad_score"],
|
| 1241 |
+
"Attention Check 1": user_state.get("Attention Check 1", None),
|
| 1242 |
+
"Attention Check 2": user_state.get("Attention Check 2", None)
|
| 1243 |
}, user_state)
|
| 1244 |
user_state["stage"] = "usability_feedback"
|
| 1245 |
user_state["usability_question_counter"] = 0
|
|
|
|
| 1293 |
"Cognitive Load": user_state["standardized_data"].get("Cognitive Load", None),
|
| 1294 |
"Additional Comments": user_state["standardized_data"].get("Additional Comments", None),
|
| 1295 |
'PHQ-9 Score': user_state["phq_score"],
|
| 1296 |
+
'GAD-7 Score': user_state["gad_score"],
|
| 1297 |
+
"Attention Check 1": user_state.get("Attention Check 1", None),
|
| 1298 |
+
"Attention Check 2": user_state.get("Attention Check 2", None)
|
| 1299 |
}, user_state)
|
| 1300 |
response = f"Thank you! We are now finished with scene {user_state['vignette_counter'] - 1}. In total you will be seeing 2 scenes.\n\nWhat would you like for your next round?\n1. A situation related to your profession.\n2. A situation related to your personal interests.\n3. Something else about me. (Add another activity or interest that is important to you by saying 'I also like...')"
|
| 1301 |
chat_history[-1] = (str(attribution_slider), response)
|
|
|
|
| 1426 |
q6 = gr.Radio(choices=["0", "1", "2", "3"], label="Feeling bad about yourself?", value = "0")
|
| 1427 |
q7 = gr.Radio(choices=["0", "1", "2", "3"], label="Trouble concentrating?", value = "0")
|
| 1428 |
q8 = gr.Radio(choices=["0", "1", "2", "3"], label="Moving or speaking so slowly people noticed?", value = "0")
|
| 1429 |
+
# q9 = gr.Radio(choices=["0", "1", "2", "3"], label="Thoughts that you would be better off dead?", value = "0")
|
| 1430 |
phq_result = gr.Markdown()
|
| 1431 |
next_button = gr.Button("Next")
|
| 1432 |
|
|
|
|
| 1547 |
)
|
| 1548 |
|
| 1549 |
# 2) After finishing PHQ-9, go to GAD-7
|
| 1550 |
+
def process_phq9_and_show_gad7(q1, q2, q3, q4, q5, q6, q7, q8, user_state):
|
| 1551 |
q1 = int(q1) if q1 is not None else 0
|
| 1552 |
q2 = int(q2) if q2 is not None else 0
|
| 1553 |
q3 = int(q3) if q3 is not None else 0
|
|
|
|
| 1556 |
q6 = int(q6) if q6 is not None else 0
|
| 1557 |
q7 = int(q7) if q7 is not None else 0
|
| 1558 |
q8 = int(q8) if q8 is not None else 0
|
| 1559 |
+
# q9 = int(q9) if q9 is not None else 0
|
| 1560 |
|
| 1561 |
# Store ID & compute PHQ-9
|
| 1562 |
+
user_state["phq_score"] = q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8
|
| 1563 |
|
| 1564 |
# On success, hide Page 2 & show Page 3
|
| 1565 |
return (
|
|
|
|
| 1571 |
|
| 1572 |
next_button.click(
|
| 1573 |
fn=process_phq9_and_show_gad7,
|
| 1574 |
+
inputs=[q1, q2, q3, q4, q5, q6, q7, q8, user_state],
|
| 1575 |
outputs=[
|
| 1576 |
phq_result,
|
| 1577 |
page_2, # hide page_2 (PHQ-9)
|