mojakob commited on
Commit
09da72d
·
verified ·
1 Parent(s): 48b2f3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -20
app.py CHANGED
@@ -129,7 +129,7 @@ EXCLUSION_THRESHOLD = 20
129
  # Storing / Uploading Functions
130
  ##############################################################################
131
 
132
- def generate_custom_vignette(chat_history, topic_choice, desired_tone, user_state):
133
  """
134
  Generates a personalized vignette for psychological assessment based on user preferences, ensuring
135
  that each vignette exclusively reflects the chosen topic (profession or interest) without mixing them.
@@ -166,6 +166,16 @@ def generate_custom_vignette(chat_history, topic_choice, desired_tone, user_stat
166
  else:
167
  tone_context = "a neutral situation."
168
 
 
 
 
 
 
 
 
 
 
 
169
  # Build a prompt that references ONLY the chosen topic
170
  prompt = f"""
171
  You are tasked with generating a short, personalized vignette for a psychological assessment.
@@ -188,6 +198,8 @@ def generate_custom_vignette(chat_history, topic_choice, desired_tone, user_stat
188
  - Do not include personal identifying information.
189
  - Do not mention both profession and personal interests together; focus exclusively on the chosen topic.
190
  - Do not mix multiple interests or contexts; stay consistent with the single chosen topic.
 
 
191
 
192
  Now generate the vignette:
193
  """
@@ -394,6 +406,9 @@ def process_feedback(ease, clarity, engagement, satisfaction, cognitive_load, us
394
  chat_history[-1] = (user_input, response)
395
  return chat_history, user_state
396
 
 
 
 
397
  def handle_slider(slider_value, chat_history, user_state):
398
  """
399
  Processes the slider input (1-10) depending on the current stage
@@ -437,7 +452,7 @@ def handle_slider(slider_value, chat_history, user_state):
437
  "Now, from 1 to 10, which do you think is more likely? (1 = Definitely Option A, 10 = Definitely Option B)\n\n"
438
  f"{user_state['options_text']}"
439
  )
440
- chat_history.append(("", response))
441
  # Return the chat + user_state, and keep the slider visible
442
  return (
443
  chat_history, # Updated chat history
@@ -466,7 +481,7 @@ def handle_slider(slider_value, chat_history, user_state):
466
  "Next, from 1 to 10, which do you think is more likely? (1 = Definitely Option A, 10 = Definitely Option B)\n\n"
467
  f"{user_state['options_text']}"
468
  )
469
- chat_history.append(("", response))
470
  return (
471
  chat_history, # Updated chat history
472
  user_state, # Updated user state
@@ -500,7 +515,7 @@ def handle_slider(slider_value, chat_history, user_state):
500
  "On a scale from 1 to 10, which is more likely? (1 = Definitely Option A, 10 = Definitely Option B)\n"
501
  f"{user_state['options_text']}"
502
  )
