Spaces:
Sleeping
Sleeping
| 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) | |