Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,7 @@ humanized_map = {
|
|
25 |
"LABEL_5": "😲 বিস্ময় (Surprise)",
|
26 |
"LABEL_6": "😐 নিরপেক্ষ (Neutral)",
|
27 |
|
28 |
-
#
|
29 |
"Anger": "😠 রাগ (Anger)",
|
30 |
"Sadness": "😢 দুঃখ (Sadness)",
|
31 |
"Joy": "😊 আনন্দিত (Joy)",
|
@@ -35,6 +35,23 @@ humanized_map = {
|
|
35 |
"Neutral": "😐 নিরপেক্ষ (Neutral)"
|
36 |
}
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
# Emotion detect function
|
39 |
def detect_emotion(text):
|
40 |
if not text.strip():
|
@@ -44,10 +61,15 @@ def detect_emotion(text):
|
|
44 |
label = result["label"]
|
45 |
score = round(result["score"] * 100, 2)
|
46 |
emotion = humanized_map.get(label)
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
50 |
return f"🤔 অজানা (Unknown) — মডেল লেবেল: {label} (score: {score}%)"
|
|
|
|
|
51 |
except Exception as e:
|
52 |
return f"❌ সমস্যা হয়েছে: {str(e)}"
|
53 |
|
|
|
25 |
"LABEL_5": "😲 বিস্ময় (Surprise)",
|
26 |
"LABEL_6": "😐 নিরপেক্ষ (Neutral)",
|
27 |
|
28 |
+
# Extra fallback for plain text labels
|
29 |
"Anger": "😠 রাগ (Anger)",
|
30 |
"Sadness": "😢 দুঃখ (Sadness)",
|
31 |
"Joy": "😊 আনন্দিত (Joy)",
|
|
|
35 |
"Neutral": "😐 নিরপেক্ষ (Neutral)"
|
36 |
}
|
37 |
|
38 |
+
# Extra keyword-based fallback mapping
|
39 |
+
keyword_map = {
|
40 |
+
"happy": "😊 আনন্দিত (Joy)",
|
41 |
+
"খুশি": "😊 আনন্দিত (Joy)",
|
42 |
+
"sad": "😢 দুঃখ (Sadness)",
|
43 |
+
"দুঃখ": "😢 দুঃখ (Sadness)",
|
44 |
+
"love": "❤️ ভালোবাসা (Love)",
|
45 |
+
"ভালবাসা": "❤️ ভালোবাসা (Love)",
|
46 |
+
"ভালোবাসা": "❤️ ভালোবাসা (Love)",
|
47 |
+
"fear": "😨 ভয় (Fear)",
|
48 |
+
"ভয়": "😨 ভয় (Fear)",
|
49 |
+
"angry": "😠 রাগ (Anger)",
|
50 |
+
"রাগ": "😠 রাগ (Anger)",
|
51 |
+
"surprise": "😲 বিস্ময় (Surprise)",
|
52 |
+
"বিস্ময়": "😲 বিস্ময় (Surprise)"
|
53 |
+
}
|
54 |
+
|
55 |
# Emotion detect function
|
56 |
def detect_emotion(text):
|
57 |
if not text.strip():
|
|
|
61 |
label = result["label"]
|
62 |
score = round(result["score"] * 100, 2)
|
63 |
emotion = humanized_map.get(label)
|
64 |
+
|
65 |
+
if not emotion:
|
66 |
+
# Keyword fallback
|
67 |
+
for word in keyword_map:
|
68 |
+
if word in text.lower():
|
69 |
+
return f"{keyword_map[word]} (keyword match)"
|
70 |
return f"🤔 অজানা (Unknown) — মডেল লেবেল: {label} (score: {score}%)"
|
71 |
+
|
72 |
+
return f"{emotion} (score: {score}%)"
|
73 |
except Exception as e:
|
74 |
return f"❌ সমস্যা হয়েছে: {str(e)}"
|
75 |
|