File size: 943 Bytes
2ec1379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
def calculate_distress(emotions):
    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,
    "nervousness": 0.7,
    "remorse": 0.7,
    "sadness": 0.9,
    "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:
        return 0.0
    if not isinstance(emotions, dict):
        raise ValueError("Emotions should be a dictionary with labels as keys and scores as values.")
    distress = sum(
        distress_weights.get(label, 0) * score for label, score in emotions.items()
    )
    return round(distress, 2)