Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,25 @@
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
-
# Load pre-trained emotion classification model
|
5 |
model_checkpoint = "MuntasirHossain/RoBERTa-base-finetuned-emotion"
|
6 |
-
emotion_model = pipeline("text-classification", model=model_checkpoint)
|
7 |
|
8 |
-
|
9 |
-
# Get the predicted emotion label
|
10 |
-
emotion_label = emotion_model(text)[0]["label"]
|
11 |
-
|
12 |
-
# Map emotion labels to corresponding emojis
|
13 |
-
emoji_mapping = {
|
14 |
-
"joy": "π",
|
15 |
-
"sadness": "π’",
|
16 |
-
"love": "β€οΈ",
|
17 |
-
"anger": "π‘",
|
18 |
-
"fear": "π±",
|
19 |
-
"surprise": "π²",
|
20 |
-
}
|
21 |
-
|
22 |
-
# Get the corresponding emoji for the predicted emotion
|
23 |
-
predicted_emoji = emoji_mapping.get(emotion_label, "π€")
|
24 |
|
25 |
-
return f"{emotion_label.capitalize()} {predicted_emoji}"
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
34 |
inputs="textbox",
|
35 |
-
outputs=
|
36 |
title=title,
|
|
|
37 |
description=description,
|
38 |
-
|
39 |
-
|
40 |
-
iface.launch()
|
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
|
|
4 |
model_checkpoint = "MuntasirHossain/RoBERTa-base-finetuned-emotion"
|
|
|
5 |
|
6 |
+
model = pipeline("text-classification", model=model_checkpoint)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
|
|
8 |
|
9 |
+
def classify(text):
|
10 |
+
label = model(text)[0]["label"]
|
11 |
+
return label
|
12 |
|
13 |
+
description = "This AI model is trained to classify texts expressing human emotion into six categories: sadness, joy, love, anger, fear, and surprise."
|
14 |
+
title = "Classify Texts Expressing Emotion"
|
15 |
+
# theme = "peach"
|
16 |
+
examples=[["This is such a beautiful place"]]
|
17 |
+
|
18 |
+
gr.Interface(fn=classify,
|
19 |
inputs="textbox",
|
20 |
+
outputs="text",
|
21 |
title=title,
|
22 |
+
# theme = theme,
|
23 |
description=description,
|
24 |
+
examples=examples,
|
25 |
+
).launch()
|
|