vighnesh-shetty-vs commited on
Commit
2b9a207
·
1 Parent(s): ab096dd

Add updated files

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -103,7 +103,8 @@ def calculate_impact(category, confidence_score, query_text, model_name):
103
  }
104
 
105
  def get_dialogue(water_level, category):
106
- state = "energetic" if water_level > 7.0 else ("tired" if water_level >= 3.0 else "raspy")
 
107
  return DIALOGUES[state].get(category, "I have no words left for this.")
108
 
109
  def generate_audio(text):
@@ -124,12 +125,13 @@ def get_relatable_translations(impact):
124
  return w_ex, e_ex, c_ex
125
 
126
  def get_stats_html(water, energy, co2, points):
127
- water_percent = max(0, min(100, (water / 10.0) * 100))
 
128
  return f"""
129
  <div class="stats-container">
130
  <div class="stat-card water-card">
131
- <div class="stat-label">WATER TANK (10L MAX)</div>
132
- <div class="stat-value">{water:.2f}L</div>
133
  <div class="progress-bar-bg"><div class="progress-bar-fill" style="width: {water_percent}%;"></div></div>
134
  </div>
135
  <div class="stat-card energy-card">
@@ -148,12 +150,13 @@ def get_stats_html(water, energy, co2, points):
148
  """
149
 
150
  def get_drip_visuals(water_level):
151
- if water_level > 7.0:
 
152
  g_start, g_end = "#7dd3fc", "#0369a1"
153
  mouth_d = "M43 112 Q60 122 77 112"
154
  cracks_op, sweat_op, tear_op = "0", "0", "0"
155
  mood, mood_color, anim = "Hydrated and coping", "rgb(34, 211, 238)", "bounce 2s infinite ease-in-out"
156
- elif 3.0 <= water_level <= 7.0:
157
  g_start, g_end = "#38bdf8", "#0284c7"
158
  mouth_d = "M43 112 Q60 110 77 112"
159
  cracks_op, sweat_op, tear_op = "0", "1", "0"
@@ -194,7 +197,7 @@ def get_drip_visuals(water_level):
194
  <div class="drip-mood" id="drip-mood" style="color: {mood_color}; font-weight: 500; font-size: 1.1rem; margin-top: 15px;">{mood}</div>
195
  <div style="text-align:center; margin-top:10px;">
196
  <div style="font-size:10px; color:#94a3b8; text-transform:uppercase; letter-spacing:1px;">Water Left</div>
197
- <div style="font-size:26px; font-weight:700; color:{mood_color};" id="d-water">{water_level:.2f}L</div>
198
  </div>
199
  </div>
200
  """
@@ -253,6 +256,7 @@ def generate_victory_dashboard(state):
253
  """
254
  confetti_elements = "".join([f'<div class="confetti-piece" style="left: {random.randint(0, 100)}%; background-color: hsl({random.randint(0, 360)}, 100%, 60%); animation-duration: {random.uniform(2.5, 5)}s; animation-delay: {random.uniform(0, 2)}s;"></div>' for _ in range(60)])
255
 
 
256
  return f"""
257
  <div class="victory-wrapper">
258
  {confetti_elements}
@@ -268,7 +272,7 @@ def generate_victory_dashboard(state):
268
  </div>
269
  <div class="v-stat-box" style="border-top: 4px solid #fca5a5;">
270
  <h4 style="color: #fca5a5;">Total Wasted</h4>
271
- <p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">💧 {10.0 - state.get('water', 10.0):.2f} L</p>
272
  <p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">⚡ {state.get('energy', 0):.4f} kWh</p>
273
  <p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">☁️ {state.get('co2', 0):.2f} g</p>
274
  </div>
@@ -408,8 +412,6 @@ h1 { text-align: center; color: #38bdf8; text-shadow: 0 0 15px rgba(56, 189, 248
408
  .alt-group { padding: 25px; background: linear-gradient(145deg, rgba(16, 185, 129, 0.05), rgba(6, 95, 70, 0.1)); border-radius: 20px; border: 1px solid rgba(16, 185, 129, 0.3); margin-top: 25px; box-shadow: 0 10px 30px rgba(0,0,0,0.2);}
409
  .alt-card { background: linear-gradient(145deg, #1e293b, #0f172a) !important; border: 1px solid #10b981 !important; color: #a7f3d0 !important; height: auto !important; min-height: 180px !important; border-radius: 16px !important; font-size: 1.05em !important; font-weight: 500 !important; white-space: pre-wrap !important; line-height: 1.5 !important; padding: 15px !important; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important; cursor: pointer; box-shadow: 0 4px 15px rgba(0,0,0,0.4) !important;}
410
  .alt-card:hover { background: linear-gradient(145deg, #064e3b, #065f46) !important; transform: translateY(-8px) !important; box-shadow: 0 12px 30px rgba(16, 185, 129, 0.3) !important; color: white !important; border-color: #34d399 !important;}
411
-
412
- /* Fix Dropdown styling for completely proper selection only */
413
  .custom-dropdown { background: rgba(30, 41, 59, 0.8) !important; border: 1px solid #38bdf8 !important; border-radius: 12px !important; }
414
 
415
  /* Victory Dashboard & Celebration */
@@ -429,6 +431,7 @@ h1 { text-align: center; color: #38bdf8; text-shadow: 0 0 15px rgba(56, 189, 248
429
  """
