Spaces:
Sleeping
Sleeping
Create utils.py
Browse files
utils.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def calculate_distress(emotions):
|
2 |
+
distress_weights = {
|
3 |
+
"fear": 1.0,
|
4 |
+
"anger": 0.9,
|
5 |
+
"disgust": 0.8,
|
6 |
+
"sadness": 0.85,
|
7 |
+
"nervousness": 0.7,
|
8 |
+
"disappointment": 0.6,
|
9 |
+
"remorse": 0.5,
|
10 |
+
"annoyance": 0.6,
|
11 |
+
"confusion": 0.6,
|
12 |
+
"disapproval": 0.4,
|
13 |
+
"embarrassment": 0.7,
|
14 |
+
"grief": 1,
|
15 |
+
"nervousness": 0.7,
|
16 |
+
"remorse": 0.7,
|
17 |
+
"sadness": 0.9,
|
18 |
+
"desire": 0.4,
|
19 |
+
"joy": 0.2,
|
20 |
+
"love": 0.3,
|
21 |
+
"admiration": 0.2,
|
22 |
+
"optimism": 0.3,
|
23 |
+
"relief": 0.2,
|
24 |
+
"pride": 0.3,
|
25 |
+
"gratitude": 0.2,
|
26 |
+
"amusement": 0.2,
|
27 |
+
"excitement": 0.3,
|
28 |
+
"surprise": 0.4,
|
29 |
+
"neutral": 0.1
|
30 |
+
}
|
31 |
+
if not emotions:
|
32 |
+
return 0.0
|
33 |
+
if not isinstance(emotions, dict):
|
34 |
+
raise ValueError("Emotions should be a dictionary with labels as keys and scores as values.")
|
35 |
+
distress = sum(
|
36 |
+
distress_weights.get(label, 0) * score for label, score in emotions.items()
|
37 |
+
)
|
38 |
+
return round(distress, 2)
|