Update app.py
Browse files
app.py
CHANGED
@@ -129,20 +129,43 @@ def analyze_emotion(text):
|
|
129 |
if isinstance(emotions, list) and len(emotions) > 0:
|
130 |
emotion_scores = emotions[0]
|
131 |
|
132 |
-
# Define
|
133 |
-
urgent_emotions =
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
141 |
|
142 |
-
#
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
return "urgent"
|
145 |
-
elif high_priority_score > 0.
|
146 |
return "high"
|
147 |
return "normal"
|
148 |
|
|
|
129 |
if isinstance(emotions, list) and len(emotions) > 0:
|
130 |
emotion_scores = emotions[0]
|
131 |
|
132 |
+
# Define emotion categories with their respective thresholds
|
133 |
+
urgent_emotions = {
|
134 |
+
'anger': 0.15,
|
135 |
+
'fear': 0.40,
|
136 |
+
'annoyance': 0.10,
|
137 |
+
'disapproval': 0.30,
|
138 |
+
'nervousness': 0.25,
|
139 |
+
'disgust': 0.20,
|
140 |
+
'disappointment': 0.40
|
141 |
+
}
|
142 |
|
143 |
+
high_priority_emotions = {
|
144 |
+
'desire': 0.25,
|
145 |
+
'excitement': 0.35,
|
146 |
+
'surprise': 0.15,
|
147 |
+
'curiosity': 0.25,
|
148 |
+
'optimism': 0.20,
|
149 |
+
'pride': 0.10
|
150 |
+
}
|
151 |
|
152 |
+
# Calculate weighted urgency scores
|
153 |
+
urgent_score = 0
|
154 |
+
high_priority_score = 0
|
155 |
+
|
156 |
+
for item in emotion_scores:
|
157 |
+
emotion = item['label']
|
158 |
+
score = item['score']
|
159 |
+
|
160 |
+
if emotion in urgent_emotions and score > urgent_emotions[emotion]:
|
161 |
+
urgent_score += score
|
162 |
+
elif emotion in high_priority_emotions and score > high_priority_emotions[emotion]:
|
163 |
+
high_priority_score += score
|
164 |
+
|
165 |
+
# Determine urgency level based on weighted scores
|
166 |
+
if urgent_score > 0.4: # Adjusted threshold
|
167 |
return "urgent"
|
168 |
+
elif high_priority_score > 0.3 or urgent_score > 0.2: # Adjusted thresholds
|
169 |
return "high"
|
170 |
return "normal"
|
171 |
|