vighnesh-shetty-vs commited on
Commit
4e510ce
Β·
1 Parent(s): 5db3c84

Add updated files

Browse files
Files changed (1) hide show
  1. app.py +80 -1
app.py CHANGED
@@ -292,6 +292,66 @@ def generate_victory_dashboard(state):
292
  except Exception as e:
293
  return f"<div style='color:red;'>Error generating dashboard: {str(e)}</div>"
294
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  # --- 3. EVENT HANDLERS ---
296
 
297
  def process_query(user_input, selected_model, state):
@@ -336,11 +396,19 @@ def process_query(user_input, selected_model, state):
336
  audio_path = generate_audio(dialogue)
337
  feedback_text = f"<div class='feedback-box'>🧠 <strong>{category.upper()}</strong> Detected!<br><br><em>\"{dialogue}\"</em></div>"
338
 
339
- if state["points"] >= 500 or state["water"] <= 0:
 
340
  state["game_over"] = True
341
  return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(), gr.update(visible=False),
342
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(value=""),
343
  gr.update(visible=False), gr.update(visible=True), gr.update(value=generate_victory_dashboard(state)))
 
 
 
 
 
 
 
344
 
345
  return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(value=feedback_text), gr.update(visible=True),
346
  gr.update(value=alt_choices[0], visible=True), gr.update(value=alt_choices[1], visible=True), gr.update(value=alt_choices[2], visible=True), gr.update(value=""), gr.update(value=""),
@@ -428,6 +496,17 @@ h1 { text-align: center; color: #38bdf8; text-shadow: 0 0 15px rgba(56, 189, 248
428
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
429
  100% { transform: translateY(1000px) rotate(720deg); opacity: 1; }
430
  }
 
 
 
 
 
 
 
 
 
 
 
