Spaces:
Tiliah
/
Runtime error

mojakob commited on
Commit
2cd905e
·
verified ·
1 Parent(s): 6cc24b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -26
app.py CHANGED
@@ -914,9 +914,10 @@ def new_chat_input(chat_history, user_state, user_input, *args, **kwargs):
914
  user_state["stage"] = "internal_external"
915
  user_state['options_text'] = generate_internal_external_options(chat_history, user_state["standardized_data"][f'Vignette'], user_state)
916
  response = (
917
- f"Please read the scenario again and use the slider below to answer the next few questions:\n{user_state['vignette']}\n"
918
- "\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"
919
- f"{user_state['options_text']}")
 
920
  chat_history[-1] = (user_input, response)
921
  return (
922
  chat_history, # Updated chat history
@@ -1353,6 +1354,10 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
1353
  ### - You agree to participate in the study and for your anonymised data to be used for academic research.
1354
  """)
1355
 
 
 
 
 
1356
  # Consent by pressing the button
1357
  briefing_start_button = gr.Button("I Acknowledge and Consent")
1358
 
@@ -1362,11 +1367,7 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
1362
 
1363
  with gr.Row(visible=False) as page_2:
1364
  with gr.Column():
1365
- # PHQ-9
1366
- # gr.Markdown("# Enter Your Prolific ID:")
1367
- pid_input = gr.Textbox(label="Prolific ID (required)")
1368
- pid_output = gr.Markdown()
1369
-
1370
  gr.Markdown("""#### Over the last 2 weeks, how often have you been bothered by
1371
  #### any of the following problems (0 = "Never", 3 = "Very often")?""")
1372
 
@@ -1468,25 +1469,38 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
1468
  ######################################################################
1469
 
1470
  # 1) After Briefing, go to PHQ-9
1471
- def show_phq9(user_state):
1472
- # Hide the briefing page, show the PHQ-9 page
 
 
 
 
 
 
 
 
 
 
 
1473
  return (
 
1474
  gr.update(visible=False), # hide page_1
1475
- gr.update(visible=True), # show page_2 (PHQ-9)
1476
  user_state
1477
  )
1478
 
1479
  briefing_start_button.click(
1480
- fn=show_phq9,
1481
- inputs=[user_state],
1482
  outputs=[
 
1483
  page_1, # hide page_1 (Briefing)
1484
  page_2, # show page_2 (PHQ-9)
1485
  user_state]
1486
  )
1487
 
1488
  # 2) After finishing PHQ-9, go to GAD-7
1489
- def process_phq9_and_show_gad7(pid, q1, q2, q3, q4, q5, q6, q7, q8, q9, user_state):
1490
  q1 = int(q1) if q1 is not None else 0
1491
  q2 = int(q2) if q2 is not None else 0
1492
  q3 = int(q3) if q3 is not None else 0
@@ -1497,22 +1511,12 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
1497
  q8 = int(q8) if q8 is not None else 0
1498
  q9 = int(q9) if q9 is not None else 0
1499
 
1500
- pid = pid.strip()
1501
- if not pid:
1502
- # If Prolific ID is missing, show an error & keep Page 2 visible
1503
- return (
1504
- "Error: Please enter your Prolific ID.",
1505
- gr.update(visible=True), # Keep page_2 visible
1506
- gr.update(visible=False), # Keep page_3 hidden
1507
- user_state
1508
- )
1509
  # Store ID & compute PHQ-9
1510
- user_state["prolific_id"] = pid
1511
  user_state["phq_score"] = q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8 + q9
1512
 
1513
  # On success, hide Page 2 & show Page 3
1514
  return (
1515
- f"Prolific ID {pid} recorded. PHQ-9 total = {user_state['phq_score']}. Proceed to GAD-7.",
1516
  gr.update(visible=False), # Hide page_2
1517
  gr.update(visible=True), # Show page_3
1518
  user_state
@@ -1520,7 +1524,7 @@ with gr.Blocks(theme= gr.themes.Glass(), css=css) as app:
1520
 
1521
  next_button.click(
1522
  fn=process_phq9_and_show_gad7,
1523
- inputs=[pid_input, q1, q2, q3, q4, q5, q6, q7, q8, q9, user_state],
1524
  outputs=[
1525
  phq_result,
1526
  page_2, # hide page_2 (PHQ-9)
 
914
  user_state["stage"] = "internal_external"
915
  user_state['options_text'] = generate_internal_external_options(chat_history, user_state["standardized_data"][f'Vignette'], user_state)
916
  response = (
917
+ f"Please read the scenario again and use the slider below to answer the next few questions:\n"
918
+ f"\n{user_state['vignette']}\n"
919
+ "\nImagine this situation is happening to you personally. \nFrom 1 to 10, which of the following statements do you think is more likely (1 = Definitely Option A, 10 = Definitely Option B):\n"
920
+ f"\n{user_state['options_text']}")
921
  chat_history[-1] = (user_input, response)
922
  return (
923
  chat_history, # Updated chat history
 
1354
  ### - You agree to participate in the study and for your anonymised data to be used for academic research.
1355
  """)
1356
 
1357
+ gr.Markdown("### Please enter your Prolific ID before moving on:")
1358
+ pid_input = gr.Textbox(label="Prolific ID (required)")
1359
+ pid_output = gr.Markdown()
1360
+
1361
  # Consent by pressing the button
1362
  briefing_start_button = gr.Button("I Acknowledge and Consent")
1363
 
 
1367
 
1368
  with gr.Row(visible=False) as page_2:
1369
  with gr.Column():
1370
+ # PHQ-9
 
 
 
 
1371
  gr.Markdown("""#### Over the last 2 weeks, how often have you been bothered by
1372
  #### any of the following problems (0 = "Never", 3 = "Very often")?""")
1373
 
 
1469
  ######################################################################
1470
 
1471
  # 1) After Briefing, go to PHQ-9
1472
+ def store_pid_and_show_phq9(pid, user_state):
1473
+ # 1) Validate the PID
1474
+ pid = pid.strip()
1475
+ if not pid:
1476
+ return (
1477
+ "Error: Please enter your Prolific ID.",
1478
+ gr.update(visible=True), # keep page_1 visible
1479
+ gr.update(visible=False), # keep page_2 hidden
1480
+ user_state
1481
+ )
1482
+ # 2) Store the PID
1483
+ user_state["prolific_id"] = pid
1484
+ # 3) Hide page_1, show page_2
1485
  return (
1486
+ f"Prolific ID {pid} recorded, now proceed to PHQ-9.",
1487
  gr.update(visible=False), # hide page_1
1488
+ gr.update(visible=True), # show page_2
1489
  user_state
1490
  )
1491
 
1492
  briefing_start_button.click(
1493
+ fn=store_pid_and_show_phq9,
1494
+ inputs=[pid_input, user_state],
1495
  outputs=[
1496
+ pid_output,
1497
  page_1, # hide page_1 (Briefing)
1498
  page_2, # show page_2 (PHQ-9)
1499
  user_state]
1500
  )
1501
 
1502
  # 2) After finishing PHQ-9, go to GAD-7
1503
+ def process_phq9_and_show_gad7(q1, q2, q3, q4, q5, q6, q7, q8, q9, user_state):
1504
  q1 = int(q1) if q1 is not None else 0
1505
  q2 = int(q2) if q2 is not None else 0
1506
  q3 = int(q3) if q3 is not None else 0
 
1511
  q8 = int(q8) if q8 is not None else 0
1512
  q9 = int(q9) if q9 is not None else 0
1513
 
 
 
 
 
 
 
 
 
 
1514
  # Store ID & compute PHQ-9
 
1515
  user_state["phq_score"] = q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8 + q9
1516
 
1517
  # On success, hide Page 2 & show Page 3
1518
  return (
1519
+ f"PHQ-9 total = {user_state['phq_score']}. Proceed to GAD-7.",
1520
  gr.update(visible=False), # Hide page_2
1521
  gr.update(visible=True), # Show page_3
1522
  user_state
 
1524
 
1525
  next_button.click(
1526
  fn=process_phq9_and_show_gad7,
1527
+ inputs=[q1, q2, q3, q4, q5, q6, q7, q8, q9, user_state],
1528
  outputs=[
1529
  phq_result,
1530
  page_2, # hide page_2 (PHQ-9)