Spaces:
Running
Running
File size: 997 Bytes
8e1eae2 2ec1379 8e1eae2 2ec1379 8e1eae2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
def calculate_distress(emotions, suicide_risk=0.0):
distress_weights = {
"fear": 1.0,
"anger": 0.9,
"disgust": 0.8,
"sadness": 0.85,
"nervousness": 0.7,
"disappointment": 0.6,
"remorse": 0.5,
"annoyance": 0.6,
"confusion": 0.6,
"disapproval": 0.4,
"embarrassment": 0.7,
"grief": 1.0,
"desire": 0.4,
"joy": 0.2,
"love": 0.3,
"admiration": 0.2,
"optimism": 0.3,
"relief": 0.2,
"pride": 0.3,
"gratitude": 0.2,
"amusement": 0.2,
"excitement": 0.3,
"surprise": 0.4,
"neutral": 0.1
}
if not emotions:
distress = 0.0
else:
distress = sum(
distress_weights.get(label, 0) * score
for label, score in emotions.items()
)
# Boost distress with suicidal risk
distress += suicide_risk * 1.5
return round(min(distress, 1.0), 2) # Cap at 1.0
|