Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,39 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
emotion_classifier = pipeline(
|
| 6 |
"text-classification",
|
| 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 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
return "Unknown"
|
| 28 |
|
|
|
|
| 29 |
interface = gr.Interface(
|
| 30 |
fn=detect_emotion,
|
| 31 |
-
inputs=gr.Textbox(
|
| 32 |
outputs=gr.Textbox(label="Emotion Detected"),
|
| 33 |
title="Bilingual Emotion Detector",
|
| 34 |
-
description="
|
| 35 |
)
|
| 36 |
|
| 37 |
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Multilingual emotion detection মডেল লোড
|
| 5 |
emotion_classifier = pipeline(
|
| 6 |
"text-classification",
|
| 7 |
+
model="Toshifumi/bert-base-multilingual-cased-finetuned-emotion",
|
| 8 |
+
return_all_scores=False
|
| 9 |
)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def detect_emotion(text):
|
| 12 |
try:
|
| 13 |
result = emotion_classifier(text)[0]
|
| 14 |
label = result["label"]
|
| 15 |
+
|
| 16 |
+
# লেবেলগুলোকে সুন্দর বাংলা বা ইংরেজি নামে ম্যাপ করতে চাইলে নিচের ম্যাপ ইউজ করো
|
| 17 |
+
label_map = {
|
| 18 |
+
"anger": "Angry",
|
| 19 |
+
"joy": "Happy",
|
| 20 |
+
"sadness": "Sad",
|
| 21 |
+
"fear": "Fear",
|
| 22 |
+
"love": "Love",
|
| 23 |
+
"surprise": "Surprised",
|
| 24 |
+
"neutral": "Neutral"
|
| 25 |
+
}
|
| 26 |
+
return label_map.get(label.lower(), label)
|
| 27 |
+
except Exception:
|
| 28 |
return "Unknown"
|
| 29 |
|
| 30 |
+
# Gradio UI সেটআপ
|
| 31 |
interface = gr.Interface(
|
| 32 |
fn=detect_emotion,
|
| 33 |
+
inputs=gr.Textbox(lines=4, placeholder="বাংলা বা English-এ লিখুন এখানে...", label="আপনার টেক্সট"),
|
| 34 |
outputs=gr.Textbox(label="Emotion Detected"),
|
| 35 |
title="Bilingual Emotion Detector",
|
| 36 |
+
description="বাংলা ও ইংরেজি টেক্সট থেকে আবেগ শনাক্ত করে একটি প্রশিক্ষিত মডেল।"
|
| 37 |
)
|
| 38 |
|
| 39 |
interface.launch()
|