431
  """
432
 
433
  with gr.Blocks(css=custom_css, title="EcoQueryQuest") as demo:
 
292
  except Exception as e:
293
  return f"<div style='color:red;'>Error generating dashboard: {str(e)}</div>"
294
 
295
+ def generate_defeat_dashboard(state):
296
+ """Generates a dark, Game Over report when Drip evaporates."""
297
+ try:
298
+ rows = ""
299
+ for item in state.get("history", []):
300
+ rows += f"""
301
+ <tr style="border-bottom: 1px solid rgba(255,255,255,0.1); background: rgba(0,0,0,0.2);">
302
+ <td style="padding: 15px; font-style: italic; color: #e2e8f0;">"{item.get('query', '')}"</td>
303
+ <td style="padding: 15px; color: #fca5a5; font-weight: bold; line-height: 1.5;">
304
+ πŸ’§ {item.get('water_ml', 0):.1f} mL<br>
305
+ ⚑ {item.get('energy_wh', 0):.2f} Wh<br>
306
+ ☁️ {item.get('co2_g', 0):.2f} g
307
+ </td>
308
+ </tr>
309
+ """
310
+
311
+ # Dynamically generate rising "ash/steam" particles
312
+ ash_elements = "".join([f'<div class="ash-piece" style="left: {random.randint(0, 100)}%; animation-duration: {random.uniform(3, 6)}s; animation-delay: {random.uniform(0, 2)}s;"></div>' for _ in range(60)])
313
+
314
+ return f"""
315
+ <div class="victory-wrapper">
316
+ {ash_elements}
317
+ <div class="defeat-dashboard">
318
+ <h1 class="defeat-title">πŸ’€ DRIP EVAPORATED! πŸ’€</h1>
319
+ <p style="text-align: center; font-size: 1.3em; color: #fca5a5; margin-bottom: 30px;">
320
+ You ran out of water before reaching 500 points. The planet's resources have been drained!
321
+ </p>
322
+
323
+ <div class="victory-stats-row">
324
+ <div class="v-stat-box" style="border-top: 4px solid #ef4444; background: rgba(239, 68, 68, 0.1);">
325
+ <h4 style="color: #ef4444;">Total Resources Wasted</h4>
326
+ <p style="color: #fca5a5; font-size: 1.3em; font-weight: bold; margin: 8px 0;">πŸ’§ 1.0 L (Tank Empty)</p>
327
+ <p style="color: #fca5a5; font-size: 1.3em; font-weight: bold; margin: 8px 0;">⚑ {state.get('energy', 0):.4f} kWh</p>
328
+ <p style="color: #fca5a5; font-size: 1.3em; font-weight: bold; margin: 8px 0;">☁️ {state.get('co2', 0):.2f} g</p>
329
+ </div>
330
+ <div class="v-stat-box" style="border-top: 4px solid #94a3b8;">
331
+ <h4 style="color: #94a3b8;">Final Score</h4>
332
+ <p style="color: white; font-size: 3.5em; font-weight: bold; margin: 10px 0;">{state.get('points', 0)}</p>
333
+ </div>
334
+ </div>
335
+
336
+ <h3 style="margin-top: 40px; color: #fca5a5; font-size: 1.8em; text-align: center;">πŸ”₯ Wasted Resources Log</h3>
337
+ <p style="opacity: 0.9; margin-bottom: 20px; text-align: center; color: #e2e8f0;">See exactly where your massive LLM compute drained Drip's tank.</p>
338
+
339
+ <div style="max-height: 400px; overflow-y: auto; background: rgba(15, 23, 42, 0.9); border-radius: 12px; border: 1px solid rgba(239, 68, 68, 0.3); padding: 10px;">
340
+ <table style="width: 100%; text-align: left; border-collapse: collapse; font-size: 1.05em;">
341
+ <tr style="background: rgba(239, 68, 68, 0.15); border-bottom: 2px solid #ef4444;">
342
+ <th style="padding: 15px; color: #fca5a5;">User Query</th>
343
+ <th style="padding: 15px; color: #fca5a5;">Resources Drained</th>
344
+ </tr>
345
+ {rows}
346
+ </table>
347
+ </div>
348
+ </div>
349
+ </div>
350
+ """
351
+ except Exception as e:
352
+ return f"<div style='color:red;'>Error generating dashboard: {str(e)}</div>"
353
+
354
+
355
  # --- 3. EVENT HANDLERS ---
356
 
357
  def process_query(user_input, selected_model, state):
 
396
  audio_path = generate_audio(dialogue)
397
  feedback_text = f"<div class='feedback-box'>🧠 <strong>{category.upper()}</strong> Detected!<br><br><em>\"{dialogue}\"</em></div>"
398
 
399
+ # Check for WIN condition
400
+ if state["points"] >= 500:
401
  state["game_over"] = True
402
  return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(), gr.update(visible=False),
403
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(value=""),
404
  gr.update(visible=False), gr.update(visible=True), gr.update(value=generate_victory_dashboard(state)))
405
+
406
+ # Check for LOSS condition
407
+ elif state["water"] <= 0:
408
+ state["game_over"] = True
409
+ return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(), gr.update(visible=False),
410
+ gr.update(), gr.update(), gr.update(), gr.update(), gr.update(value=""),
411
+ gr.update(visible=False), gr.update(visible=True), gr.update(value=generate_defeat_dashboard(state)))
412
 
413
  return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(value=feedback_text), gr.update(visible=True),
414
  gr.update(value=alt_choices[0], visible=True), gr.update(value=alt_choices[1], visible=True), gr.update(value=alt_choices[2], visible=True), gr.update(value=""), gr.update(value=""),
 
496
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
497
  100% { transform: translateY(1000px) rotate(720deg); opacity: 1; }
498
  }
499
+
500
+ /* Defeat Dashboard & Animations */
501
+ @keyframes pulseRed { 0% { box-shadow: 0 0 20px rgba(239, 68, 68, 0.4); } 50% { box-shadow: 0 0 60px rgba(239, 68, 68, 0.8); } 100% { box-shadow: 0 0 20px rgba(239, 68, 68, 0.4); } }
502
+ .defeat-dashboard { background: linear-gradient(135deg, #2b1010, #450a0a); padding: 40px; border-radius: 24px; border: 2px solid #ef4444; animation: pulseRed 2s infinite; color: white; position: relative; z-index: 5; margin-top: 20px; }
503
+ .defeat-title { text-align: center; color: #ef4444; font-size: 3.5em !important; text-shadow: 0 0 20px rgba(239, 68, 68, 0.8); margin-bottom: 5px; }
504
+ .ash-piece { position: absolute; width: 8px; height: 8px; background-color: rgba(156, 163, 175, 0.6); border-radius: 50%; opacity: 0; animation: floatAsh linear forwards infinite; z-index: 10; filter: blur(1px); }
505
+ @keyframes floatAsh {
506
+ 0% { transform: translateY(600px) scale(1); opacity: 0; }
507
+ 20% { opacity: 0.8; }
508
+ 100% { transform: translateY(-100px) scale(2); opacity: 0; }
509
+ }
510
  """
511
 
512
  with gr.Blocks(css=custom_css, title="EcoQueryQuest") as demo: