Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,28 +7,24 @@ emotion_classifier = pipeline(
|
|
| 7 |
model="Toshifumi/bert-base-multilingual-cased-finetuned-emotion"
|
| 8 |
)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
return "Neutral"
|
| 20 |
|
| 21 |
def detect_emotion(text):
|
| 22 |
try:
|
| 23 |
result = emotion_classifier(text)[0]
|
| 24 |
label = result["label"]
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
return label
|
| 30 |
-
except:
|
| 31 |
-
return fallback_bangla_emotion(text)
|
| 32 |
|
| 33 |
interface = gr.Interface(
|
| 34 |
fn=detect_emotion,
|
|
|
|
| 7 |
model="Toshifumi/bert-base-multilingual-cased-finetuned-emotion"
|
| 8 |
)
|
| 9 |
|
| 10 |
+
# Mapping label_x to actual emotion name
|
| 11 |
+
label_map = {
|
| 12 |
+
"label_0": "Anger",
|
| 13 |
+
"label_1": "Sadness",
|
| 14 |
+
"label_2": "Joy",
|
| 15 |
+
"label_3": "Love",
|
| 16 |
+
"label_4": "Fear",
|
| 17 |
+
"label_5": "Surprise"
|
| 18 |
+
}
|
|
|
|
| 19 |
|
| 20 |
def detect_emotion(text):
|
| 21 |
try:
|
| 22 |
result = emotion_classifier(text)[0]
|
| 23 |
label = result["label"]
|
| 24 |
+
emotion = label_map.get(label, "Unknown")
|
| 25 |
+
return emotion
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return "Unknown"
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
interface = gr.Interface(
|
| 30 |
fn=detect_emotion,
|