Update app.py
Browse files
app.py
CHANGED
@@ -116,13 +116,53 @@ def transcribe_audio(audio_file):
|
|
116 |
print(f"Transcription error details: {str(e)}")
|
117 |
raise Exception(f"Transcription error: {str(e)}")
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
def improve_task_description(text):
|
120 |
-
"""Improve and summarize task description using SambaNova API"""
|
121 |
try:
|
|
|
|
|
|
|
122 |
prompt = f"""Please analyze and structure this task description, including determining its urgency level.
|
123 |
|
124 |
Original task: {text}
|
125 |
|
|
|
|
|
126 |
Please provide:
|
127 |
1. A clear, concise task title
|
128 |
2. Key objectives
|
@@ -133,8 +173,10 @@ Please provide:
|
|
133 |
- Deadlines mentioned
|
134 |
- Impact and consequences described
|
135 |
- Business criticality
|
|
|
136 |
|
137 |
Format the response with "URGENCY_LEVEL: [level]" as the first line, followed by the structured description.
|
|
|
138 |
"""
|
139 |
|
140 |
headers = {
|
@@ -167,12 +209,17 @@ Format the response with "URGENCY_LEVEL: [level]" as the first line, followed by
|
|
167 |
# Extract urgency level and description
|
168 |
lines = response_text.split('\n')
|
169 |
urgency_line = lines[0].strip()
|
170 |
-
|
|
|
|
|
171 |
|
172 |
if urgency_line.startswith("URGENCY_LEVEL:"):
|
173 |
level = urgency_line.split(":")[1].strip().lower()
|
174 |
if level in ["normal", "high", "urgent"]:
|
175 |
-
urgency
|
|
|
|
|
|
|
176 |
description = '\n'.join(lines[1:]).strip()
|
177 |
else:
|
178 |
description = response_text
|
|
|
116 |
print(f"Transcription error details: {str(e)}")
|
117 |
raise Exception(f"Transcription error: {str(e)}")
|
118 |
|
119 |
+
def analyze_emotion(text):
|
120 |
+
"""Analyze text emotion using Hugging Face API"""
|
121 |
+
API_URL = "https://api-inference.huggingface.co/models/SamLowe/roberta-base-go_emotions"
|
122 |
+
headers = {"Authorization": f"Bearer {os.getenv('HUGGINGFACE_API_KEY')}"}
|
123 |
+
|
124 |
+
try:
|
125 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": text})
|
126 |
+
emotions = response.json()
|
127 |
+
|
128 |
+
# Extract emotion scores
|
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 |
+
|
149 |
+
return "normal"
|
150 |
+
except Exception as e:
|
151 |
+
print(f"Error in emotion analysis: {str(e)}")
|
152 |
+
return "normal"
|
153 |
+
|
154 |
def improve_task_description(text):
|
155 |
+
"""Improve and summarize task description using SambaNova API and emotion analysis"""
|
156 |
try:
|
157 |
+
# First analyze emotion to get initial urgency assessment
|
158 |
+
emotion_urgency = analyze_emotion(text)
|
159 |
+
|
160 |
prompt = f"""Please analyze and structure this task description, including determining its urgency level.
|
161 |
|
162 |
Original task: {text}
|
163 |
|
164 |
+
Initial emotion-based urgency assessment: {emotion_urgency}
|
165 |
+
|
166 |
Please provide:
|
167 |
1. A clear, concise task title
|
168 |
2. Key objectives
|
|
|
173 |
- Deadlines mentioned
|
174 |
- Impact and consequences described
|
175 |
- Business criticality
|
176 |
+
- Emotional context and tone
|
177 |
|
178 |
Format the response with "URGENCY_LEVEL: [level]" as the first line, followed by the structured description.
|
179 |
+
Consider the emotion-based urgency assessment provided above when making the final urgency determination.
|
180 |
"""
|
181 |
|
182 |
headers = {
|
|
|
209 |
# Extract urgency level and description
|
210 |
lines = response_text.split('\n')
|
211 |
urgency_line = lines[0].strip()
|
212 |
+
|
213 |
+
# Use emotion-based urgency as fallback
|
214 |
+
urgency = emotion_urgency
|
215 |
|
216 |
if urgency_line.startswith("URGENCY_LEVEL:"):
|
217 |
level = urgency_line.split(":")[1].strip().lower()
|
218 |
if level in ["normal", "high", "urgent"]:
|
219 |
+
# Compare with emotion-based urgency and use the higher priority
|
220 |
+
urgency_levels = {"normal": 0, "high": 1, "urgent": 2}
|
221 |
+
if urgency_levels[level] > urgency_levels[emotion_urgency]:
|
222 |
+
urgency = level
|
223 |
description = '\n'.join(lines[1:]).strip()
|
224 |
else:
|
225 |
description = response_text
|