prahalya commited on
Commit
d911999
Β·
verified Β·
1 Parent(s): 6e7366f

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +150 -0
  2. data.csv +7 -0
  3. model.pkl +3 -0
  4. pipe.pkl +3 -0
  5. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+ import torch
4
+ # Streamlit UI
5
+ st.set_page_config(page_title="Emotion Detection", layout="centered")
6
+ # 🎯 Add Image at the Top
7
+ st.image("inno.jpg", use_container_width=True,width=300)
8
+
9
+ #1. Business and Data Understanding
10
+ st.header(" 1. Business and Data Understanding")
11
+ st.write("""
12
+ Understanding human emotions is critical for businesses that interact with customers, employees, or users through text, speech, or images.
13
+ Subjectivity of Emotions: Emotions can be complex, overlapping, and vary based on individual perceptions.
14
+ * Data Limitations: Labeled emotional datasets are often limited or imbalanced.
15
+ * Real-time Processing Needs: Businesses require fast, scalable solutions for handling large volumes of data.
16
+ * Multimodal Complexity: Emotions can be expressed through text, speech, or facial expressions, requiring different ML models.
17
+ * Privacy & Ethical Concerns: Emotion analysis can raise ethical and legal issues related to data privacy.""")
18
+
19
+ # b) Business Objective
20
+ st.subheader(" b) Business Objective")
21
+ st.write("""
22
+ The primary business objective of emotion detection is to understand, analyze, and
23
+ respond to human emotions in real time to improve customer experience,
24
+ employee engagement, marketing strategies, and decision-making.
25
+ Key Business Objectives:
26
+ 1 Improve Customer Experience & Satisfaction:
27
+ - Detect customer emotions in support chats, emails, and voice calls.
28
+ - Provide personalized responses and proactive service to reduce customer frustration.
29
+ - Optimize chatbots and virtual assistants to improve engagement.
30
+
31
+ 2 Enhance Brand Reputation & Market Intelligence:
32
+ - Analyze social media sentiments and product reviews to measure public perception.
33
+ - Identify negative feedback early to prevent PR crises.
34
+ - Improve product and service offerings based on emotional insights.
35
+
36
+ 3 Increase Employee Engagement & Workplace Well-being:
37
+ - Analyze employee sentiment in feedback surveys, emails, and communication tools.
38
+ - Detect burnout, dissatisfaction, or stress levels in employees.
39
+ - Improve HR policies and work culture based on emotion analytics.
40
+
41
+ 4 Optimize Marketing & Advertising Strategies:
42
+ - Measure emotional reactions to ads, videos, and brand campaigns.
43
+ - Personalize marketing content based on user emotions.
44
+ - Improve product recommendations and customer targeting.
45
+
46
+ 5 Support Mental Health & Well-being:
47
+ - Detect signs of stress, anxiety, or depression in conversations.
48
+ - Provide AI-driven emotional support through chatbots and virtual therapy.
49
+ - Assist psychologists and therapists in tracking patient emotions.
50
+
51
+ 6 Enable Real-Time Decision Making:
52
+ - Use emotion-based insights to make faster, data-driven business decisions.
53
+ - Improve customer retention by addressing negative sentiments proactively.
54
+ - Automate sentiment monitoring for large-scale data analysis.""")
55
+
56
+ # c) Business Constraints
57
+
58
+ st.subheader(" c) Business Constraints")
59
+ st.write("""
60
+ - *Data Privacy & Security*
61
+ - *Language & Emoji Variations*
62
+ - *Accuracy & Context Awareness*
63
+ - *scalability*
64
+ - *Real-Time Processing*
65
+ """)
66
+
67
+ # d) Data Understanding
68
+ st.subheader(" d) Data Understanding")
69
+ st.write("""
70
+ - *Dataset Size:* 422,746 text samples.
71
+ - *Data Types:* Text data, labeled emotions, unstructured text.
72
+ - *Data Features:*
73
+ *Raw Text:* Actual emotional expressions.
74
+ *Emojis & Symbols:* Indicators of sentiment.
75
+ """)
76
+
77
+
78
+ # Load pre-trained emotion detection model
79
+ model_name = "j-hartmann/emotion-english-distilroberta-base"
80
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
81
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
82
+
83
+ # Get the actual emotion labels from the model
84
+ emotion_labels = model.config.id2label
85
+
86
+ # Emotion styles (emoji + colors)
87
+ emotion_styles = {
88
+ "joy": {"emoji": "πŸ˜ƒ", "color": "#D3D3D3"},
89
+ "sadness": {"emoji": "😒", "color": "#3498BB"},
90
+ "anger": {"emoji": "😑", "color": "#FFDAA9"},
91
+ "fear": {"emoji": "😨", "color": "#FFFAAD"},
92
+ "surprise": {"emoji": "😲", "color": "#98CB98"},
93
+ "disgust": {"emoji": "🀒", "color": "#FFBFC1"},
94
+ "neutral": {"emoji": "😐", "color": "#E6E6FA"}
95
+ }
96
+
97
+
98
+ # 🎨 Change Background Color
99
+ st.markdown(
100
+ """
101
+ <style>
102
+ body {
103
+ background-color:#AFEEEE; /* Light Grayish Blue */
104
+ }
105
+ </style>
106
+ """,
107
+ unsafe_allow_html=True
108
+ )
109
+
110
+
111
+
112
+ st.markdown("<h1 style='text-align: center; color: #7B3B98;'>Emotion Detection using ML</h1>", unsafe_allow_html=True)
113
+ st.markdown("<h3 style='text-align: left; color: #3498BB;'>πŸ“ Enter the text:</h3>", unsafe_allow_html=True)
114
+
115
+ # User Input
116
+ user_text = st.text_input("", placeholder="Type your text here...")
117
+
118
+ if st.button("Submit"):
119
+ if user_text:
120
+ # Tokenize input text
121
+ inputs = tokenizer(user_text, return_tensors="pt")
122
+
123
+ # Get model predictions
124
+ with torch.no_grad():
125
+
126
+
127
+
128
+ outputs = model(**inputs)
129
+
130
+ # Get the predicted emotion
131
+ scores = outputs.logits[0]
132
+ predicted_label_id = torch.argmax(scores).item()
133
+ predicted_emotion = emotion_labels[predicted_label_id].strip().lower()
134
+
135
+ # Get emoji & color
136
+ emotion_data = emotion_styles.get(predicted_emotion, {"emoji": "😐", "color": "#D3D3D3"})
137
+ emoji_display = emotion_data["emoji"]
138
+ text_color = emotion_data["color"]
139
+
140
+ # Display Results with Color
141
+ st.markdown(
142
+ f"""
143
+ <div style="text-align: center; padding: 10px; border-radius: 10px; background-color: {text_color}; color: black; font-size: 24px;">
144
+ <b>Detected Emotion:</b> {predicted_emotion.capitalize()} {emoji_display}
145
+ </div>
146
+ """,
147
+ unsafe_allow_html=True
148
+ )
149
+ else:
150
+ st.warning("Please enter some text!")
data.csv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ customer_id,name,contact,email,age,location,subscription_type,payment_plan,num_subscription_pauses,payment_method,customer_service_inquiries,signup_date,weekly_hours,average_session_length,song_skip_rate,weekly_songs_played,weekly_unique_songs,num_favorite_artists,num_platform_friends,num_playlists_created,num_shared_playlists,notifications_clicked
2
+ 121530,aadhi,8977893494,aadhi01516@gmail.com,38,New Jersey,Family,Monthly,3,Paypal,Medium,-2900,38.07676034,59.23617873,0.830366768,69,57,24,18,76,32,3
3
+ 119139,moon,9600814004,prahalya128@gmail.com,36,Idaho,Free,Monthly,2,Debit Card,Low,-2603,14.98920398,10.72029557,0.659665888,352,293,35,25,19,10,35
4
+ 121530,aadhi,8977893494,k,38,New Jersey,Family,Monthly,3,Paypal,Medium,-2900,38.07676034,59.23617873,0.830366768,69,57,24,18,76,32,3
5
+ 119139,moon,9600814004,k,36,Idaho,Free,Monthly,2,Debit Card,Low,-2603,14.98920398,10.72029557,0.659665888,352,293,35,25,19,10,35
6
+ 121530,aadhi,8977893494,k,38,New Jersey,Family,Monthly,3,Paypal,Medium,-2900,38.07676034,59.23617873,0.830366768,69,57,24,18,76,32,3
7
+ 119139,moon,9600814004,k,36,Idaho,Free,Monthly,2,Debit Card,Low,-2603,14.98920398,10.72029557,0.659665888,352,293,35,25,19,10,35
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:57b403cfd4304d36b9b2eb190de505084ae31c67430fa83c779aa7ff03622767
3
+ size 2069
pipe.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aa81099c9687a11a62b5dbc7aa47d9dfb316ce4861df254d9a1afdab6aa9bb6b
3
+ size 3082
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ pandas
2
+ numpy
3
+ nltk
4
+ scikit-learn
5
+ streamlit
6
+ joblib