sunbal7 commited on
Commit
114e659
Β·
verified Β·
1 Parent(s): 561044a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -37
app.py CHANGED
@@ -11,19 +11,21 @@ st.set_page_config(
11
  initial_sidebar_state="collapsed"
12
  )
13
 
14
- # Custom CSS for light purple theme
15
  st.markdown("""
16
  <style>
17
  :root {
18
  --primary: #b19cd9;
19
- --background: #f5f0ff;
 
20
  --secondary-background: #e6e0fa;
21
  --text: #4a4a4a;
22
  --font: "Arial", sans-serif;
23
  }
24
 
25
  body {
26
- background-color: var(--background);
 
27
  color: var(--text);
28
  font-family: var(--font);
29
  }
@@ -31,14 +33,22 @@ body {
31
  .stTextInput>div>div>input {
32
  background-color: var(--secondary-background) !important;
33
  color: var(--text) !important;
 
 
34
  }
35
 
36
  .stButton>button {
37
  background-color: var(--primary) !important;
38
  color: white !important;
39
  border: none;
40
- border-radius: 8px;
41
  padding: 8px 16px;
 
 
 
 
 
 
42
  }
43
 
44
  .stMarkdown {
@@ -47,67 +57,105 @@ body {
47
  }
48
 
49
  .chat-message {
50
- padding: 12px;
51
- border-radius: 12px;
52
- margin: 8px 0;
53
  max-width: 80%;
 
54
  }
55
 
56
  .user-message {
57
  background-color: var(--secondary-background);
58
  margin-left: auto;
59
- text-align: right;
 
60
  }
61
 
62
  .bot-message {
63
  background-color: var(--primary);
64
  color: white;
65
  margin-right: auto;
 
66
  }
67
 
68
  .face-container {
69
  text-align: center;
70
  padding: 20px;
71
- background: white;
72
- border-radius: 16px;
73
- box-shadow: 0 4px 12px rgba(0,0,0,0.1);
74
- margin: 20px 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
76
  </style>
77
  """, unsafe_allow_html=True)
78
 
79
  # Emotion databases
80
- POSITIVE_WORDS = {"happy", "awesome", "great", "joy", "excited", "good", "wonderful", "fantastic", "amazing"}
81
- NEGATIVE_WORDS = {"sad", "depressed", "angry", "cry", "lonely", "bad", "terrible", "awful", "miserable"}
 
82
  HELP_RESPONSES = [
83
  "Would you like to talk about it? πŸ’¬",
84
- "I'm here to listen πŸ’™",
85
  "Want some uplifting quotes? πŸ“œ",
86
  "Would a virtual hug help? πŸ€—",
87
- "Let's focus on something positive 🌈"
 
88
  ]
89
 
90
  # ASCII Art Library
91
  FACES = {
92
  "happy": r"""
93
- ╔════════╗
94
- πŸ˜„ AWESOME!
95
- β•šβ•β•β•β•β•β•β•β•β•
96
  """,
97
  "sad": r"""
98
- ╔════════╗
99
- 😒 SAD DAY?
100
- β•šβ•β•β•β•β•β•β•β•β•
101
  """,
102
  "neutral": r"""
103
- ╔════════╗
104
- 😐 HELLO
105
- β•šβ•β•β•β•β•β•β•β•β•
106
  """,
107
  "love": r"""
108
- ╔════════╗
109
- 😍 LOVELY!
110
- β•šβ•β•β•β•β•β•β•β•β•
 
 
 
 
 
111
  """
112
  }
113
 
@@ -123,7 +171,8 @@ def confetti_effect():
123
 
124
  function fire(particleRatio, opts) {
125
  confetti(Object.assign({}, defaults, opts, {
126
- particleCount: Math.floor(count * particleRatio)
 
127
  }));
128
  }
129
 
@@ -143,8 +192,10 @@ def detect_emotion(text):
143
  return "happy"
144
  elif any(word in text for word in NEGATIVE_WORDS):
145
  return "sad"
146
- elif "love" in text or "heart" in text:
147
  return "love"
 
 
148
  return "neutral"
149
 
150
  # Initialize chat history
@@ -152,9 +203,8 @@ if "messages" not in st.session_state:
152
  st.session_state.messages = []
153
  st.session_state.current_emotion = "neutral"
154
 
