Spaces:
Runtime error
Runtime error
Update app.py
Browse filesFully functional version
app.py
CHANGED
|
@@ -135,26 +135,28 @@ pickle_file = "assessment_data.pkl"
|
|
| 135 |
# Make sure your Excel file has the PHQ/GAD columns:
|
| 136 |
if not os.path.exists(excel_file):
|
| 137 |
pd.DataFrame(columns=[
|
| 138 |
-
'
|
| 139 |
'Vignette Number', 'Vignette', 'Tone', 'First Reveal', 'Initial Internal',
|
| 140 |
'Initial External', 'Initial Stable', 'Initial Unstable', 'Initial Global',
|
| 141 |
'Initial Specific', 'Reassessment Internal', 'Reassessment External',
|
| 142 |
'Initial Relevance Rating', 'Final Relevance Rating', 'Emotional Relevance',
|
| 143 |
-
'Positive Valence', 'Negative Valence', 'Likelihood of Change',
|
| 144 |
-
|
|
|
|
| 145 |
]).to_excel(excel_file, index=False, engine="openpyxl")
|
| 146 |
|
| 147 |
|
| 148 |
# Same for the pickle file:
|
| 149 |
if not os.path.exists(pickle_file):
|
| 150 |
pd.DataFrame(columns=[
|
| 151 |
-
'
|
| 152 |
'Vignette Number', 'Vignette', 'Tone', 'First Reveal', 'Initial Internal',
|
| 153 |
'Initial External', 'Initial Stable', 'Initial Unstable', 'Initial Global',
|
| 154 |
'Initial Specific', 'Reassessment Internal', 'Reassessment External',
|
| 155 |
'Initial Relevance Rating', 'Final Relevance Rating', 'Emotional Relevance',
|
| 156 |
-
'Positive Valence', 'Negative Valence', 'Likelihood of Change',
|
| 157 |
-
|
|
|
|
| 158 |
]).to_pickle(pickle_file)
|
| 159 |
|
| 160 |
##############################################################################
|
|
@@ -207,7 +209,15 @@ app_state = {
|
|
| 207 |
"topic_choice": None,
|
| 208 |
"options_text": None,
|
| 209 |
"desired_tone": None,
|
| 210 |
-
"usability_question_counter": 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
}
|
| 212 |
|
| 213 |
|
|
@@ -368,22 +378,6 @@ def save_to_excel(new_row):
|
|
| 368 |
# Load the existing DataFrame
|
| 369 |
df = pd.read_excel(excel_file, engine="openpyxl")
|
| 370 |
|
| 371 |
-
# Ensure 'Prolific ID' column exists
|
| 372 |
-
if 'Prolific ID' not in df.columns:
|
| 373 |
-
print("Columns in the Excel file:", df.columns.tolist())
|
| 374 |
-
print("Adding missing 'Prolific ID' column.")
|
| 375 |
-
df['Prolific ID'] = None # Add with default value
|
| 376 |
-
# raise KeyError("The 'Prolific ID' column is missing in the Excel file.")
|
| 377 |
-
|
| 378 |
-
# Check if the participant's ID already exists
|
| 379 |
-
participant_id = new_row.get("Prolific ID")
|
| 380 |
-
if participant_id in df["Prolific ID"].values:
|
| 381 |
-
# Update the row for the existing participant
|
| 382 |
-
df.loc[df["Prolific ID"] == participant_id] = new_row
|
| 383 |
-
else:
|
| 384 |
-
# Add a new row for this participant
|
| 385 |
-
df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True)
|
| 386 |
-
|
| 387 |
# Save the updated DataFrame
|
| 388 |
print("New row data being saved:", new_row)
|
| 389 |
print("App state before saving:", app_state)
|
|
@@ -555,11 +549,13 @@ def new_chat_input(message, history, *args, **kwargs):
|
|
| 555 |
#save_to_pickle(app_state["standardized_data"])
|
| 556 |
#save_to_excel(app_state["standardized_data"])
|
| 557 |
feedback_questions = [
|
| 558 |
-
"
|
|
|
|
|
|
|
| 559 |
"How clear were the instructions? (1 = Not at all, 10 = Very much)",
|
| 560 |
"How engaging was the assessment experience? (1 = Not at all, 10 = Very much)",
|
| 561 |
"How satisfied are you with this assessment? (1 = Not at all, 10 = Very much)",
|
| 562 |
-
"How mentally demanding was the assessment? (1 = Not at all, 10 = Very much)"
|
| 563 |
]
|
| 564 |
|
| 565 |
# Initialize counter only once
|
|
@@ -570,15 +566,37 @@ def new_chat_input(message, history, *args, **kwargs):
|
|
| 570 |
if app_state["usability_question_counter"] >= len(feedback_questions):
|
| 571 |
app_state["stage"] = "completed"
|
| 572 |
save_to_excel({
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 582 |
})
|
| 583 |
return "Thank you for your feedback! Please use the following link to submit your results: https://app.prolific.com/submissions/complete?cc=CBQG85HO"
|
| 584 |
|
|
@@ -599,7 +617,7 @@ def new_chat_input(message, history, *args, **kwargs):
|
|
| 599 |
"Satisfaction",
|
| 600 |
"Cognitive Load"
|
| 601 |
][app_state["usability_question_counter"]]
|
| 602 |
-
app_state["
|
| 603 |
|
| 604 |
# Move to the next question
|
| 605 |
app_state["usability_question_counter"] += 1
|
|
@@ -610,6 +628,39 @@ def new_chat_input(message, history, *args, **kwargs):
|
|
| 610 |
|
| 611 |
# If all questions are complete, transition to the next stage
|
| 612 |
app_state["stage"] = "completed"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 613 |
return "Thank you for your feedback! Please use the following link to submit your results: https://app.prolific.com/submissions/complete?cc=CBQG85HO"
|
| 614 |
|
| 615 |
# elif app_state["stage"] == "usability_response":
|
|
@@ -983,8 +1034,8 @@ Considering these new developments, please select which of these options seems m
|
|
| 983 |
app_state["stage"] = "topic_choice"
|
| 984 |
# save_to_pickle(app_state["standardized_data"])
|
| 985 |
# save_to_excel(app_state["standardized_data"])
|
| 986 |
-
|
| 987 |
-
|
| 988 |
return f"Thank you! We are now finished with scene {app_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...')"
|
| 989 |
else:
|
| 990 |
print(f"Unexpected app_state or input: stage={app_state['stage']}, message={message}")
|
|
|
|
| 135 |
# Make sure your Excel file has the PHQ/GAD columns:
|
| 136 |
if not os.path.exists(excel_file):
|
| 137 |
pd.DataFrame(columns=[
|
| 138 |
+
'Prolific ID', 'Age', 'Profession', 'Interests', 'Topic Choice',
|
| 139 |
'Vignette Number', 'Vignette', 'Tone', 'First Reveal', 'Initial Internal',
|
| 140 |
'Initial External', 'Initial Stable', 'Initial Unstable', 'Initial Global',
|
| 141 |
'Initial Specific', 'Reassessment Internal', 'Reassessment External',
|
| 142 |
'Initial Relevance Rating', 'Final Relevance Rating', 'Emotional Relevance',
|
| 143 |
+
'Positive Valence', 'Negative Valence', 'Likelihood of Change', "Ease of Use",
|
| 144 |
+
"Clarity of Instructions", "Engagement Level", "Satisfaction with Assessment",
|
| 145 |
+
"Cognitive Load", "Additional Comments", 'PHQ-9 Score', 'GAD-7 Score'
|
| 146 |
]).to_excel(excel_file, index=False, engine="openpyxl")
|
| 147 |
|
| 148 |
|
| 149 |
# Same for the pickle file:
|
| 150 |
if not os.path.exists(pickle_file):
|
| 151 |
pd.DataFrame(columns=[
|
| 152 |
+
'Prolific ID', 'Age', 'Profession', 'Interests', 'Topic Choice',
|
| 153 |
'Vignette Number', 'Vignette', 'Tone', 'First Reveal', 'Initial Internal',
|
| 154 |
'Initial External', 'Initial Stable', 'Initial Unstable', 'Initial Global',
|
| 155 |
'Initial Specific', 'Reassessment Internal', 'Reassessment External',
|
| 156 |
'Initial Relevance Rating', 'Final Relevance Rating', 'Emotional Relevance',
|
| 157 |
+
'Positive Valence', 'Negative Valence', 'Likelihood of Change', "Ease of Use",
|
| 158 |
+
"Clarity of Instructions", "Engagement Level", "Satisfaction with Assessment",
|
| 159 |
+
"Cognitive Load", "Additional Comments", 'PHQ-9 Score', 'GAD-7 Score'
|
| 160 |
]).to_pickle(pickle_file)
|
| 161 |
|
| 162 |
##############################################################################
|
|
|
|
| 209 |
"topic_choice": None,
|
| 210 |
"options_text": None,
|
| 211 |
"desired_tone": None,
|
| 212 |
+
"usability_question_counter": 0,
|
| 213 |
+
"usability_feedback": {
|
| 214 |
+
"Ease of Use": None,
|
| 215 |
+
"Clarity of Instructions": None,
|
| 216 |
+
"Engagement Level": None,
|
| 217 |
+
"Satisfaction with Assessment": None,
|
| 218 |
+
"Cognitive Load": None,
|
| 219 |
+
"Additional Comments": None
|
| 220 |
+
}
|
| 221 |
}
|
| 222 |
|
| 223 |
|
|
|
|
| 378 |
# Load the existing DataFrame
|
| 379 |
df = pd.read_excel(excel_file, engine="openpyxl")
|
| 380 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
# Save the updated DataFrame
|
| 382 |
print("New row data being saved:", new_row)
|
| 383 |
print("App state before saving:", app_state)
|
|
|
|
| 549 |
#save_to_pickle(app_state["standardized_data"])
|
| 550 |
#save_to_excel(app_state["standardized_data"])
|
| 551 |
feedback_questions = [
|
| 552 |
+
"""Thank you for completing all the scenarios. We just have a few more questions before you leave.
|
| 553 |
+
|
| 554 |
+
How easy was it to complete the assessment? (1 = Not at all, 10 = Very much)""",
|
| 555 |
"How clear were the instructions? (1 = Not at all, 10 = Very much)",
|
| 556 |
"How engaging was the assessment experience? (1 = Not at all, 10 = Very much)",
|
| 557 |
"How satisfied are you with this assessment? (1 = Not at all, 10 = Very much)",
|
| 558 |
+
"How mentally demanding was the assessment? (1 = Not at all, 10 = Very much)",
|
| 559 |
]
|
| 560 |
|
| 561 |
# Initialize counter only once
|
|
|
|
| 566 |
if app_state["usability_question_counter"] >= len(feedback_questions):
|
| 567 |
app_state["stage"] = "completed"
|
| 568 |
save_to_excel({
|
| 569 |
+
'Prolific ID': app_state["prolific_id"],
|
| 570 |
+
'Age': app_state["standardized_data"].get("Age", None),
|
| 571 |
+
'Profession': app_state["standardized_data"].get("Profession", None),
|
| 572 |
+
'Interests': app_state["standardized_data"].get("Interests", None),
|
| 573 |
+
'Topic Choice': app_state["standardized_data"].get("Topic Choice", None),
|
| 574 |
+
'Vignette Number': app_state["standardized_data"].get("Vignette Number", None),
|
| 575 |
+
'Vignette': app_state["standardized_data"].get("Vignette", None),
|
| 576 |
+
'Tone': app_state["standardized_data"].get("Tone", None),
|
| 577 |
+
'First Reveal': app_state["standardized_data"].get("First Reveal", None),
|
| 578 |
+
'Initial Internal': app_state["standardized_data"].get("Initial Internal", None),
|
| 579 |
+
'Initial External': app_state["standardized_data"].get("Initial External", None),
|
| 580 |
+
'Initial Stable': app_state["standardized_data"].get("Initial Stable", None),
|
| 581 |
+
'Initial Unstable': app_state["standardized_data"].get("Initial Unstable", None),
|
| 582 |
+
'Initial Global': app_state["standardized_data"].get("Initial Global", None),
|
| 583 |
+
'Initial Specific': app_state["standardized_data"].get("Initial Specific", None),
|
| 584 |
+
'Reassessment Internal': app_state["standardized_data"].get("Reassessment Internal", None),
|
| 585 |
+
'Reassessment External': app_state["standardized_data"].get("Reassessment External", None),
|
| 586 |
+
'Initial Relevance Rating': app_state["standardized_data"].get("Initial Relevance Rating", None),
|
| 587 |
+
'Final Relevance Rating': app_state["standardized_data"].get("Final Relevance Rating", None),
|
| 588 |
+
'Emotional Relevance': app_state["standardized_data"].get("Emotional Relevance", None),
|
| 589 |
+
'Positive Valence': app_state["standardized_data"].get("Positive Valence", None),
|
| 590 |
+
'Negative Valence': app_state["standardized_data"].get("Negative Valence", None),
|
| 591 |
+
'Likelihood of Change': app_state["standardized_data"].get("Likelihood of Change", None),
|
| 592 |
+
"Ease of Use": app_state["standardized_data"].get("Ease of Use", None),
|
| 593 |
+
"Clarity of Instructions": app_state["standardized_data"].get("Clarity of Instructions", None),
|
| 594 |
+
"Engagement Level": app_state["standardized_data"].get("Engagement Level", None),
|
| 595 |
+
"Satisfaction with Assessment": app_state["standardized_data"].get("Satisfaction with Assessment", None),
|
| 596 |
+
"Cognitive Load": app_state["standardized_data"].get("Cognitive Load", None),
|
| 597 |
+
"Additional Comments": app_state["standardized_data"].get("Additional Comments", None),
|
| 598 |
+
'PHQ-9 Score': app_state["phq_score"],
|
| 599 |
+
'GAD-7 Score': app_state["gad_score"]
|
| 600 |
})
|
| 601 |
return "Thank you for your feedback! Please use the following link to submit your results: https://app.prolific.com/submissions/complete?cc=CBQG85HO"
|
| 602 |
|
|
|
|
| 617 |
"Satisfaction",
|
| 618 |
"Cognitive Load"
|
| 619 |
][app_state["usability_question_counter"]]
|
| 620 |
+
app_state["usability_feedback"][question_key] = standardized_response
|
| 621 |
|
| 622 |
# Move to the next question
|
| 623 |
app_state["usability_question_counter"] += 1
|
|
|
|
| 628 |
|
| 629 |
# If all questions are complete, transition to the next stage
|
| 630 |
app_state["stage"] = "completed"
|
| 631 |
+
save_to_excel({
|
| 632 |
+
'Prolific ID': app_state["prolific_id"],
|
| 633 |
+
'Age': app_state["standardized_data"].get("Age", None),
|
| 634 |
+
'Profession': app_state["standardized_data"].get("Profession", None),
|
| 635 |
+
'Interests': app_state["standardized_data"].get("Interests", None),
|
| 636 |
+
'Topic Choice': app_state["standardized_data"].get("Topic Choice", None),
|
| 637 |
+
'Vignette Number': app_state["standardized_data"].get("Vignette Number", None),
|
| 638 |
+
'Vignette': app_state["standardized_data"].get("Vignette", None),
|
| 639 |
+
'Tone': app_state["standardized_data"].get("Tone", None),
|
| 640 |
+
'First Reveal': app_state["standardized_data"].get("First Reveal", None),
|
| 641 |
+
'Initial Internal': app_state["standardized_data"].get("Initial Internal", None),
|
| 642 |
+
'Initial External': app_state["standardized_data"].get("Initial External", None),
|
| 643 |
+
'Initial Stable': app_state["standardized_data"].get("Initial Stable", None),
|
| 644 |
+
'Initial Unstable': app_state["standardized_data"].get("Initial Unstable", None),
|
| 645 |
+
'Initial Global': app_state["standardized_data"].get("Initial Global", None),
|
| 646 |
+
'Initial Specific': app_state["standardized_data"].get("Initial Specific", None),
|
| 647 |
+
'Reassessment Internal': app_state["standardized_data"].get("Reassessment Internal", None),
|
| 648 |
+
'Reassessment External': app_state["standardized_data"].get("Reassessment External", None),
|
| 649 |
+
'Initial Relevance Rating': app_state["standardized_data"].get("Initial Relevance Rating", None),
|
| 650 |
+
'Final Relevance Rating': app_state["standardized_data"].get("Final Relevance Rating", None),
|
| 651 |
+
'Emotional Relevance': app_state["standardized_data"].get("Emotional Relevance", None),
|
| 652 |
+
'Positive Valence': app_state["standardized_data"].get("Positive Valence", None),
|
| 653 |
+
'Negative Valence': app_state["standardized_data"].get("Negative Valence", None),
|
| 654 |
+
'Likelihood of Change': app_state["standardized_data"].get("Likelihood of Change", None),
|
| 655 |
+
"Ease of Use": app_state["standardized_data"].get("Ease of Use", None),
|
| 656 |
+
"Clarity of Instructions": app_state["standardized_data"].get("Clarity of Instructions", None),
|
| 657 |
+
"Engagement Level": app_state["standardized_data"].get("Engagement Level", None),
|
| 658 |
+
"Satisfaction with Assessment": app_state["standardized_data"].get("Satisfaction with Assessment", None),
|
| 659 |
+
"Cognitive Load": app_state["standardized_data"].get("Cognitive Load", None),
|
| 660 |
+
"Additional Comments": app_state["standardized_data"].get("Additional Comments", None),
|
| 661 |
+
'PHQ-9 Score': app_state["phq_score"],
|
| 662 |
+
'GAD-7 Score': app_state["gad_score"]
|
| 663 |
+
})
|
| 664 |
return "Thank you for your feedback! Please use the following link to submit your results: https://app.prolific.com/submissions/complete?cc=CBQG85HO"
|
| 665 |
|
| 666 |
# elif app_state["stage"] == "usability_response":
|
|
|
|
| 1034 |
app_state["stage"] = "topic_choice"
|
| 1035 |
# save_to_pickle(app_state["standardized_data"])
|
| 1036 |
# save_to_excel(app_state["standardized_data"])
|
| 1037 |
+
# app_state["standardized_data"] = {} # Clear standardized data for the next vignette
|
| 1038 |
+
# app_state["standardized_data"]['Prolific ID'] = app_state["prolific_id"]
|
| 1039 |
return f"Thank you! We are now finished with scene {app_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...')"
|
| 1040 |
else:
|
| 1041 |
print(f"Unexpected app_state or input: stage={app_state['stage']}, message={message}")
|