Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,166 +17,36 @@ from pathlib import Path
|
|
| 17 |
from fsspec.implementations.local import LocalFileSystem
|
| 18 |
from huggingface_hub import HfFileSystem
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Function to get user ID from URL
|
| 34 |
def get_param_from_url(param):
|
| 35 |
user_id = st.query_params.get(param, "")
|
| 36 |
return user_id
|
| 37 |
|
| 38 |
-
|
| 39 |
-
########################################################################################
|
| 40 |
-
|
| 41 |
# 'local' or 'hf'. hf is for Hugging Face file system but has limits on the number of access per hour
|
| 42 |
filesystem = 'hf'
|
| 43 |
input_repo_path = 'datasets/emvecchi/therapy_annotation'
|
| 44 |
output_repo_path = 'datasets/emvecchi/therapy_annotation/pilot'
|
| 45 |
|
| 46 |
to_annotate_file_name = 'to_annotate.csv' # CSV file to annotate
|
| 47 |
-
COLS_TO_SAVE = ['dialogue_id','dialogue_name','generatedPatient']
|
| 48 |
-
|
| 49 |
-
agreement_labels = ['strongly disagree', 'disagree', 'neither agree no disagree', 'agree', 'strongly agree']
|
| 50 |
-
mentioned_y_n = ['yes, explicitly', 'yes, implicitly', 'no', 'not sure', 'other']
|
| 51 |
-
degree_labels = ['not at all', 'slightly', 'moderately', 'very much', 'extremely']
|
| 52 |
-
quality_labels = ['very poor', 'poor', 'acceptable', 'good', 'very good']
|
| 53 |
-
priority_labels = ['not a priority', 'low priority', 'neutral', 'moderate priority', 'high priority']
|
| 54 |
-
yes_no_labels = ['no','yes']
|
| 55 |
-
yes_no_other_labels = ['no','yes','other']
|
| 56 |
-
default_labels = agreement_labels
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
consent_text = '''
|
| 60 |
-
## Consent Form
|
| 61 |
-
You will be asked to take part in a research study. Before you decide to take part in this study, it is important that you understand why the study is being done and what it involves. Please read the following information carefully.
|
| 62 |
-
________________________________________________________________________________________
|
| 63 |
-
Project title: [...]\\
|
| 64 |
-
Researchers: [...]\\
|
| 65 |
-
Institute: Institute for Machine Speech Processing (IMS)\\
|
| 66 |
-
University: University of Stuttgart\\
|
| 67 |
-
Contact: eva-maria.vecchi@ims.uni-stuttgart.de
|
| 68 |
-
_________________________________________________________________________________________
|
| 69 |
-
### Description of the research study
|
| 70 |
-
|
| 71 |
-
In this study, we investigate [...]
|
| 72 |
-
|
| 73 |
-
The intended use of the results of this study includes [...]
|
| 74 |
-
|
| 75 |
-
**Time required:** Your participation will take up to an estimated [...] hours. The time required may vary on an individual basis.
|
| 76 |
-
|
| 77 |
-
**Risks and benefits:** The risks to your participation in this online survey are those associated with basic computer tasks, including boredom, fatigue, mild stress, or breach of confidentiality. Some of the topics discussed in the online posts to be annotated may include violence, suicide or rape. The only benefit to you is the learning experience from participating in a research study. The benefit to society is the contribution to scientific knowledge
|
| 78 |
-
|
| 79 |
-
**Compensation:** You will be compensated for participating in this study. If you are interested, we will also be more than happy to share more information about our research with you.
|
| 80 |
-
|
| 81 |
-
**Voluntary participation:** Your participation in this study is voluntary. It is your decision whether or not to participate in this study. If you decide to participate in this study, you will be asked to confirm this consent form ("I agree."). Even after signing the consent form, you can withdraw from participation at any time and without giving any reason. Partial data will not be analysed.
|
| 82 |
-
|
| 83 |
-
**Confidentiality:** Your responses to this experiment will be anonymous. Please do not share any
|
| 84 |
-
|
| 85 |
-
Information that can be used to identify you. The researcher(s) will make every effort to maintain your confidentiality.
|
| 86 |
-
|
| 87 |
-
**Contact:** If at any time you have questions about this study or would like to report any adverse effects due to this study, please contact the researcher(s).
|
| 88 |
-
|
| 89 |
-
**Trigger Warning:** [...]
|
| 90 |
-
|
| 91 |
-
### Consent:
|
| 92 |
-
Please indicate, in the box below, that you are at least 18 years old, have read and understood this consent form, are comfortable using the English and German languages to complete the survey, and you agree to participate in this online research survey.
|
| 93 |
-
- *I am age 18 or older.*
|
| 94 |
-
- *I have read this consent form or had it read to me.*
|
| 95 |
-
- *I am comfortable using the English language to participate in this survey.*
|
| 96 |
-
- *I agree to participate in this research and I want to continue with the survey.*
|
| 97 |
-
'''
|
| 98 |
-
|
| 99 |
-
fields0: List[Field] = [
|
| 100 |
-
Field(name="patient", type="input_col", title=" "),
|
| 101 |
-
Field(type="markdown", title="", mandatory=False, other_params={"use_dialogue_name": True}),
|
| 102 |
-
]
|
| 103 |
-
fields1: List[Field] = [
|
| 104 |
-
Field(type="expander", title="**Session Transcription:** *(expand)*", children=[
|
| 105 |
-
Field(name="dialogue_name", type="input_col", title=""),
|
| 106 |
-
]),
|
| 107 |
-
|
| 108 |
-
Field(type="container", title="##### Session-/Patient-Specific Properties", children=[
|
| 109 |
-
Field(name="diagnosis", type="likert_radio",
|
| 110 |
-
title="Is there mention of a specific [possible] clinical diagnosis?", other_params={'labels': mentioned_y_n}, mandatory=True),
|
| 111 |
-
Field(name="stressor", type="likert_radio",
|
| 112 |
-
title="Does the patient mention sources of psychological pressure that contribute to the development or worsening of the patient's state?",
|
| 113 |
-
other_params={'labels': mentioned_y_n}, mandatory=True),
|
| 114 |
-
]),
|
| 115 |
-
|
| 116 |
-
Field(type="container", title="#### True-To-Patient-Prompt Features", children=[
|
| 117 |
-
Field(type="expander", title="**Patient Role Description:** *(expand)*", children=[
|
| 118 |
-
Field(name="role_name", type="input_col", title=""),
|
| 119 |
-
]),
|
| 120 |
-
Field(name="emotion", type="likert_radio",
|
| 121 |
-
title="To what extent did the simulated patient’s emotional expressions (e.g., frustration, sadness, guardedness) align with those expected for this role?",
|
| 122 |
-
other_params={"labels": degree_labels}, mandatory=True),
|
| 123 |
-
Field(name="conversationalStyle", type="likert_radio",
|
| 124 |
-
title="How well did the patient consistently exhibit the conversational style they were assigned, and did this feel realistic compared to actual patients with this style?",
|
| 125 |
-
other_params={"labels": degree_labels}, mandatory=True),
|
| 126 |
-
Field(name="maladaptive", type="likert_radio",
|
| 127 |
-
title="How accurately did the patient’s statements reflect distorted thoughts consistent with the underlying cognitive model?",
|
| 128 |
-
other_params={"labels": degree_labels}, mandatory=True),
|
| 129 |
-
Field(name="fidelity", type="likert_radio",
|
| 130 |
-
title="Overall, how closely did the patient reflect real patients in terms of realism, variability, and challenge during the session?",
|
| 131 |
-
other_params={"labels": degree_labels}, mandatory=True),
|
| 132 |
-
]),
|
| 133 |
-
|
| 134 |
-
Field(type="container", title="#### Interpersonal therapeutic competence", children=[
|
| 135 |
-
Field(name="v_expressiveness", type="likert_radio",
|
| 136 |
-
title="**Verbal expressiveness.** How fluent, clear, and confident is the person’s verbal communication (regardless of content)?",
|
| 137 |
-
other_params={'labels': ['Very unclear','Unclear','Average','Clear','Very Clear']},
|
| 138 |
-
mandatory=True, following_mandatory_values=[1]),
|
| 139 |
-
Field(name="hope", type="likert_radio",
|
| 140 |
-
title="**Hope and positive expectation.** To what extent does the person convey optimism, confidence, and positive expectations for the patient’s future or therapy?",
|
| 141 |
-
other_params={'labels': ['Hopeless','Discouraging','Neutral','Hopeful','Very hopeful']},
|
| 142 |
-
mandatory=True, following_mandatory_values=[1]),
|
| 143 |
-
Field(name="credible", type="likert_radio",
|
| 144 |
-
title="**Ability to be credible and convincing.** How credible and convincing is the person when presenting a new perspective or interpretation to the patient?",
|
| 145 |
-
other_params={'labels': ['Unconvincing','Weak','Neutral','Convincing','Very convincing']},
|
| 146 |
-
mandatory=True, following_mandatory_values=[1]),
|
| 147 |
-
Field(name="e_expressiveness", type="likert_radio",
|
| 148 |
-
title="**Emotional expressiveness.** How well does the person’s voice and manner convey emotional engagement and intensity (without being hostile)?",
|
| 149 |
-
other_params={'labels': ['Flat','Low','Moderate','Expressive','Very expressive']},
|
| 150 |
-
mandatory=True, following_mandatory_values=[1]),
|
| 151 |
-
Field(name="acceptance", type="likert_radio",
|
| 152 |
-
title="**Acceptance, understanding, and warmth.** To what extent does the person show care, acceptance, and warmth toward the patient (without judgment)?",
|
| 153 |
-
other_params={'labels': ['Cold','Limited','Neutral','Warm','Very warm']},
|
| 154 |
-
mandatory=True, following_mandatory_values=[1]),
|
| 155 |
-
Field(name="empathy", type="likert_radio",
|
| 156 |
-
title="**Empathy.** How well does the person demonstrate an accurate, deeper understanding of the patient’s subjective experience?",
|
| 157 |
-
other_params={'labels': ['Distorted','Superficial','Partial','Accurate','Deep']},
|
| 158 |
-
mandatory=True, following_mandatory_values=[1]),
|
| 159 |
-
Field(name="alliance", type="likert_radio",
|
| 160 |
-
title="**Ability to form alliances.** How effectively does the person create a collaborative “working together” atmosphere with the patient?",
|
| 161 |
-
other_params={'labels': ['Blocking','Weak','Moderate','Cooperative','Strong']},
|
| 162 |
-
mandatory=True, following_mandatory_values=[1]),
|
| 163 |
-
Field(name="tensions", type="likert_radio",
|
| 164 |
-
title="**Addressing tensions and crises.** How effectively does the person acknowledge and work through interpersonal tensions or crises in the interaction?",
|
| 165 |
-
other_params={'labels': ['Avoiding','Poor','Partial','Productive','Resolving']},
|
| 166 |
-
mandatory=True, following_mandatory_values=[1]),
|
| 167 |
-
]),
|
| 168 |
-
|
| 169 |
-
Field(type="container", title="##### Additional Comments *(optional)*", children=[
|
| 170 |
-
Field(name="other_comments", type="text", title="Please provide any additional details or information:", mandatory=False),
|
| 171 |
-
]),
|
| 172 |
-
]
|
| 173 |
|
| 174 |
-
STEPS: List[List[Field]] = [fields0, fields1]
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
# title="*I am uncomfortable annotating this text and voluntarily skip this instance*", mandatory=False)
|
| 179 |
-
#]
|
| 180 |
INPUT_FIELD_DEFAULT_VALUES = {'slider': 0,
|
| 181 |
'text': '',
|
| 182 |
'textarea': '',
|
|
@@ -189,8 +59,6 @@ INPUT_FIELD_DEFAULT_VALUES = {'slider': 0,
|
|
| 189 |
SHOW_HELP_ICON = False
|
| 190 |
SHOW_VALIDATION_ERROR_MESSAGE = True
|
| 191 |
|
| 192 |
-
|
| 193 |
-
|
| 194 |
########################################################################################
|
| 195 |
if filesystem == 'hf':
|
| 196 |
HF_TOKEN = os.environ.get("HF_TOKEN_WRITE")
|
|
|
|
| 17 |
from fsspec.implementations.local import LocalFileSystem
|
| 18 |
from huggingface_hub import HfFileSystem
|
| 19 |
|
| 20 |
+
from annotation_questions import (
|
| 21 |
+
Field,
|
| 22 |
+
STEPS,
|
| 23 |
+
INPUT_FIELD_DEFAULT_VALUES,
|
| 24 |
+
COLS_TO_SAVE,
|
| 25 |
+
consent_text,
|
| 26 |
+
SHOW_HELP_ICON,
|
| 27 |
+
SHOW_VALIDATION_ERROR_MESSAGE,
|
| 28 |
+
yes_no_labels, # if you still use these in y_n_radio
|
| 29 |
+
default_labels # if you still use this fallback
|
| 30 |
+
# plus any others you rely on in app.py
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
########################################################################################
|
| 34 |
|
| 35 |
# Function to get user ID from URL
|
| 36 |
def get_param_from_url(param):
|
| 37 |
user_id = st.query_params.get(param, "")
|
| 38 |
return user_id
|
| 39 |
|
|
|
|
|
|
|
|
|
|
| 40 |
# 'local' or 'hf'. hf is for Hugging Face file system but has limits on the number of access per hour
|
| 41 |
filesystem = 'hf'
|
| 42 |
input_repo_path = 'datasets/emvecchi/therapy_annotation'
|
| 43 |
output_repo_path = 'datasets/emvecchi/therapy_annotation/pilot'
|
| 44 |
|
| 45 |
to_annotate_file_name = 'to_annotate.csv' # CSV file to annotate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
|
|
|
| 47 |
|
| 48 |
+
STEPS = get_steps()
|
| 49 |
+
|
|
|
|
|
|
|
| 50 |
INPUT_FIELD_DEFAULT_VALUES = {'slider': 0,
|
| 51 |
'text': '',
|
| 52 |
'textarea': '',
|
|
|
|
| 59 |
SHOW_HELP_ICON = False
|
| 60 |
SHOW_VALIDATION_ERROR_MESSAGE = True
|
| 61 |
|
|
|
|
|
|
|
| 62 |
########################################################################################
|
| 63 |
if filesystem == 'hf':
|
| 64 |
HF_TOKEN = os.environ.get("HF_TOKEN_WRITE")
|