taimoor61's picture
Update app.py
29c65a1
raw
history blame
1.28 kB
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()