430
 
431
  with gr.Blocks(css=custom_css, title="EcoQueryQuest") as demo:
 
432
  game_state = gr.State({
433
  "water": 1.0, "energy": 0.0, "co2": 0.0, "points": 0, "queries": 0,
434
  "history": [], "game_over": False, "current_best_alt": None, "current_shuffled_alts": []
@@ -437,20 +440,19 @@ with gr.Blocks(css=custom_css, title="EcoQueryQuest") as demo:
437
  gr.Markdown("<h1>🌍 EcoQueryQuest</h1>")
438
  gr.Markdown("<div class='subtitle'>Select a model, type a query, and watch Drip react. Reach 500 points to win!</div>")
439
 
440
- stats_html = gr.HTML(get_stats_html(10.0, 0.0, 0.0, 0))
 
441
 
442
  with gr.Column(visible=True) as main_game_ui:
443
  with gr.Row():
444
  with gr.Column(scale=1, elem_classes=["drip-pod"]):
445
- drip_html = gr.HTML(get_drip_visuals(10.0))
446
- # The audio component remains visible=True natively so it autoplays, but is visually hidden via CSS wrapper classes
447
  drip_audio = gr.Audio(label="Drip's Voice", autoplay=True, interactive=False, elem_classes=["hidden-audio"])
448
  drip_feedback = gr.HTML("<div class='feedback-box'>Waiting for your first query...</div>")
449
 
450
  with gr.Column(scale=2):
451
- # Ensure dropdown is the ONLY dropdown, strictly interactive but not allowing custom user values to protect scaling logic
452
  model_selector = gr.Dropdown(choices=list(MODELS.keys()), value="GPT-5.4", label="Select Target LLM Backend", elem_classes=["custom-dropdown"], interactive=True, allow_custom_value=False)
453
-
454
  with gr.Row(elem_classes=["input-row"]):
455
  user_input = gr.Textbox(show_label=False, placeholder="Type your query here...", elem_classes=["custom-textbox"], scale=4, lines=3)
456
  submit_btn = gr.Button("Send Query", elem_classes=["custom-btn"], scale=1)
 
103
  }
104
 
105
  def get_dialogue(water_level, category):
106
+ # Adjusted dialogue thresholds for 1L max
107
+ state = "energetic" if water_level > 0.7 else ("tired" if water_level >= 0.3 else "raspy")
108
  return DIALOGUES[state].get(category, "I have no words left for this.")
109
 
110
  def generate_audio(text):
 
125
  return w_ex, e_ex, c_ex
126
 
127
  def get_stats_html(water, energy, co2, points):
128
+ # Updated progress bar logic for a 1.0L maximum
129
+ water_percent = max(0, min(100, (water / 1.0) * 100))
130
  return f"""
131
  <div class="stats-container">
132
  <div class="stat-card water-card">
133
+ <div class="stat-label">WATER TANK (1L MAX)</div>
134
+ <div class="stat-value">{water:.3f}L</div>
135
  <div class="progress-bar-bg"><div class="progress-bar-fill" style="width: {water_percent}%;"></div></div>
136
  </div>
137
  <div class="stat-card energy-card">
 
150
  """
151
 
152
  def get_drip_visuals(water_level):
153
+ # Adjusted visual state thresholds for 1.0L maximum
154
+ if water_level > 0.7:
155
  g_start, g_end = "#7dd3fc", "#0369a1"
156
  mouth_d = "M43 112 Q60 122 77 112"
157
  cracks_op, sweat_op, tear_op = "0", "0", "0"
158
  mood, mood_color, anim = "Hydrated and coping", "rgb(34, 211, 238)", "bounce 2s infinite ease-in-out"
159
+ elif 0.3 <= water_level <= 0.7:
160
  g_start, g_end = "#38bdf8", "#0284c7"
161
  mouth_d = "M43 112 Q60 110 77 112"
162
  cracks_op, sweat_op, tear_op = "0", "1", "0"
 
197
  <div class="drip-mood" id="drip-mood" style="color: {mood_color}; font-weight: 500; font-size: 1.1rem; margin-top: 15px;">{mood}</div>
198
  <div style="text-align:center; margin-top:10px;">
199
  <div style="font-size:10px; color:#94a3b8; text-transform:uppercase; letter-spacing:1px;">Water Left</div>
200
+ <div style="font-size:26px; font-weight:700; color:{mood_color};" id="d-water">{water_level:.3f}L</div>
201
  </div>
202
  </div>
203
  """
 
256
  """
257
  confetti_elements = "".join([f'<div class="confetti-piece" style="left: {random.randint(0, 100)}%; background-color: hsl({random.randint(0, 360)}, 100%, 60%); animation-duration: {random.uniform(2.5, 5)}s; animation-delay: {random.uniform(0, 2)}s;"></div>' for _ in range(60)])
258
 
259
+ # Updated "Total Wasted" formula from 10.0 to 1.0 to reflect the 1L tank
260
  return f"""
261
  <div class="victory-wrapper">
262
  {confetti_elements}
 
272
  </div>
273
  <div class="v-stat-box" style="border-top: 4px solid #fca5a5;">
274
  <h4 style="color: #fca5a5;">Total Wasted</h4>
275
+ <p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">💧 {1.0 - state.get('water', 1.0):.3f} L</p>
276
  <p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">⚡ {state.get('energy', 0):.4f} kWh</p>
277
  <p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">☁️ {state.get('co2', 0):.2f} g</p>
278
  </div>
 
412
  .alt-group { padding: 25px; background: linear-gradient(145deg, rgba(16, 185, 129, 0.05), rgba(6, 95, 70, 0.1)); border-radius: 20px; border: 1px solid rgba(16, 185, 129, 0.3); margin-top: 25px; box-shadow: 0 10px 30px rgba(0,0,0,0.2);}
413
  .alt-card { background: linear-gradient(145deg, #1e293b, #0f172a) !important; border: 1px solid #10b981 !important; color: #a7f3d0 !important; height: auto !important; min-height: 180px !important; border-radius: 16px !important; font-size: 1.05em !important; font-weight: 500 !important; white-space: pre-wrap !important; line-height: 1.5 !important; padding: 15px !important; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important; cursor: pointer; box-shadow: 0 4px 15px rgba(0,0,0,0.4) !important;}
414
  .alt-card:hover { background: linear-gradient(145deg, #064e3b, #065f46) !important; transform: translateY(-8px) !important; box-shadow: 0 12px 30px rgba(16, 185, 129, 0.3) !important; color: white !important; border-color: #34d399 !important;}
 
 
415
  .custom-dropdown { background: rgba(30, 41, 59, 0.8) !important; border: 1px solid #38bdf8 !important; border-radius: 12px !important; }
416
 
417
  /* Victory Dashboard & Celebration */
 
431
  """
432
 
433
  with gr.Blocks(css=custom_css, title="EcoQueryQuest") as demo:
434
+ # UPDATED to start with 1.0 Liters
435
  game_state = gr.State({
436
  "water": 1.0, "energy": 0.0, "co2": 0.0, "points": 0, "queries": 0,
437
  "history": [], "game_over": False, "current_best_alt": None, "current_shuffled_alts": []
 
440
  gr.Markdown("<h1>🌍 EcoQueryQuest</h1>")
441
  gr.Markdown("<div class='subtitle'>Select a model, type a query, and watch Drip react. Reach 500 points to win!</div>")
442
 
443
+ # UPDATED to start UI with 1.0 Liters
444
+ stats_html = gr.HTML(get_stats_html(1.0, 0.0, 0.0, 0))
445
 
446
  with gr.Column(visible=True) as main_game_ui:
447
  with gr.Row():
448
  with gr.Column(scale=1, elem_classes=["drip-pod"]):
449
+ # UPDATED to start Drip visual with 1.0 Liters
450
+ drip_html = gr.HTML(get_drip_visuals(1.0))
451
  drip_audio = gr.Audio(label="Drip's Voice", autoplay=True, interactive=False, elem_classes=["hidden-audio"])
452
  drip_feedback = gr.HTML("<div class='feedback-box'>Waiting for your first query...</div>")
453
 
454
  with gr.Column(scale=2):
 
455
  model_selector = gr.Dropdown(choices=list(MODELS.keys()), value="GPT-5.4", label="Select Target LLM Backend", elem_classes=["custom-dropdown"], interactive=True, allow_custom_value=False)
 
456
  with gr.Row(elem_classes=["input-row"]):
457
  user_input = gr.Textbox(show_label=False, placeholder="Type your query here...", elem_classes=["custom-textbox"], scale=4, lines=3)
458
  submit_btn = gr.Button("Send Query", elem_classes=["custom-btn"], scale=1)