155
- # Title and description
156
- st.title("✨ Emotion Mirror Chatbot")
157
- st.markdown("I'm a reactive AI agent that mirrors your emotions! Try words like *happy*, *sad*, or *awesome*")
158
 
159
  # Display current face
160
  with st.container():
@@ -178,12 +228,14 @@ if prompt := st.chat_input("How are you feeling today?"):
178
 
179
  # Generate bot response
180
  if emotion == "happy":
181
- response = FACES["happy"] + "\n\n🌟 That's wonderful to hear!"
182
  confetti_effect()
183
  elif emotion == "sad":
184
  response = FACES["sad"] + "\n\n" + random.choice(HELP_RESPONSES)
185
  elif emotion == "love":
186
- response = FACES["love"] + "\n\nπŸ’– Love is in the air!"
 
 
187
  else:
188
  response = FACES["neutral"] + "\n\nTell me more about your feelings..."
189
 
@@ -191,10 +243,13 @@ if prompt := st.chat_input("How are you feeling today?"):
191
  st.session_state.messages.append({"role": "bot", "content": response})
192
 
193
  # Rerun to update the display
194
- st.experimental_rerun()
195
 
196
  # Add reset button
197
  if st.button("Reset Conversation"):
198
  st.session_state.messages = []
199
  st.session_state.current_emotion = "neutral"
200
- st.experimental_rerun()
 
 
 
 
11
  initial_sidebar_state="collapsed"
12
  )
13
 
14
+ # Custom CSS for enhanced light purple theme
15
  st.markdown("""
16
  <style>
17
  :root {
18
  --primary: #b19cd9;
19
+ --primary-dark: #8a7faa;
20
+ --background: linear-gradient(135deg, #f5f0ff, #e6d7ff);
21
  --secondary-background: #e6e0fa;
22
  --text: #4a4a4a;
23
  --font: "Arial", sans-serif;
24
  }
25
 
26
  body {
27
+ background-image: var(--background);
28
+ background-attachment: fixed;
29
  color: var(--text);
30
  font-family: var(--font);
31
  }
 
33
  .stTextInput>div>div>input {
34
  background-color: var(--secondary-background) !important;
35
  color: var(--text) !important;
36
+ border: 2px solid var(--primary) !important;
37
+ border-radius: 12px;
38
  }
39
 
40
  .stButton>button {
41
  background-color: var(--primary) !important;
42
  color: white !important;
43
  border: none;
44
+ border-radius: 12px;
45
  padding: 8px 16px;
46
+ transition: all 0.3s ease;
47
+ }
48
+
49
+ .stButton>button:hover {
50
+ background-color: var(--primary-dark) !important;
51
+ transform: scale(1.05);
52
  }
53
 
54
  .stMarkdown {
 
57
  }
58
 
59
  .chat-message {
60
+ padding: 12px 16px;
61
+ border-radius: 16px;
62
+ margin: 10px 0;
63
  max-width: 80%;
64
+ box-shadow: 0 2px 6px rgba(0,0,0,0.1);
65
  }
66
 
67
  .user-message {
68
  background-color: var(--secondary-background);
69
  margin-left: auto;
70
+ text-align: left;
71
+ border-bottom-right-radius: 4px;
72
  }
73
 
74
  .bot-message {
75
  background-color: var(--primary);
76
  color: white;
77
  margin-right: auto;
78
+ border-bottom-left-radius: 4px;
79
  }
80
 
81
  .face-container {
82
  text-align: center;
83
  padding: 20px;
84
+ background: rgba(255, 255, 255, 0.7);
85
+ backdrop-filter: blur(5px);
86
+ border-radius: 20px;
87
+ box-shadow: 0 8px 20px rgba(0,0,0,0.1);
88
+ margin: 20px auto;
89
+ max-width: 300px;
90
+ border: 2px solid var(--primary);
91
+ }
92
+
93
+ .header {
94
+ text-align: center;
95
+ margin-bottom: 20px;
96
+ }
97
+
98
+ .title {
99
+ color: var(--primary);
100
+ font-size: 2.5rem;
101
+ margin-bottom: 10px;
102
+ text-shadow: 1px 1px 3px rgba(0,0,0,0.1);
103
+ }
104
+
105
+ .subtitle {
106
+ color: var(--text);
107
+ font-size: 1.1rem;
108
+ margin-bottom: 30px;
109
+ }
110
+
111
+ .footer {
112
+ text-align: center;
113
+ margin-top: 30px;
114
+ color: var(--primary);
115
+ font-size: 0.9rem;
116
  }
117
  </style>
118
  """, unsafe_allow_html=True)
