prahalya commited on
Commit
2cd8852
·
verified ·
1 Parent(s): 899230e

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -150
app.py DELETED
@@ -1,150 +0,0 @@
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!")