Spaces:
Runtime error
Runtime error
Update app.py
Browse files- changed page order (briefing first)
- removed questionnaire names
- changed phrasing of responses
- repeating vignette when assessing attributions
app.py
CHANGED
|
@@ -658,7 +658,7 @@ def new_chat_input(user_input, chat_history, user_state, *args, **kwargs):
|
|
| 658 |
user_state["stage"] = "vignette_usability_assessment"
|
| 659 |
print(f"Stage updated to: {user_state['stage']}")
|
| 660 |
|
| 661 |
-
response = f"""Alright, please imagine you are witnessing the following scene: \n \n {user_state["vignette"]} \n \n Before we proceed
|
| 662 |
chat_history[-1] = (user_input, response)
|
| 663 |
return chat_history, user_state, ""
|
| 664 |
else:
|
|
@@ -749,7 +749,8 @@ def new_chat_input(user_input, chat_history, user_state, *args, **kwargs):
|
|
| 749 |
user_state["stage"] = "internal_external"
|
| 750 |
user_state['options_text'] = generate_internal_external_options(chat_history, user_state["standardized_data"][f'Vignette'], user_state)
|
| 751 |
response = (
|
| 752 |
-
"
|
|
|
|
| 753 |
f"{user_state['options_text']}")
|
| 754 |
chat_history[-1] = (user_input, response)
|
| 755 |
return chat_history, user_state, ""
|
|
@@ -768,7 +769,7 @@ def new_chat_input(user_input, chat_history, user_state, *args, **kwargs):
|
|
| 768 |
response = (
|
| 769 |
"Okay, let's try again. Please imagine you are witnessing the following scene:\n\n"
|
| 770 |
f"""{user_state["vignette"]}\n\n"""
|
| 771 |
-
"Before we proceed
|
| 772 |
|
| 773 |
chat_history[-1] = (user_input, response)
|
| 774 |
return chat_history, user_state, ""
|
|
@@ -799,8 +800,8 @@ def new_chat_input(user_input, chat_history, user_state, *args, **kwargs):
|
|
| 799 |
previous_choice = user_state["explanation_response"]
|
| 800 |
user_state['options_text'] = generate_stable_unstable_options(chat_history, user_state["standardized_data"][f'Vignette'], previous_choice, user_state)
|
| 801 |
response = (
|
| 802 |
-
"Now, considering your previous choice, please select the option that - in your eyes - best describes what might have led to this situation:\n
|
| 803 |
-
f"{user_state['options_text']}")
|
| 804 |
|
| 805 |
chat_history[-1] = (user_input, response)
|
| 806 |
return chat_history, user_state, ""
|
|
@@ -1063,18 +1064,45 @@ def new_chat_input(user_input, chat_history, user_state, *args, **kwargs):
|
|
| 1063 |
# }"""
|
| 1064 |
|
| 1065 |
|
| 1066 |
-
|
| 1067 |
with gr.Blocks(theme= gr.themes.Glass()) as app:
|
| 1068 |
########################################################################
|
| 1069 |
-
# Page 1:
|
| 1070 |
########################################################################
|
| 1071 |
|
| 1072 |
user_state = gr.State(get_default_app_state())
|
| 1073 |
|
| 1074 |
-
with gr.Row(visible=True) as page_1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1075 |
with gr.Column():
|
| 1076 |
# PHQ-9
|
| 1077 |
-
gr.Markdown("## Pretest: PHQ-9")
|
| 1078 |
gr.Markdown("### Enter Your Prolific ID:")
|
| 1079 |
pid_input = gr.Textbox(label="Prolific ID (required)")
|
| 1080 |
pid_output = gr.Markdown()
|
|
@@ -1093,13 +1121,14 @@ with gr.Blocks(theme= gr.themes.Glass()) as app:
|
|
| 1093 |
q9 = gr.Slider(0, 3, step=1, label="Thoughts that you would be better off dead?")
|
| 1094 |
phq_result = gr.Markdown()
|
| 1095 |
next_button = gr.Button("Next")
|
| 1096 |
-
|
| 1097 |
########################################################################
|
| 1098 |
-
# Page
|
| 1099 |
########################################################################
|
| 1100 |
-
|
|
|
|
| 1101 |
with gr.Column():
|
| 1102 |
-
gr.Markdown("""
|
| 1103 |
Over the last 2 weeks, how often have you been bothered by
|
| 1104 |
any of the following problems (0 = "Never", 3 = "Very often")?
|
| 1105 |
""")
|
|
@@ -1112,39 +1141,12 @@ with gr.Blocks(theme= gr.themes.Glass()) as app:
|
|
| 1112 |
g7 = gr.Slider(0, 3, step=1, label="Feeling afraid as if something awful might happen?")
|
| 1113 |
gad_result = gr.HTML()
|
| 1114 |
finish_button = gr.Button("Finish")
|
| 1115 |
-
|
| 1116 |
-
########################################################################
|
| 1117 |
-
# Page 3: Chatbot
|
| 1118 |
-
########################################################################
|
| 1119 |
-
# Page 3a: Briefing/Instructions before Chatbot
|
| 1120 |
-
with gr.Row(visible=False) as page_3a:
|
| 1121 |
-
with gr.Column():
|
| 1122 |
-
gr.Markdown("## Briefing & Informed Consent")
|
| 1123 |
-
gr.Markdown("""
|
| 1124 |
-
By participating in this study, you will be asked to imagine yourself in various fictional scenarios
|
| 1125 |
-
and answer questions about your thoughts or feelings. Your data will remain anonymous and will be used
|
| 1126 |
-
solely for research purposes.
|
| 1127 |
-
|
| 1128 |
-
The chatbot you will interact with is standardized and does not have access to the internet. It relies solely on its
|
| 1129 |
-
internal model for generating responses.
|
| 1130 |
-
|
| 1131 |
-
**How to Interact:**
|
| 1132 |
-
1. Read each prompt or question carefully.
|
| 1133 |
-
2. Type your response in the input field provided, then press **Enter**.
|
| 1134 |
-
3. The chatbot will respond based on your previous inputs; it does not pull information from external sources.
|
| 1135 |
-
4. Continue following the chatbot’s instructions until you have completed all scenarios and subsequent questions.
|
| 1136 |
-
|
| 1137 |
-
You may include personal interests or additional details at any time (for example, "I also like hiking") by typing
|
| 1138 |
-
them naturally into the conversation. Please keep your responses relevant to the prompts you receive.
|
| 1139 |
-
|
| 1140 |
-
By clicking **Continue** below, you acknowledge that you have read this information and consent to participate
|
| 1141 |
-
in the study.
|
| 1142 |
-
""")
|
| 1143 |
-
# Consent by pressing the button
|
| 1144 |
-
briefing_start_button = gr.Button("Continue")
|
| 1145 |
|
| 1146 |
-
#
|
| 1147 |
-
|
|
|
|
|
|
|
|
|
|
| 1148 |
with gr.Column():
|
| 1149 |
gr.Markdown("## Tell Us About Yourself")
|
| 1150 |
gr.Markdown("""Great! During the course of this assessment you will be confronted with descriptions of fictional everyday situations. Please try to immerse yourself in these scenarios as if they were happening to you personally.
|
|
@@ -1159,9 +1161,12 @@ with gr.Blocks(theme= gr.themes.Glass()) as app:
|
|
| 1159 |
|
| 1160 |
user_profile_button = gr.Button("Submit Profile")
|
| 1161 |
user_profile_output = gr.Markdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1162 |
|
| 1163 |
-
|
| 1164 |
-
with gr.Row(visible=False) as page_3:
|
| 1165 |
with gr.Column():
|
| 1166 |
# Title and Description
|
| 1167 |
gr.Markdown("## Welcome to the Chatbot Assessment")
|
|
@@ -1184,31 +1189,49 @@ with gr.Blocks(theme= gr.themes.Glass()) as app:
|
|
| 1184 |
outputs=[chatbot, user_state, user_message],
|
| 1185 |
queue=False # Disable queueing for real-time streaming
|
| 1186 |
)
|
| 1187 |
-
|
| 1188 |
######################################################################
|
| 1189 |
# Transition Logic
|
| 1190 |
######################################################################
|
| 1191 |
|
| 1192 |
-
# 1) After
|
| 1193 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1194 |
pid = pid.strip()
|
| 1195 |
if not pid:
|
| 1196 |
-
# If Prolific ID is missing, show an error & keep Page
|
| 1197 |
return (
|
| 1198 |
"Error: Please enter your Prolific ID.",
|
| 1199 |
-
gr.update(visible=True), # Keep
|
| 1200 |
-
gr.update(visible=False), # Keep
|
| 1201 |
user_state
|
| 1202 |
)
|
| 1203 |
# Store ID & compute PHQ-9
|
| 1204 |
user_state["prolific_id"] = pid
|
| 1205 |
user_state["phq_score"] = q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8 + q9
|
| 1206 |
|
| 1207 |
-
# On success, hide Page
|
| 1208 |
return (
|
| 1209 |
f"Prolific ID {pid} recorded. PHQ-9 total = {user_state['phq_score']}. Proceed to GAD-7.",
|
| 1210 |
-
gr.update(visible=False), # Hide
|
| 1211 |
-
gr.update(visible=True), # Show
|
| 1212 |
user_state
|
| 1213 |
)
|
| 1214 |
|
|
@@ -1217,14 +1240,14 @@ with gr.Blocks(theme= gr.themes.Glass()) as app:
|
|
| 1217 |
inputs=[pid_input, q1, q2, q3, q4, q5, q6, q7, q8, q9, user_state],
|
| 1218 |
outputs=[
|
| 1219 |
phq_result,
|
| 1220 |
-
|
| 1221 |
-
|
| 1222 |
user_state
|
| 1223 |
]
|
| 1224 |
)
|
| 1225 |
|
| 1226 |
-
#
|
| 1227 |
-
def
|
| 1228 |
user_state["gad_score"] = g1 + g2 + g3 + g4 + g5 + g6 + g7
|
| 1229 |
combined_score = user_state["phq_score"] + user_state["gad_score"]
|
| 1230 |
|
|
@@ -1232,47 +1255,28 @@ with gr.Blocks(theme= gr.themes.Glass()) as app:
|
|
| 1232 |
# Show an error, keep GAD-7 visible, keep briefing hidden
|
| 1233 |
return (
|
| 1234 |
"Your combined score exceeds the threshold. You do not meet the inclusion criteria.",
|
| 1235 |
-
gr.update(visible=True), # keep
|
| 1236 |
-
gr.update(visible=False), # keep
|
| 1237 |
user_state)
|
| 1238 |
|
| 1239 |
user_state["eligible"] = True
|
| 1240 |
-
|
| 1241 |
return (
|
| 1242 |
-
f"GAD-7 completed, total = {user_state['gad_score']}. Proceeding to
|
| 1243 |
-
gr.update(visible=False), # hide
|
| 1244 |
-
gr.update(visible=True), # show
|
| 1245 |
-
user_state
|
| 1246 |
-
)
|
| 1247 |
|
| 1248 |
finish_button.click(
|
| 1249 |
-
fn=
|
| 1250 |
inputs=[g1, g2, g3, g4, g5, g6, g7, user_state],
|
| 1251 |
outputs=[
|
| 1252 |
gad_result,
|
| 1253 |
-
|
| 1254 |
-
|
| 1255 |
user_state]
|
| 1256 |
)
|
| 1257 |
-
|
| 1258 |
-
# 3) After Briefing, go to User Profile
|
| 1259 |
-
def show_user_profile(user_state):
|
| 1260 |
-
# Hide the briefing page, show the user profile page
|
| 1261 |
-
return (
|
| 1262 |
-
gr.update(visible=False), # hide page_3a
|
| 1263 |
-
gr.update(visible=True), # show page_3b
|
| 1264 |
-
user_state
|
| 1265 |
-
)
|
| 1266 |
|
| 1267 |
-
briefing_start_button.click(
|
| 1268 |
-
fn=show_user_profile,
|
| 1269 |
-
inputs=[user_state],
|
| 1270 |
-
outputs=[
|
| 1271 |
-
page_3a, # hide page 3a
|
| 1272 |
-
page_3b, # show page 3b
|
| 1273 |
-
user_state]
|
| 1274 |
-
)
|
| 1275 |
-
|
| 1276 |
# 4) After User Profile, go to Chatbot
|
| 1277 |
def process_user_profile(age, profession, interest, user_state):
|
| 1278 |
|
|
@@ -1293,11 +1297,11 @@ with gr.Blocks(theme= gr.themes.Glass()) as app:
|
|
| 1293 |
user_state["standardized_data"]["Interests"] = interest.strip()
|
| 1294 |
|
| 1295 |
print(f"user_state at the end of show_chatbot_after_profile: {user_state}")
|
| 1296 |
-
|
| 1297 |
return (
|
| 1298 |
"Profile submitted successfully. Proceeding to the chatbot.",
|
| 1299 |
-
gr.update(visible=False), # Hide
|
| 1300 |
-
gr.update(visible=True), # Show
|
| 1301 |
user_state
|
| 1302 |
)
|
| 1303 |
|
|
@@ -1306,9 +1310,10 @@ with gr.Blocks(theme= gr.themes.Glass()) as app:
|
|
| 1306 |
inputs=[age_input, profession_input, interest_input, user_state],
|
| 1307 |
outputs=[
|
| 1308 |
user_profile_output,
|
| 1309 |
-
|
| 1310 |
-
|
| 1311 |
user_state]
|
| 1312 |
)
|
|
|
|
| 1313 |
|
| 1314 |
app.launch()
|
|
|
|
| 658 |
user_state["stage"] = "vignette_usability_assessment"
|
| 659 |
print(f"Stage updated to: {user_state['stage']}")
|
| 660 |
|
| 661 |
+
response = f"""Alright, please imagine you are witnessing the following scene: \n \n {user_state["vignette"]} \n \n Before we proceed: Have you personally experienced something similar to this scenario before? Please rate the similarity on a scale from 1 to 10 (1 = Not at all similar, 10 = Extremely similar)."""
|
| 662 |
chat_history[-1] = (user_input, response)
|
| 663 |
return chat_history, user_state, ""
|
| 664 |
else:
|
|
|
|
| 749 |
user_state["stage"] = "internal_external"
|
| 750 |
user_state['options_text'] = generate_internal_external_options(chat_history, user_state["standardized_data"][f'Vignette'], user_state)
|
| 751 |
response = (
|
| 752 |
+
f"Please read the scenario again:\n{user_state['vignette']}\n"
|
| 753 |
+
"\nFrom 1 to 10, which of the following statements do you personally think is more likely (1 = Definitely Option 1, 10 = Definitely Option 2):\n"
|
| 754 |
f"{user_state['options_text']}")
|
| 755 |
chat_history[-1] = (user_input, response)
|
| 756 |
return chat_history, user_state, ""
|
|
|
|
| 769 |
response = (
|
| 770 |
"Okay, let's try again. Please imagine you are witnessing the following scene:\n\n"
|
| 771 |
f"""{user_state["vignette"]}\n\n"""
|
| 772 |
+
"Before we proceed: Have you personally experienced something similar to this scenario before? Please rate the similarity on a scale from 1 to 10 (1 = Not at all similar, 10 = Extremely similar).")
|
| 773 |
|
| 774 |
chat_history[-1] = (user_input, response)
|
| 775 |
return chat_history, user_state, ""
|
|
|
|
| 800 |
previous_choice = user_state["explanation_response"]
|
| 801 |
user_state['options_text'] = generate_stable_unstable_options(chat_history, user_state["standardized_data"][f'Vignette'], previous_choice, user_state)
|
| 802 |
response = (
|
| 803 |
+
"Now, considering your previous choice, please select the option that - in your eyes - best describes what might have led to this situation:\n"
|
| 804 |
+
f"\n{user_state['options_text']}")
|
| 805 |
|
| 806 |
chat_history[-1] = (user_input, response)
|
| 807 |
return chat_history, user_state, ""
|
|
|
|
| 1064 |
# }"""
|
| 1065 |
|
| 1066 |
|
|
|
|
| 1067 |
with gr.Blocks(theme= gr.themes.Glass()) as app:
|
| 1068 |
########################################################################
|
| 1069 |
+
# Page 1: Briefing & Informed Consent
|
| 1070 |
########################################################################
|
| 1071 |
|
| 1072 |
user_state = gr.State(get_default_app_state())
|
| 1073 |
|
| 1074 |
+
with gr.Row(visible=True) as page_1:
|
| 1075 |
+
with gr.Column():
|
| 1076 |
+
gr.Markdown("## Briefing & Informed Consent")
|
| 1077 |
+
gr.Markdown("""
|
| 1078 |
+
By participating in this study, you will be asked to imagine yourself in various fictional scenarios
|
| 1079 |
+
and answer questions about your thoughts or feelings. Your data will remain anonymous and will be used
|
| 1080 |
+
solely for research purposes.
|
| 1081 |
+
The chatbot you will interact with is standardized and does not have access to the internet. It relies solely on its
|
| 1082 |
+
internal model for generating responses.
|
| 1083 |
+
|
| 1084 |
+
**How to Interact:**
|
| 1085 |
+
1. Read each prompt or question carefully.
|
| 1086 |
+
2. Type your response in the input field provided, then press **Enter**.
|
| 1087 |
+
3. The chatbot will respond based on your previous inputs; it does not pull information from external sources.
|
| 1088 |
+
4. Continue following the chatbot’s instructions until you have completed all scenarios and subsequent questions.
|
| 1089 |
+
|
| 1090 |
+
You may include personal interests or additional details at any time (for example, "I also like hiking") by typing
|
| 1091 |
+
them naturally into the conversation. Please keep your responses relevant to the prompts you receive.
|
| 1092 |
+
|
| 1093 |
+
By clicking **Continue** below, you acknowledge that you have read this information and consent to participate
|
| 1094 |
+
in the study.
|
| 1095 |
+
""")
|
| 1096 |
+
# Consent by pressing the button
|
| 1097 |
+
briefing_start_button = gr.Button("Continue")
|
| 1098 |
+
|
| 1099 |
+
########################################################################
|
| 1100 |
+
# Page 2: Pretest: PHQ-9
|
| 1101 |
+
########################################################################
|
| 1102 |
+
|
| 1103 |
+
with gr.Row(visible=False) as page_2:
|
| 1104 |
with gr.Column():
|
| 1105 |
# PHQ-9
|
|
|
|
| 1106 |
gr.Markdown("### Enter Your Prolific ID:")
|
| 1107 |
pid_input = gr.Textbox(label="Prolific ID (required)")
|
| 1108 |
pid_output = gr.Markdown()
|
|
|
|
| 1121 |
q9 = gr.Slider(0, 3, step=1, label="Thoughts that you would be better off dead?")
|
| 1122 |
phq_result = gr.Markdown()
|
| 1123 |
next_button = gr.Button("Next")
|
| 1124 |
+
|
| 1125 |
########################################################################
|
| 1126 |
+
# Page 3: Pretest: GAD-7
|
| 1127 |
########################################################################
|
| 1128 |
+
|
| 1129 |
+
with gr.Row(visible=False) as page_3:
|
| 1130 |
with gr.Column():
|
| 1131 |
+
gr.Markdown("""
|
| 1132 |
Over the last 2 weeks, how often have you been bothered by
|
| 1133 |
any of the following problems (0 = "Never", 3 = "Very often")?
|
| 1134 |
""")
|
|
|
|
| 1141 |
g7 = gr.Slider(0, 3, step=1, label="Feeling afraid as if something awful might happen?")
|
| 1142 |
gad_result = gr.HTML()
|
| 1143 |
finish_button = gr.Button("Finish")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1144 |
|
| 1145 |
+
#######################################################################
|
| 1146 |
+
# Page 4: User Profile
|
| 1147 |
+
#######################################################################
|
| 1148 |
+
|
| 1149 |
+
with gr.Row(visible=False) as page_4:
|
| 1150 |
with gr.Column():
|
| 1151 |
gr.Markdown("## Tell Us About Yourself")
|
| 1152 |
gr.Markdown("""Great! During the course of this assessment you will be confronted with descriptions of fictional everyday situations. Please try to immerse yourself in these scenarios as if they were happening to you personally.
|
|
|
|
| 1161 |
|
| 1162 |
user_profile_button = gr.Button("Submit Profile")
|
| 1163 |
user_profile_output = gr.Markdown()
|
| 1164 |
+
|
| 1165 |
+
#######################################################################
|
| 1166 |
+
# Page 5: Chatbot Assessment
|
| 1167 |
+
#######################################################################
|
| 1168 |
|
| 1169 |
+
with gr.Row(visible=False) as page_5:
|
|
|
|
| 1170 |
with gr.Column():
|
| 1171 |
# Title and Description
|
| 1172 |
gr.Markdown("## Welcome to the Chatbot Assessment")
|
|
|
|
| 1189 |
outputs=[chatbot, user_state, user_message],
|
| 1190 |
queue=False # Disable queueing for real-time streaming
|
| 1191 |
)
|
| 1192 |
+
|
| 1193 |
######################################################################
|
| 1194 |
# Transition Logic
|
| 1195 |
######################################################################
|
| 1196 |
|
| 1197 |
+
# 1) After Briefing, go to PHQ-9
|
| 1198 |
+
def show_phq9(user_state):
|
| 1199 |
+
# Hide the briefing page, show the PHQ-9 page
|
| 1200 |
+
return (
|
| 1201 |
+
gr.update(visible=False), # hide page_1
|
| 1202 |
+
gr.update(visible=True), # show page_2 (PHQ-9)
|
| 1203 |
+
user_state
|
| 1204 |
+
)
|
| 1205 |
+
|
| 1206 |
+
briefing_start_button.click(
|
| 1207 |
+
fn=show_phq9,
|
| 1208 |
+
inputs=[user_state],
|
| 1209 |
+
outputs=[
|
| 1210 |
+
page_1, # hide page_1 (Briefing)
|
| 1211 |
+
page_2, # show page_2 (PHQ-9)
|
| 1212 |
+
user_state]
|
| 1213 |
+
)
|
| 1214 |
+
|
| 1215 |
+
# 2) After finishing PHQ-9, go to GAD-7
|
| 1216 |
+
def process_phq9_and_show_gad7(pid, q1, q2, q3, q4, q5, q6, q7, q8, q9, user_state):
|
| 1217 |
pid = pid.strip()
|
| 1218 |
if not pid:
|
| 1219 |
+
# If Prolific ID is missing, show an error & keep Page 2 visible
|
| 1220 |
return (
|
| 1221 |
"Error: Please enter your Prolific ID.",
|
| 1222 |
+
gr.update(visible=True), # Keep page_2 visible
|
| 1223 |
+
gr.update(visible=False), # Keep page_3 hidden
|
| 1224 |
user_state
|
| 1225 |
)
|
| 1226 |
# Store ID & compute PHQ-9
|
| 1227 |
user_state["prolific_id"] = pid
|
| 1228 |
user_state["phq_score"] = q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8 + q9
|
| 1229 |
|
| 1230 |
+
# On success, hide Page 2 & show Page 3
|
| 1231 |
return (
|
| 1232 |
f"Prolific ID {pid} recorded. PHQ-9 total = {user_state['phq_score']}. Proceed to GAD-7.",
|
| 1233 |
+
gr.update(visible=False), # Hide page_2
|
| 1234 |
+
gr.update(visible=True), # Show page_3
|
| 1235 |
user_state
|
| 1236 |
)
|
| 1237 |
|
|
|
|
| 1240 |
inputs=[pid_input, q1, q2, q3, q4, q5, q6, q7, q8, q9, user_state],
|
| 1241 |
outputs=[
|
| 1242 |
phq_result,
|
| 1243 |
+
page_2, # hide page_2 (PHQ-9)
|
| 1244 |
+
page_3, # show page_3 (GAD-7)
|
| 1245 |
user_state
|
| 1246 |
]
|
| 1247 |
)
|
| 1248 |
|
| 1249 |
+
# 3) After finishing GAD-7, go to User Profile
|
| 1250 |
+
def process_gad7_and_show_user_profile(g1, g2, g3, g4, g5, g6, g7, user_state):
|
| 1251 |
user_state["gad_score"] = g1 + g2 + g3 + g4 + g5 + g6 + g7
|
| 1252 |
combined_score = user_state["phq_score"] + user_state["gad_score"]
|
| 1253 |
|
|
|
|
| 1255 |
# Show an error, keep GAD-7 visible, keep briefing hidden
|
| 1256 |
return (
|
| 1257 |
"Your combined score exceeds the threshold. You do not meet the inclusion criteria.",
|
| 1258 |
+
gr.update(visible=True), # keep page_3 visible
|
| 1259 |
+
gr.update(visible=False), # keep page_1 hidden (Briefing)
|
| 1260 |
user_state)
|
| 1261 |
|
| 1262 |
user_state["eligible"] = True
|
| 1263 |
+
|
| 1264 |
return (
|
| 1265 |
+
f"GAD-7 completed, total = {user_state['gad_score']}. Proceeding to user profile.",
|
| 1266 |
+
gr.update(visible=False), # hide page_3 (GAD-7)
|
| 1267 |
+
gr.update(visible=True), # show page_4 (User Profile)
|
| 1268 |
+
user_state)
|
|
|
|
| 1269 |
|
| 1270 |
finish_button.click(
|
| 1271 |
+
fn=process_gad7_and_show_user_profile, # Updated function name
|
| 1272 |
inputs=[g1, g2, g3, g4, g5, g6, g7, user_state],
|
| 1273 |
outputs=[
|
| 1274 |
gad_result,
|
| 1275 |
+
page_3, # hide page_3 (GAD-7)
|
| 1276 |
+
page_4, # show page_4 (User Profile)
|
| 1277 |
user_state]
|
| 1278 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1280 |
# 4) After User Profile, go to Chatbot
|
| 1281 |
def process_user_profile(age, profession, interest, user_state):
|
| 1282 |
|
|
|
|
| 1297 |
user_state["standardized_data"]["Interests"] = interest.strip()
|
| 1298 |
|
| 1299 |
print(f"user_state at the end of show_chatbot_after_profile: {user_state}")
|
| 1300 |
+
|
| 1301 |
return (
|
| 1302 |
"Profile submitted successfully. Proceeding to the chatbot.",
|
| 1303 |
+
gr.update(visible=False), # Hide page_4 (User Profile)
|
| 1304 |
+
gr.update(visible=True), # Show page_5 (Chatbot)
|
| 1305 |
user_state
|
| 1306 |
)
|
| 1307 |
|
|
|
|
| 1310 |
inputs=[age_input, profession_input, interest_input, user_state],
|
| 1311 |
outputs=[
|
| 1312 |
user_profile_output,
|
| 1313 |
+
page_4, # hide page_4 (User Profile)
|
| 1314 |
+
page_5, # show page_5 (Chatbot)
|
| 1315 |
user_state]
|
| 1316 |
)
|
| 1317 |
+
|
| 1318 |
|
| 1319 |
app.launch()
|