119
 
120
  # Emotion databases
121
+ POSITIVE_WORDS = {"happy", "awesome", "great", "joy", "excited", "good", "wonderful", "fantastic", "amazing", "yay", "ecstatic"}
122
+ NEGATIVE_WORDS = {"sad", "depressed", "angry", "cry", "lonely", "bad", "terrible", "awful", "miserable", "upset", "grief"}
123
+ LOVE_WORDS = {"love", "heart", "adore", "crush", "romance", "affection", "passion"}
124
  HELP_RESPONSES = [
125
  "Would you like to talk about it? πŸ’¬",
126
+ "I'm here to listen whenever you need πŸ’™",
127
  "Want some uplifting quotes? πŸ“œ",
128
  "Would a virtual hug help? πŸ€—",
129
+ "Let's focus on something positive 🌈",
130
+ "Remember: this too shall pass 🌀️"
131
  ]
132
 
133
  # ASCII Art Library
134
  FACES = {
135
  "happy": r"""
136
+ ╔════════════╗
137
+ πŸ˜„ AWESOME DAY!
138
+ β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•
139
  """,
140
  "sad": r"""
141
+ ╔════════════╗
142
+ 😒 TOUGH TIMES?
143
+ β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•
144
  """,
145
  "neutral": r"""
146
+ ╔════════════╗
147
+ 😐 HELLO THERE
148
+ β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•
149
  """,
150
  "love": r"""
151
+ ╔════════════╗
152
+ 😍 LOVELY FEELING!
153
+ β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•
154
+ """,
155
+ "angry": r"""
156
+ ╔════════════╗
157
+ 😠 TAKE A DEEP BREATH
158
+ β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•
159
  """
160
  }
161
 
 
171
 
172
  function fire(particleRatio, opts) {
173
  confetti(Object.assign({}, defaults, opts, {
174
+ particleCount: Math.floor(count * particleRatio),
175
+ colors: ['#b19cd9', '#e6d7ff', '#8a7faa', '#ffffff']
176
  }));
177
  }
178
 
 
192
  return "happy"
193
  elif any(word in text for word in NEGATIVE_WORDS):
194
  return "sad"
195
+ elif any(word in text for word in LOVE_WORDS):
196
  return "love"
197
+ elif "angry" in text or "mad" in text or "furious" in text:
198
+ return "angry"
199
  return "neutral"
200
 
201
  # Initialize chat history
 
203
  st.session_state.messages = []
204
  st.session_state.current_emotion = "neutral"
205
 
206
+ # Header with title and description
207
+ st.markdown('<div class="header"><div class="title">✨ Emotion Mirror Chatbot</div><div class="subtitle">I\'m a reactive AI agent that mirrors your emotions! Try words like <i>happy, sad, love,</i> or <i>awesome</i></div></div>', unsafe_allow_html=True)
 
208
 
209
  # Display current face
210
  with st.container():
 
228
 
229
  # Generate bot response
230
  if emotion == "happy":
231
+ response = FACES["happy"] + "\n\n🌟 That's wonderful to hear! Keep spreading positivity!"
232
  confetti_effect()
233
  elif emotion == "sad":
234
  response = FACES["sad"] + "\n\n" + random.choice(HELP_RESPONSES)
235
  elif emotion == "love":
236
+ response = FACES["love"] + "\n\nπŸ’– Love is the most beautiful feeling! Treasure it."
237
+ elif emotion == "angry":
238
+ response = FACES["angry"] + "\n\n☁️ Take a deep breath. Count to ten. You've got this."
239
  else:
240
  response = FACES["neutral"] + "\n\nTell me more about your feelings..."
241
 
 
243
  st.session_state.messages.append({"role": "bot", "content": response})
244
 
245
  # Rerun to update the display
246
+ st.rerun()
247
 
248
  # Add reset button
249
  if st.button("Reset Conversation"):
250
  st.session_state.messages = []
251
  st.session_state.current_emotion = "neutral"
252
+ st.rerun()
253
+
254
+ # Footer
255
+ st.markdown('<div class="footer">Made with ❀️ | Reactive AI Agent | Streamlit</div>', unsafe_allow_html=True)