Update app.py
Browse files
app.py
CHANGED
|
@@ -208,13 +208,8 @@ def classify_emotion(text, classifier):
|
|
| 208 |
all_scores = []
|
| 209 |
for chunk in chunks:
|
| 210 |
try:
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
truncation=True,
|
| 214 |
-
max_length=512,
|
| 215 |
-
return_tensors="pt"
|
| 216 |
-
)
|
| 217 |
-
result = classifier(chunk, truncation=True, max_length=512)
|
| 218 |
scores = result[0]
|
| 219 |
all_scores.append(scores)
|
| 220 |
except Exception as chunk_error:
|
|
@@ -226,11 +221,10 @@ def classify_emotion(text, classifier):
|
|
| 226 |
count = len(all_scores)
|
| 227 |
|
| 228 |
for scores in all_scores:
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
label_scores[label] += score['score']
|
| 234 |
|
| 235 |
avg_scores = {label: score/count for label, score in label_scores.items()}
|
| 236 |
final_emotion = max(avg_scores.items(), key=lambda x: x[1])[0]
|
|
@@ -241,7 +235,7 @@ def classify_emotion(text, classifier):
|
|
| 241 |
except Exception as e:
|
| 242 |
st.warning(f"Error in emotion classification: {str(e)}")
|
| 243 |
return "LABEL_2"
|
| 244 |
-
|
| 245 |
def get_embedding_for_text(text, tokenizer, model):
|
| 246 |
"""Get embedding for complete text."""
|
| 247 |
chunks = split_text(text)
|
|
|
|
| 208 |
all_scores = []
|
| 209 |
for chunk in chunks:
|
| 210 |
try:
|
| 211 |
+
# Direct classification without additional tokenization
|
| 212 |
+
result = classifier(chunk)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
scores = result[0]
|
| 214 |
all_scores.append(scores)
|
| 215 |
except Exception as chunk_error:
|
|
|
|
| 221 |
count = len(all_scores)
|
| 222 |
|
| 223 |
for scores in all_scores:
|
| 224 |
+
label = scores['label']
|
| 225 |
+
if label not in label_scores:
|
| 226 |
+
label_scores[label] = 0
|
| 227 |
+
label_scores[label] += scores['score']
|
|
|
|
| 228 |
|
| 229 |
avg_scores = {label: score/count for label, score in label_scores.items()}
|
| 230 |
final_emotion = max(avg_scores.items(), key=lambda x: x[1])[0]
|
|
|
|
| 235 |
except Exception as e:
|
| 236 |
st.warning(f"Error in emotion classification: {str(e)}")
|
| 237 |
return "LABEL_2"
|
| 238 |
+
|
| 239 |
def get_embedding_for_text(text, tokenizer, model):
|
| 240 |
"""Get embedding for complete text."""
|
| 241 |
chunks = split_text(text)
|