|
from transformers import pipeline |
|
import gradio as gr |
|
|
|
|
|
model_checkpoint = "MuntasirHossain/RoBERTa-base-finetuned-emotion" |
|
emotion_model = pipeline("text-classification", model=model_checkpoint) |
|
|
|
def classify_and_visualize_emotion(text): |
|
|
|
emotion_label = emotion_model(text)[0]["label"] |
|
|
|
|
|
emoji_mapping = { |
|
"joy": "π", |
|
"sadness": "π’", |
|
"love": "β€οΈ", |
|
"anger": "π‘", |
|
"fear": "π±", |
|
"surprise": "π²", |
|
} |
|
|
|
|
|
predicted_emoji = emoji_mapping.get(emotion_label, "π€") |
|
|
|
return f"{emotion_label.capitalize()} {predicted_emoji}" |
|
|
|
|
|
title = "Emotion Classifier with Emoji Visualization" |
|
description = "This AI model classifies text expressions into six emotions: joy, sadness, love, anger, fear, and surprise. The result is visualized with emojis." |
|
|
|
|
|
iface = gr.Interface( |
|
fn=classify_and_visualize_emotion, |
|
inputs="textbox", |
|
outputs=gr.Html(), |
|
title=title, |
|
description=description, |
|
) |
|
|
|
iface.launch() |
|
|