Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -320,37 +320,46 @@ def save_to_pickle(standardized_data, user_state):
|
|
| 320 |
# user_state["prolific_id"] = pid
|
| 321 |
# return f"Prolific ID {pid} has been recorded.", user_state
|
| 322 |
|
| 323 |
-
def
|
| 324 |
-
#
|
| 325 |
pid = pid.strip()
|
| 326 |
if not pid:
|
| 327 |
-
return "Error: Please enter your Prolific ID.",
|
| 328 |
-
|
| 329 |
-
user_state["prolific_id"] = pid
|
| 330 |
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
user_state["phq_score"] = total_score
|
| 334 |
|
| 335 |
-
#
|
| 336 |
return (
|
| 337 |
-
f"Prolific ID {pid} has been recorded. PHQ-9 completed. Score: {
|
| 338 |
-
gr.update(visible=False), # Hide
|
| 339 |
gr.update(visible=True), # Show GAD-7 page
|
| 340 |
user_state
|
| 341 |
)
|
| 342 |
|
| 343 |
-
def
|
| 344 |
-
#
|
| 345 |
user_state["gad_score"] = sum(scores)
|
| 346 |
combined_score = user_state["phq_score"] + user_state["gad_score"]
|
| 347 |
|
| 348 |
-
|
| 349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
|
| 351 |
user_state["eligible"] = True
|
| 352 |
-
return "GAD-7 completed successfully. Proceeding to the next step.", gr.update(visible=False), gr.update(visible=True), user_state
|
| 353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
|
| 355 |
def store_user_profile(age, profession, interest, user_state):
|
| 356 |
"""
|
|
@@ -1047,28 +1056,24 @@ with gr.Blocks(css=css) as app:
|
|
| 1047 |
######################################################################
|
| 1048 |
|
| 1049 |
# 1) After finishing PHQ-9, go to GAD-7
|
| 1050 |
-
def show_gad7(user_state):
|
| 1051 |
-
|
| 1052 |
|
| 1053 |
next_button.click(
|
| 1054 |
-
fn=
|
| 1055 |
inputs=[pid_input, q1, q2, q3, q4, q5, q6, q7, q8, q9, user_state],
|
| 1056 |
outputs=[phq_result, page_1, page_2, user_state]
|
| 1057 |
)
|
| 1058 |
-
next_button.click(show_gad7, inputs=[user_state], outputs=[page_1, page_2, user_state])
|
| 1059 |
-
|
| 1060 |
|
| 1061 |
# 2) After finishing GAD-7, go to Briefing Page
|
| 1062 |
-
def show_briefing(user_state):
|
| 1063 |
-
|
| 1064 |
|
| 1065 |
finish_button.click(
|
| 1066 |
-
fn=
|
| 1067 |
inputs=[g1, g2, g3, g4, g5, g6, g7, user_state],
|
| 1068 |
outputs=[gad_result, page_2, page_3a, user_state]
|
| 1069 |
)
|
| 1070 |
-
finish_button.click(show_briefing, inputs=[user_state], outputs=[page_2, page_3a, user_state])
|
| 1071 |
-
|
| 1072 |
|
| 1073 |
# 3) After Briefing, go to User Profile
|
| 1074 |
def show_user_profile(user_state):
|
|
|
|
| 320 |
# user_state["prolific_id"] = pid
|
| 321 |
# return f"Prolific ID {pid} has been recorded.", user_state
|
| 322 |
|
| 323 |
+
def process_phq9_and_show_gad7(pid, *scores, user_state):
|
| 324 |
+
# Step 1: Process Prolific ID and PHQ-9 scores
|
| 325 |
pid = pid.strip()
|
| 326 |
if not pid:
|
| 327 |
+
return "Error: Please enter your Prolific ID.", gr.update(visible=True), gr.update(visible=False), user_state
|
|
|
|
|
|
|
| 328 |
|
| 329 |
+
user_state["prolific_id"] = pid
|
| 330 |
+
user_state["phq_score"] = sum(scores)
|
|
|
|
| 331 |
|
| 332 |
+
# Step 2: Return outputs to hide current page and show GAD-7 page
|
| 333 |
return (
|
| 334 |
+
f"Prolific ID {pid} has been recorded. PHQ-9 completed. Score: {user_state['phq_score']}. Proceed to GAD-7.",
|
| 335 |
+
gr.update(visible=False), # Hide PHQ-9 page
|
| 336 |
gr.update(visible=True), # Show GAD-7 page
|
| 337 |
user_state
|
| 338 |
)
|
| 339 |
|
| 340 |
+
def process_gad7_and_show_briefing(*scores, user_state):
|
| 341 |
+
# Step 1: Process GAD-7 scores
|
| 342 |
user_state["gad_score"] = sum(scores)
|
| 343 |
combined_score = user_state["phq_score"] + user_state["gad_score"]
|
| 344 |
|
| 345 |
+
# Step 2: Check eligibility
|
| 346 |
+
if combined_score > 20: # Example threshold
|
| 347 |
+
return (
|
| 348 |
+
"Your combined score exceeds the threshold. You do not meet the inclusion criteria.",
|
| 349 |
+
gr.update(visible=True), # Keep GAD-7 page visible
|
| 350 |
+
gr.update(visible=False), # Keep briefing hidden
|
| 351 |
+
user_state
|
| 352 |
+
)
|
| 353 |
|
| 354 |
user_state["eligible"] = True
|
|
|
|
| 355 |
|
| 356 |
+
# Step 3: Transition to briefing page
|
| 357 |
+
return (
|
| 358 |
+
"GAD-7 completed successfully. Proceeding to the briefing.",
|
| 359 |
+
gr.update(visible=False), # Hide GAD-7 page
|
| 360 |
+
gr.update(visible=True), # Show briefing page
|
| 361 |
+
user_state
|
| 362 |
+
)
|
| 363 |
|
| 364 |
def store_user_profile(age, profession, interest, user_state):
|
| 365 |
"""
|
|
|
|
| 1056 |
######################################################################
|
| 1057 |
|
| 1058 |
# 1) After finishing PHQ-9, go to GAD-7
|
| 1059 |
+
# def show_gad7(user_state):
|
| 1060 |
+
# return (gr.update(visible=False), gr.update(visible=True), user_state)
|
| 1061 |
|
| 1062 |
next_button.click(
|
| 1063 |
+
fn=process_phq9_and_show_gad7,
|
| 1064 |
inputs=[pid_input, q1, q2, q3, q4, q5, q6, q7, q8, q9, user_state],
|
| 1065 |
outputs=[phq_result, page_1, page_2, user_state]
|
| 1066 |
)
|
|
|
|
|
|
|
| 1067 |
|
| 1068 |
# 2) After finishing GAD-7, go to Briefing Page
|
| 1069 |
+
# def show_briefing(user_state):
|
| 1070 |
+
# return (gr.update(visible=False), gr.update(visible=True), user_state)
|
| 1071 |
|
| 1072 |
finish_button.click(
|
| 1073 |
+
fn=process_gad7_and_show_briefing,
|
| 1074 |
inputs=[g1, g2, g3, g4, g5, g6, g7, user_state],
|
| 1075 |
outputs=[gad_result, page_2, page_3a, user_state]
|
| 1076 |
)
|
|
|
|
|
|
|
| 1077 |
|
| 1078 |
# 3) After Briefing, go to User Profile
|
| 1079 |
def show_user_profile(user_state):
|