File size: 1,280 Bytes
973cc88 2024591 973cc88 2024591 973cc88 2024591 973cc88 29c65a1 973cc88 2024591 973cc88 29c65a1 2024591 973cc88 29c65a1 973cc88 29c65a1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
from transformers import pipeline
import gradio as gr
# Load pre-trained emotion classification model
model_checkpoint = "MuntasirHossain/RoBERTa-base-finetuned-emotion"
emotion_model = pipeline("text-classification", model=model_checkpoint)
def classify_and_visualize_emotion(text):
# Get the predicted emotion label
emotion_label = emotion_model(text)[0]["label"]
# Map emotion labels to corresponding emojis
emoji_mapping = {
"joy": "π",
"sadness": "π’",
"love": "β€οΈ",
"anger": "π‘",
"fear": "π±",
"surprise": "π²",
}
# Get the corresponding emoji for the predicted emotion
predicted_emoji = emoji_mapping.get(emotion_label, "π€")
return f"{emotion_label.capitalize()} {predicted_emoji}"
# Define interface title and description
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."
# Set up Gradio Interface with HTML visualization
iface = gr.Interface(
fn=classify_and_visualize_emotion,
inputs="textbox",
outputs=gr.Html(),
title=title,
description=description,
)
iface.launch()
|