File size: 5,336 Bytes
e7155e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d672b27
e7155e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import streamlit as st
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch

# Load Pre-trained Emotion Detection Model
MODEL_NAME = "j-hartmann/emotion-english-distilroberta-base"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)

# Emotion Mapping (Emojis & Colors)
emotion_styles = {
    "joy": {"emoji": "πŸ˜ƒ", "color": "#E6E6FA"},
    "sadness": {"emoji": "😒", "color": "#3498DB"},
    "anger": {"emoji": "😑", "color": "#FFDAB9"},
    "fear": {"emoji": "😨", "color": "#FFFACD"},
    "surprise": {"emoji": "😲", "color": "#98FB98"},
    "disgust": {"emoji": "🀒", "color": "#FFB6C1"},
    "neutral": {"emoji": "😐", "color": "#D3D3D3"}
}

# Configure Streamlit Page
st.set_page_config(page_title="Emotion Detection", layout="centered")

# Custom CSS for Background and Styling
st.markdown(
    """
    <style>
        body { background-color: black; color: white; }
        .result-box {
            text-align: center;
            padding: 15px;
            border-radius: 10px;
            font-size: 22px;
            font-weight: bold;
        }
    </style>
    """,
    unsafe_allow_html=True
)

# Header Section
st.image("innomatics-footer-logo.webp", use_container_width=True)  # Replace with your image file
st.markdown("<h1 style='text-align: center; color: blue;'>πŸ” Emotion Detection 😊</h1>", unsafe_allow_html=True)

# Business Context
st.markdown("<h2 style='color: orange;'> πŸ“Š Business Context</h2>",unsafe_allow_html=True)

st.markdown("<h3 style='color: red;'>πŸ“Œ Business Problem</h3>", unsafe_allow_html=True)
st.markdown("""
Businesses struggle to understand customer emotions in real-time. Traditional feedback methods, such as surveys and reviews, fail to capture spontaneous emotional responses, leading to:

- **Missed opportunities** for improving customer experience.
- **Delayed insights** into customer satisfaction.
- **Inability to personalize interactions** based on real emotions.

An effective emotion detection system can help businesses analyze customer sentiments instantly, enabling proactive engagement and improved decision-making.
""", unsafe_allow_html=True)

st.markdown("<h3 style='color: green;'>🎯 Business Objective</h3>", unsafe_allow_html=True)
st.markdown("""
The primary goal of this Emotion Detection System is to enhance customer experience by identifying emotions in real-time from text-based interactions.

##### **Key Objectives:**
- βœ… **Real-time Emotion Analysis** – Detect emotions from customer messages, emails, and social media interactions.
- βœ… **Improved Customer Satisfaction** – Address negative sentiments promptly to enhance brand loyalty.
- βœ… **Personalized Engagement** – Tailor responses based on detected emotions for a better user experience.
- βœ… **Data-Driven Decisions** – Provide insights for optimizing services, marketing strategies, and customer interactions.
- βœ… **Operational Efficiency** – Automate sentiment analysis, reducing manual effort and response time.
""", unsafe_allow_html=True)

st.markdown("<h3 style='color: blue;'>βš–οΈ Business Constraints</h3>", unsafe_allow_html=True)
st.markdown("""
The system must meet the following business and technical constraints:

- 1️⃣ **Data Privacy & Compliance** – Must adhere to regulations like **GDPR** and **CCPA** to ensure user data protection.
- 2️⃣ **Real-time Processing** – The model should analyze and respond to emotions instantly, without significant delays.
- 3️⃣ **System Integration** – Should seamlessly integrate with **chatbots, CRMs, call centers, and social media platforms**.
- 4️⃣ **Accuracy & Reliability** – High **precision with minimal false positives** to avoid misinterpretations.
- 5️⃣ **Scalability** – Should efficiently handle **large-scale interactions** across multiple customer touchpoints.
- 6️⃣ **Cost-effectiveness** – Must be financially viable while delivering measurable ROI.
- 7️⃣ **Multi-language & Multi-model Support** – Capable of detecting emotions across **various languages** and communication channels **(text, voice, images)**.
""", unsafe_allow_html=True)

# User Input Section
st.markdown("<h2 style='color: purple;'> πŸ“ Enter Your Text Below</h2>",unsafe_allow_html=True)
user_text = st.text_input("", placeholder="Type your text here...")

# Emotion Prediction
if st.button("Predict Emotion"):
    if user_text:
        inputs = tokenizer(user_text, return_tensors="pt")

        with torch.no_grad():
            outputs = model(**inputs)

        # Get predicted emotion
        scores = outputs.logits[0]
        predicted_label_id = torch.argmax(scores).item()
        predicted_emotion = model.config.id2label[predicted_label_id].lower()

        # Display Results
        emotion_data = emotion_styles.get(predicted_emotion, {"emoji": "😐", "color": "#95A5A6"})
        st.markdown(
            f"""
            <div class="result-box" style="background-color: {emotion_data['color']}; color: black;">
                Detected Emotion: <b>{predicted_emotion.capitalize()} {emotion_data['emoji']}</b>
            </div>
            """,
            unsafe_allow_html=True
        )
    else:
        st.warning("Please enter some text!")