503
- chat_history.append(("", response))
504
  return (
505
  chat_history, # Updated chat history
506
  user_state, # Updated user state
@@ -1146,8 +1161,8 @@ def new_chat_input(user_input, chat_history, user_state, attribution_slider, *ar
1146
  user_state["stage"] = "internal_external"
1147
  user_state['options_text'] = generate_internal_external_options(chat_history, user_state["standardized_data"][f'Vignette'], user_state)
1148
  response = (
1149
- f"Please read the scenario again:\n{user_state['vignette']}\n"
1150
- "\nFrom 1 to 10, which of the following statements do you personally think is more likely (1 = Definitely Option A, 10 = Definitely Option B):\n"
1151
  f"{user_state['options_text']}")
1152
  chat_history[-1] = (user_input, response)
1153
  return (
@@ -1157,31 +1172,35 @@ def new_chat_input(user_input, chat_history, user_state, attribution_slider, *ar
1157
  gr.update(visible=True), # Slider
1158
  gr.update(visible=True) # Confirm button
1159
  )
1160
-
1161
  elif user_state["stage"] == "vignette_regeneration":
1162
  additional_info = user_input
1163
- user_state["user_responses"].append({'user_state["stage"]': 'additional_info', 'response': additional_info})
 
 
 
1164
 
1165
- # Retrieve the current 'Topic Choice' and 'New Interest' (if any)
1166
  topic_choice = user_state["standardized_data"].get("Topic Choice", user_state["topic_choice"])
1167
  new_interest = user_state["standardized_data"].get("New Interest", None)
1168
 
1169
- # If the topic_choice was '3' and a new interest exists, use the new interest for vignette generation
1170
  if topic_choice == "3" and new_interest:
1171
  topic_choice_for_vignette = new_interest
1172
  else:
1173
  topic_choice_for_vignette = topic_choice
1174
 
1175
- # Regenerate the vignette
1176
  user_state["vignette"], user_state["tone"] = generate_custom_vignette(
1177
  chat_history=chat_history,
1178
  topic_choice=topic_choice_for_vignette,
1179
  desired_tone=user_state["desired_tone"],
1180
- user_state=user_state
 
1181
  )
1182
 
1183
  user_state["user_responses"].append({
1184
- 'user_state["stage"]': 'vignette_regenerated',
1185
  'content': user_state["vignette"],
1186
  'tone': user_state["tone"]
1187
  })
@@ -1198,7 +1217,7 @@ def new_chat_input(user_input, chat_history, user_state, attribution_slider, *ar
1198
  "Before we proceed: Have you personally experienced something similar to this scenario before? "
1199
  "Please rate the similarity on a scale from 1 to 10 (1 = Not at all similar, 10 = Extremely similar)."
1200
  )
1201
-
1202
  chat_history[-1] = (user_input, response)
1203
  return (
1204
  chat_history, # Updated chat history
@@ -1270,7 +1289,7 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
1270
  with gr.Column():
1271
  gr.Markdown("""
1272
  # **Information for Participants and Declaration of Consent**
1273
- ##**Evaluating the Validity of LLM-Based Psychological Assessments**
1274
 
1275
  ---
1276
 
@@ -1354,7 +1373,7 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
1354
  pid_output = gr.Markdown()
1355
 
1356
  gr.Markdown("""### Over the last 2 weeks, how often have you been bothered by
1357
- ##'' any of the following problems (0 = "Never", 3 = "Very often")?""")
1358
 
1359
  q1 = gr.Radio(choices=["0", "1", "2", "3"], label="Little interest or pleasure in doing things?", value = "0")
1360
  q2 = gr.Radio(choices=["0", "1", "2", "3"], label="Feeling down, depressed, or hopeless?", value = "0")
@@ -1395,12 +1414,12 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
1395
  with gr.Row(visible=False) as page_4:
1396
  with gr.Column():
1397
  gr.Markdown("# Tell Us About Yourself")
1398
- 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.
1399
 
1400
- ## In order to provide you with situations that might be more relevant to you specifically,
1401
- ## we need some general information about you. Don't worry, you will remain anonymous!
1402
 
1403
- ## Please tell us your age, profession and one of your personal interests.""")
1404
  age_input = gr.Textbox(label="Age", placeholder="Enter your age (e.g., 25)", lines=1)
1405
  profession_input = gr.Textbox(label="Profession", placeholder="Enter your profession (e.g., Engineer)", lines=1)
1406
  interest_input = gr.Textbox(label="One personal interest", placeholder="Enter a hobby or interest (e.g., Painting)", lines=1)
 
129
  # Storing / Uploading Functions
130
  ##############################################################################
131
 
132
+ def generate_custom_vignette(chat_history, topic_choice, desired_tone, user_state, feedback=None):
133
  """
134
  Generates a personalized vignette for psychological assessment based on user preferences, ensuring
135
  that each vignette exclusively reflects the chosen topic (profession or interest) without mixing them.
 
166
  else:
167
  tone_context = "a neutral situation."
168
 
169
+ # If feedback is provided, embed it in the prompt
170
+ feedback_instructions = ""
171
+ if feedback and feedback.strip():
172
+ feedback_instructions = f"""
173
+ The user has provided additional information or critiques about the previous scenario:
174
+ "{feedback}"
175
+
176
+ Please incorporate this feedback to make the scenario more aligned with the user's context.
177
+ """
178
+
179
  # Build a prompt that references ONLY the chosen topic
180
  prompt = f"""
181
  You are tasked with generating a short, personalized vignette for a psychological assessment.
 
198
  - Do not include personal identifying information.
199
  - Do not mention both profession and personal interests together; focus exclusively on the chosen topic.
200
  - Do not mix multiple interests or contexts; stay consistent with the single chosen topic.
201
+
202
+ {feedback_instructions}
203
 
204
  Now generate the vignette:
205
  """
 
406
  chat_history[-1] = (user_input, response)
407
  return chat_history, user_state
408
 
409
+
410
+ ### Slider Function ###############################################################
411
+
412
  def handle_slider(slider_value, chat_history, user_state):
413
  """
414
  Processes the slider input (1-10) depending on the current stage
 
452
  "Now, from 1 to 10, which do you think is more likely? (1 = Definitely Option A, 10 = Definitely Option B)\n\n"
453
  f"{user_state['options_text']}"
454
  )
455
+ chat_history[-1] = ("", response)
456
  # Return the chat + user_state, and keep the slider visible
457
  return (
458
  chat_history, # Updated chat history
 
481
  "Next, from 1 to 10, which do you think is more likely? (1 = Definitely Option A, 10 = Definitely Option B)\n\n"
482
  f"{user_state['options_text']}"
483
  )
484
+ chat_history[-1] = ("", response)
485
  return (
486
  chat_history, # Updated chat history
487
  user_state, # Updated user state
 
515
  "On a scale from 1 to 10, which is more likely? (1 = Definitely Option A, 10 = Definitely Option B)\n"
516
  f"{user_state['options_text']}"
517
  )
518
+ chat_history[-1] = ("", response)
519
  return (
520
  chat_history, # Updated chat history
521
  user_state, # Updated user state
 
1161
  user_state["stage"] = "internal_external"
1162
  user_state['options_text'] = generate_internal_external_options(chat_history, user_state["standardized_data"][f'Vignette'], user_state)
1163
  response = (
1164
+ f"Please read the scenario again and use the slider below to answer the next few questions:\n{user_state['vignette']}\n"
1165
+ "\nImagine this situation is happening to you personally. From 1 to 10, which of the following statements do you think is more likely (1 = Definitely Option A, 10 = Definitely Option B):\n"
1166
  f"{user_state['options_text']}")
1167
  chat_history[-1] = (user_input, response)
1168
  return (
 
1172
  gr.update(visible=True), # Slider
1173
  gr.update(visible=True) # Confirm button
1174
  )
1175
+
1176
  elif user_state["stage"] == "vignette_regeneration":
1177
  additional_info = user_input
1178
+ user_state["user_responses"].append({
1179
+ "user_state['stage']": "vignette_regeneration",
1180
+ "feedback": additional_info
1181
+ })
1182
 
1183
+ # Retrieve current topic choice
1184
  topic_choice = user_state["standardized_data"].get("Topic Choice", user_state["topic_choice"])
1185
  new_interest = user_state["standardized_data"].get("New Interest", None)
1186
 
1187
+ # If topic_choice was "3" + new_interest exists, use that as the topic; else use topic_choice
1188
  if topic_choice == "3" and new_interest:
1189
  topic_choice_for_vignette = new_interest
1190
  else:
1191
  topic_choice_for_vignette = topic_choice
1192
 
1193
+ # Regenerate the vignette, passing user feedback
1194
  user_state["vignette"], user_state["tone"] = generate_custom_vignette(
1195
  chat_history=chat_history,
1196
  topic_choice=topic_choice_for_vignette,
1197
  desired_tone=user_state["desired_tone"],
1198
+ user_state=user_state,
1199
+ feedback=additional_info
1200
  )
1201
 
1202
  user_state["user_responses"].append({
1203
+ 'user_state["stage"]': "vignette_regenerated",
1204
  'content': user_state["vignette"],
1205
  'tone': user_state["tone"]
1206
  })
 
1217
  "Before we proceed: Have you personally experienced something similar to this scenario before? "
1218
  "Please rate the similarity on a scale from 1 to 10 (1 = Not at all similar, 10 = Extremely similar)."
1219
  )
1220
+
1221
  chat_history[-1] = (user_input, response)
1222
  return (
1223
  chat_history, # Updated chat history
 
1289
  with gr.Column():
1290
  gr.Markdown("""
1291
  # **Information for Participants and Declaration of Consent**
1292
+ ## **Evaluating the Validity of LLM-Based Psychological Assessments**
1293
 
1294
  ---
1295
 
 
1373
  pid_output = gr.Markdown()
1374
 
1375
  gr.Markdown("""### Over the last 2 weeks, how often have you been bothered by
1376
+ ## '' any of the following problems (0 = "Never", 3 = "Very often")?""")
1377
 
1378
  q1 = gr.Radio(choices=["0", "1", "2", "3"], label="Little interest or pleasure in doing things?", value = "0")
1379
  q2 = gr.Radio(choices=["0", "1", "2", "3"], label="Feeling down, depressed, or hopeless?", value = "0")
 
1414
  with gr.Row(visible=False) as page_4:
1415
  with gr.Column():
1416
  gr.Markdown("# Tell Us About Yourself")
1417
+ 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.
1418
 
1419
+ ### In order to provide you with situations that might be more relevant to you specifically,
1420
+ ### we need some general information about you. Don't worry, you will remain anonymous!
1421
 
1422
+ ### Please tell us your age, profession and one of your personal interests.""")
1423
  age_input = gr.Textbox(label="Age", placeholder="Enter your age (e.g., 25)", lines=1)
1424
  profession_input = gr.Textbox(label="Profession", placeholder="Enter your profession (e.g., Engineer)", lines=1)
1425
  interest_input = gr.Textbox(label="One personal interest", placeholder="Enter a hobby or interest (e.g., Painting)", lines=1)