import streamlit as st from transformers import pipeline import pandas as pd # Page setup st.set_page_config(page_title="🎭 Emotion Guessing Game", layout="centered") # CSS for emoji bounce st.markdown(""" """, unsafe_allow_html=True) # Emoji for each emotion emoji_dict = { "joy": "😄", "sadness": "😢", "anger": "😠", "fear": "😱", "love": "❤️", "surprise": "😲" } # Online sound for each emotion sound_urls = { "joy": "https://www.soundjay.com/human/sounds/applause-8.mp3", "sadness": "https://www.soundjay.com/human/sounds/sigh-01.mp3", "anger": "https://www.soundjay.com/human/sounds/angry-shout-1.mp3", "fear": "https://www.soundjay.com/human/sounds/scream-02.mp3", "love": "https://www.soundjay.com/button/beep-07.mp3", "surprise": "https://www.soundjay.com/button/button-2.mp3" } # Load emotion detection model @st.cache_resource def load_model(): return pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion") classifier = load_model() # Title st.title("🎭 Emotion Guessing Game") st.markdown("Type a sentence and let AI guess your emotion!") # Input text = st.text_input("💬 How are you feeling today?") if text: result = classifier(text)[0] emotion = result["label"] confidence = round(result["score"] * 100, 2) emoji = emoji_dict.get(emotion, "🤔") # Show animated emoji st.markdown(f"
{emoji}
", unsafe_allow_html=True) st.markdown(f"### Emotion Detected: **{emotion}** {emoji}") st.markdown(f"Confidence: {confidence}%") # 🎊 Confetti for positive emotions if emotion in ["joy", "love", "surprise"]: st.balloons() # 🔊 Auto play sound if emotion in sound_urls: st.audio(sound_urls[emotion], format="audio/mp3", start_time=0) # Show full emotion chart all_results = classifier(text) df = pd.DataFrame({ "Emotion": [r["label"] for r in all_results], "Score": [round(r["score"] * 100, 2) for r in all_results] }) st.subheader("📊 Emotion Confidence Scores") st.bar_chart(df.set_index("Emotion"))