Pamudu13 commited on
Commit
d01eb9b
·
verified ·
1 Parent(s): aadd612

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -11
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 urgent emotions
133
- urgent_emotions = ['anger', 'fear', 'annoyance', 'disapproval', 'nervousness']
134
- high_priority_emotions = ['desire', 'excitement', 'surprise']
 
 
 
 
 
 
 
135
 
136
- # Calculate urgency based on emotional content
137
- urgent_score = sum(score for emotion, score in emotion_scores.items()
138
- if emotion in urgent_emotions)
139
- high_priority_score = sum(score for emotion, score in emotion_scores.items()
140
- if emotion in high_priority_emotions)
 
 
 
141
 
142
- # Determine urgency level based on emotion scores
143
- if urgent_score > 0.5:
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  return "urgent"
145
- elif high_priority_score > 0.4 or urgent_score > 0.3:
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