qaisar701shan commited on
Commit
e6a74d8
Β·
verified Β·
1 Parent(s): 106293e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -212
app.py CHANGED
@@ -18,7 +18,7 @@ html, body {
18
  overflow-x: hidden;
19
  }
20
  .stApp {
21
- background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%) !important;
22
  }
23
  .chat-container {
24
  position: fixed;
@@ -121,209 +121,62 @@ html, body {
121
  </style>
122
  """, unsafe_allow_html=True)
123
 
124
- # ----------------- Premium Celebration Effects -----------------
125
  def show_confetti():
 
126
  confetti_js = """
127
- <script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.6.0/dist/confetti.browser.min.js"></script>
128
  <script>
129
  (function() {
130
- // Create container if it doesn't exist
131
- let container = document.getElementById('confetti-container');
132
- if (!container) {
133
- container = document.createElement('div');
134
- container.id = 'confetti-container';
135
- container.className = 'celebration-container';
136
- document.body.appendChild(container);
137
- }
138
-
139
- // Make canvas full screen
140
- const canvas = document.createElement('canvas');
141
- canvas.style.width = '100%';
142
- canvas.style.height = '100%';
143
- canvas.style.position = 'absolute';
144
- canvas.style.top = '0';
145
- canvas.style.left = '0';
146
- container.appendChild(canvas);
147
-
148
- const myConfetti = confetti.create(canvas, {
149
- resize: true,
150
- useWorker: true
151
- });
152
-
153
- // Enhanced confetti with emojis and shapes
154
- const emojis = ['✨', '⭐', '🌟', '🎊', 'πŸŽ‰', 'πŸ’–', '😊', '🌈'];
155
- const duration = 3000;
156
- const end = Date.now() + duration;
157
- const colors = ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff', '#00ffff'];
158
-
159
- function frame() {
160
- // Standard confetti
161
- myConfetti({
162
- particleCount: 100,
163
- angle: 60,
164
- spread: 55,
165
- origin: { x: 0 },
166
- colors: colors
167
- });
168
- myConfetti({
169
- particleCount: 100,
170
- angle: 120,
171
- spread: 55,
172
- origin: { x: 1 },
173
- colors: colors
174
- });
175
-
176
- // Emoji confetti
177
- if (Date.now() % 100 < 30) {
178
- myConfetti({
179
- particleCount: 5,
180
- spread: 70,
181
- shapes: ['text'],
182
- shapeOptions: {
183
- text: {
184
- value: emojis[Math.floor(Math.random() * emojis.length)],
185
- fontSize: 24
186
- }
187
- },
188
- origin: { y: 0.7 }
189
- });
190
- }
191
-
192
- // Stars
193
- if (Date.now() % 100 < 20) {
194
- myConfetti({
195
- particleCount: 15,
196
- spread: 50,
197
- shapes: ['star'],
198
- shapeOptions: {
199
- star: {
200
- fill: true,
201
- points: 5
202
- }
203
- },
204
- colors: ['#FFD700', '#FFA500', '#FF6347'],
205
- origin: { y: 0.6 }
206
- });
207
- }
208
-
209
- if (Date.now() < end) {
210
- requestAnimationFrame(frame);
211
- } else {
212
- canvas.remove();
213
- }
214
- }
215
-
216
- frame();
217
- })();
218
- </script>
219
- """
220
- html(confetti_js, height=0, width=0)
221
-
222
- def show_balloons():
223
- balloon_js = """
224
- <script>
225
- (function() {
226
- // Create container if it doesn't exist
227
- let container = document.getElementById('balloon-container');
228
- if (!container) {
229
- container = document.createElement('div');
230
- container.id = 'balloon-container';
231
- container.className = 'celebration-container';
232
- document.body.appendChild(container);
233
- }
234
 
235
- // Balloon styles
236
- const styles = document.createElement('style');
237
- styles.innerHTML = `
238
- @keyframes floatUp {
239
- 0% { transform: translateY(100vh) translateX(0) rotate(0deg); opacity: 1; }
240
- 80% { opacity: 0.8; }
241
- 100% { transform: translateY(-50vh) translateX(var(--random-x)) rotate(360deg); opacity: 0; }
242
- }
243
- .balloon {
244
- position: absolute;
245
- bottom: -100px;
246
- width: var(--size);
247
- height: calc(var(--size) * 1.3);
248
- border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
249
- box-shadow: inset -10px -10px 15px rgba(0,0,0,0.2);
250
- animation: floatUp var(--duration) ease-in forwards;
251
- z-index: 10;
252
- }
253
- .balloon-string {
254
- position: absolute;
255
- bottom: -15px;
256
- left: 50%;
257
- width: 2px;
258
- height: 30px;
259
- background-color: rgba(0,0,0,0.2);
260
- transform: translateX(-50%);
261
- }
262
- .balloon-emoji {
263
- position: absolute;
264
- top: 25%;
265
- left: 50%;
266
- transform: translateX(-50%);
267
- font-size: calc(var(--size) * 0.4);
268
- z-index: 11;
269
- }
270
- `;
271
- document.head.appendChild(styles);
272
 
273
- // Balloon colors and emojis
274
- const colors = [
275
- 'radial-gradient(circle at 30% 30%, #FF6B6B, #FF0000)',
276
- 'radial-gradient(circle at 30% 30%, #4ECDC4, #00A8A8)',
277
- 'radial-gradient(circle at 30% 30%, #FFBE0B, #FF8C00)',
278
- 'radial-gradient(circle at 30% 30%, #9370DB, #663399)',
279
- 'radial-gradient(circle at 30% 30%, #3A86FF, #0038A8)',
280
- 'radial-gradient(circle at 30% 30%, #FF69B4, #FF1493)'
281
- ];
282
-
283
- const emojis = ['🎈', 'πŸŽ‰', '🎊', 'πŸ’–', '😊', '✨', '🎁', '🌟'];
284
-
285
- // Create 50 premium balloons
286
- for (let i = 0; i < 50; i++) {
287
  setTimeout(() => {
288
- const balloon = document.createElement('div');
289
- balloon.className = 'balloon';
290
-
291
- // Random properties
292
- const size = 60 + Math.random() * 60;
293
- const duration = 5 + Math.random() * 3;
294
- const xPos = Math.random() * 100;
295
- const xMovement = (Math.random() - 0.5) * 200;
296
- const color = colors[Math.floor(Math.random() * colors.length)];
297
- const emoji = emojis[Math.floor(Math.random() * emojis.length)];
298
-
299
- // Apply properties
300
- balloon.style.setProperty('--size', `${size}px`);
301
- balloon.style.setProperty('--duration', `${duration}s`);
302
- balloon.style.setProperty('--random-x', `${xMovement}px`);
303
- balloon.style.background = color;
304
- balloon.style.left = `${xPos}%`;
305
 
306
- // Add string
307
- const string = document.createElement('div');
308
- string.className = 'balloon-string';
309
- balloon.appendChild(string);
 
 
 
 
 
310
 
311
- // Add emoji
312
- const emojiEl = document.createElement('div');
313
- emojiEl.className = 'balloon-emoji';
314
- emojiEl.textContent = emoji;
315
- balloon.appendChild(emojiEl);
316
 
317
- container.appendChild(balloon);
318
-
319
- // Remove after animation
320
- setTimeout(() => balloon.remove(), duration * 1000);
321
- }, i * 150);
322
  }
 
 
323
  })();
324
  </script>
325
  """
326
- html(balloon_js, height=0, width=0)
 
 
 
 
 
 
 
 
327
 
328
  # ----------------- Content Collections -----------------
329
  JOKES = [
@@ -360,20 +213,6 @@ GAMES = {
360
  "Movies or TV shows?",
361
  "Books or video games?",
362
  "City life or country life?"
363
- ],
364
- "20 Questions": [
365
- "Think of an animal and I'll try to guess it!",
366
- "Think of a famous person and I'll ask questions",
367
- "Choose a movie and I'll figure it out",
368
- "Pick a country and I'll guess it",
369
- "Imagine a food and I'll discover what it is"
370
- ],
371
- "Story Building": [
372
- "Let's create a story together - you start!",
373
- "I'll begin a story and you continue it",
374
- "We'll alternate sentences to build a tale",
375
- "Create a story where the main character is a talking pizza",
376
- "Make up a story about a magical pair of shoes"
377
  ]
378
  }
379
 
@@ -404,6 +243,7 @@ if "chat_memory" not in st.session_state:
404
  def add_to_chat(bot_message: str):
405
  st.session_state.history.append({"user": "", "bot": bot_message})
406
  st.session_state.show_chat = True
 
407
 
408
  def load_models():
409
  if not st.session_state.models_loaded:
@@ -454,15 +294,19 @@ if col3.button("πŸ’‘ Get advice", key="main_advice"):
454
 
455
  # Enhanced Celebration buttons
456
  st.markdown("### Need some cheer?")
457
- celeb_col1, celeb_col2 = st.columns(2)
458
 
459
- if celeb_col1.button("πŸŽ‰ Premium Confetti", key="confetti"):
460
  show_confetti()
461
- add_to_chat("Enjoy this premium confetti shower! ✨🌟")
462
 
463
- if celeb_col2.button("🎈 Premium Balloons", key="balloons"):
464
  show_balloons()
465
- add_to_chat("Here come the premium balloons! οΏ½πŸŽ‰")
 
 
 
 
466
 
467
  # Chat input
468
  user_input = st.text_input("πŸ’¬ Say something to SentiPal...", key="chat_input")
@@ -478,6 +322,7 @@ if st.button("Send", key="send_button") and user_input.strip():
478
  "bot": reply + f"\n\n_(detected emotion: **{emotion}**, {confidence*100:.1f}%)_"
479
  })
480
  st.session_state.show_chat = True
 
481
 
482
  # ----------------- Chat Display -----------------
483
  if st.session_state.history:
@@ -493,6 +338,10 @@ if st.session_state.history:
493
  st.markdown(f'<div class="bot-message">SentiPal: {item["bot"]}</div>', unsafe_allow_html=True)
494
 
495
  if st.button("Close Chat", key="close_chat", type="primary"):
496
- st.session_state.show_chat = False
497
-
498
- st.markdown("</div>", unsafe_allow_html=True)
 
 
 
 
 
18
  overflow-x: hidden;
19
  }
20
  .stApp {
21
+ background: linear-gradient(135deg, #ff9a9e 0%, #c90076 100%) !important;
22
  }
23
  .chat-container {
24
  position: fixed;
 
121
  </style>
122
  """, unsafe_allow_html=True)
123
 
124
+ # ----------------- Celebration Effects -----------------
125
  def show_confetti():
126
+ # Simple confetti that works in Hugging Face Spaces
127
  confetti_js = """
 
128
  <script>
129
  (function() {
130
+ const container = document.createElement('div');
131
+ container.className = 'celebration-container';
132
+ document.body.appendChild(container);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
 
134
+ const colors = ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff'];
135
+ const emojis = ['✨', '🌟', 'πŸŽ‰'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
+ for (let i = 0; i < 100; i++) {
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  setTimeout(() => {
139
+ const confetti = document.createElement('div');
140
+ confetti.style.position = 'absolute';
141
+ confetti.style.width = '15px';
142
+ confetti.style.height = '15px';
143
+ confetti.style.left = Math.random() * 100 + 'vw';
144
+ confetti.style.top = '-20px';
 
 
 
 
 
 
 
 
 
 
 
145
 
146
+ if (Math.random() > 0.7) {
147
+ // Emoji confetti
148
+ confetti.textContent = emojis[Math.floor(Math.random() * emojis.length)];
149
+ confetti.style.fontSize = '20px';
150
+ } else {
151
+ // Color confetti
152
+ confetti.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
153
+ confetti.style.borderRadius = '50%';
154
+ }
155
 
156
+ const duration = 3000 + Math.random() * 2000;
157
+ confetti.animate([
158
+ { top: '-20px', opacity: 1 },
159
+ { top: '100vh', opacity: 0 }
160
+ ], { duration: duration, easing: 'cubic-bezier(0.1,0.8,0.3,1)' });
161
 
162
+ container.appendChild(confetti);
163
+ setTimeout(() => confetti.remove(), duration);
164
+ }, i * 30);
 
 
165
  }
166
+
167
+ setTimeout(() => container.remove(), 5000);
168
  })();
169
  </script>
170
  """
171
+ html(confetti_js, height=0, width=0)
172
+
173
+ def show_balloons():
174
+ # Use Streamlit's built-in balloons which work everywhere
175
+ st.balloons()
176
+
177
+ def show_snow():
178
+ # Use Streamlit's built-in snow which work everywhere
179
+ st.snow()
180
 
181
  # ----------------- Content Collections -----------------
182
  JOKES = [
 
213
  "Movies or TV shows?",
214
  "Books or video games?",
215
  "City life or country life?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  ]
217
  }
218
 
 
243
  def add_to_chat(bot_message: str):
244
  st.session_state.history.append({"user": "", "bot": bot_message})
245
  st.session_state.show_chat = True
246
+ # show_balloons() # Show balloons on any interaction
247
 
248
  def load_models():
249
  if not st.session_state.models_loaded:
 
294
 
295
  # Enhanced Celebration buttons
296
  st.markdown("### Need some cheer?")
297
+ celeb_col1, celeb_col2, celeb_col3 = st.columns(3)
298
 
299
+ if celeb_col1.button("πŸŽ‰ Confetti", key="confetti"):
300
  show_confetti()
301
+ add_to_chat("Enjoy the confetti! ✨")
302
 
303
+ if celeb_col2.button("🎈 Balloons", key="balloons"):
304
  show_balloons()
305
+ add_to_chat("Here come the balloons! 🎈")
306
+
307
+ if celeb_col3.button("❄️ Snow", key="snow"):
308
+ show_snow()
309
+ add_to_chat("Snow is falling! ❄️")
310
 
311
  # Chat input
312
  user_input = st.text_input("πŸ’¬ Say something to SentiPal...", key="chat_input")
 
322
  "bot": reply + f"\n\n_(detected emotion: **{emotion}**, {confidence*100:.1f}%)_"
323
  })
324
  st.session_state.show_chat = True
325
+ show_balloons() # Show balloons on message send
326
 
327
  # ----------------- Chat Display -----------------
328
  if st.session_state.history:
 
338
  st.markdown(f'<div class="bot-message">SentiPal: {item["bot"]}</div>', unsafe_allow_html=True)
339
 
340
  if st.button("Close Chat", key="close_chat", type="primary"):
341
+ #st.session_state.show_chat = False
342
+ for key in list(st.session_state.keys()):
343
+ del st.session_state[key]
344
+ st.rerun()
345
+
346
+ st.markdown("</div>", unsafe_allow_html=True)
347
+