vighnesh-shetty-vs commited on
Commit
81e6f72
·
1 Parent(s): b746835

Add updated files

Browse files
Files changed (2) hide show
  1. app.py +12 -12
  2. dialogues.py +6 -5
app.py CHANGED
@@ -25,13 +25,16 @@ def generate_audio(text):
25
  return filepath
26
 
27
  def get_stats_html(water, energy, co2, points):
 
 
 
28
  return f"""
29
  <div class="stats-container">
30
  <div class="stat-card water-card">
31
- <div class="stat-label">WATER TANK</div>
32
  <div class="stat-value">{water:.2f}L</div>
33
  <div class="progress-bar-bg">
34
- <div class="progress-bar-fill" style="width: {water}%;"></div>
35
  </div>
36
  </div>
37
  <div class="stat-card energy-card">
@@ -50,13 +53,14 @@ def get_stats_html(water, energy, co2, points):
50
  """
51
 
52
  def get_drip_visuals(water_level):
53
- if water_level > 70:
 
54
  g_start, g_end = "#7dd3fc", "#0369a1"
55
  mouth_d = "M43 112 Q60 122 77 112"
56
  cracks_op, sweat_op, tear_op = "0", "0", "0"
57
- mood, mood_color = "Hydrated and (barely) coping", "rgb(34, 211, 238)"
58
  anim = "bounce 2s infinite ease-in-out"
59
- elif 30 <= water_level <= 70:
60
  g_start, g_end = "#38bdf8", "#0284c7"
61
  mouth_d = "M43 112 Q60 110 77 112"
62
  cracks_op, sweat_op, tear_op = "0", "1", "0"
@@ -140,7 +144,6 @@ def format_alt_button(text):
140
 
141
  def process_query(user_input, selected_model, state):
142
  if state["game_over"] or not user_input.strip():
143
- # Notice we are returning an extra update at the end for the user_input box
144
  return [state, gr.update()] + [gr.update()]*9 + [gr.update()]
145
 
146
  result = classifier(user_input, CATEGORIES)
@@ -179,7 +182,6 @@ def process_query(user_input, selected_model, state):
179
  state["game_over"] = True
180
  return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(value="<div class='feedback-box'>Game Over! Check your score.</div>"), gr.update(visible=False), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(value=""))
181
 
182
- # The 12th return item is the empty string to clear the user_input
183
  return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(value=feedback_text), gr.update(visible=show_alts),
184
  gr.update(value=alt_choices[0]), gr.update(value=alt_choices[1]), gr.update(value=alt_choices[2]), gr.update(value=""), gr.update(value=""))
185
 
@@ -243,10 +245,8 @@ h1 { text-align: center; color: #38bdf8; text-shadow: 0 0 15px rgba(56, 189, 248
243
  .custom-dropdown { background: rgba(30, 41, 59, 0.8) !important; border: 1px solid #38bdf8 !important; border-radius: 12px !important; }
244
  """
245
 
246
- # ... (Keep all your CSS, HTML, and helper functions above exactly the same) ...
247
-
248
  with gr.Blocks(title="EcoQueryQuest") as demo:
249
- # 1. Update the starting game state to 10.0 Liters
250
  game_state = gr.State({
251
  "water": 10.0, "energy": 0.0, "co2": 0.0, "points": 0, "queries": 0,
252
  "history": [], "game_over": False, "current_best_alt": None, "current_shuffled_alts": []
@@ -255,12 +255,12 @@ with gr.Blocks(title="EcoQueryQuest") as demo:
255
  gr.Markdown("<h1>🌍 EcoQueryQuest</h1>")
256
  gr.Markdown("<div class='subtitle'>Select a model, type a query, and watch Drip react. Reach 500 points to win!</div>")
257
 
258
- # 2. Update the initial stats HTML render to 10.0 Liters
259
  stats_html = gr.HTML(get_stats_html(10.0, 0.0, 0.0, 0))
260
 
261
  with gr.Row():
262
  with gr.Column(scale=1, elem_classes=["drip-pod"]):
263
- # 3. Update the initial Drip visual render to 10.0 Liters
264
  drip_html = gr.HTML(get_drip_visuals(10.0))
265
  drip_audio = gr.Audio(label="Drip's Voice", autoplay=True, interactive=False, elem_classes=["drip-audio"])
266
  drip_feedback = gr.HTML("<div class='feedback-box'>Waiting for your first query...</div>")
 
25
  return filepath
26
 
27
  def get_stats_html(water, energy, co2, points):
28
+ # Calculate percentage for the progress bar based on a 10L max
29
+ water_percent = max(0, min(100, (water / 10.0) * 100))
30
+
31
  return f"""
32
  <div class="stats-container">
33
  <div class="stat-card water-card">
34
+ <div class="stat-label">WATER TANK (10L MAX)</div>
35
  <div class="stat-value">{water:.2f}L</div>
36
  <div class="progress-bar-bg">
37
+ <div class="progress-bar-fill" style="width: {water_percent}%;"></div>
38
  </div>
39
  </div>
40
  <div class="stat-card energy-card">
 
53
  """
54
 
55
  def get_drip_visuals(water_level):
56
+ # Adjusted visual thresholds for a 10L max
57
+ if water_level > 7.0:
58
  g_start, g_end = "#7dd3fc", "#0369a1"
59
  mouth_d = "M43 112 Q60 122 77 112"
60
  cracks_op, sweat_op, tear_op = "0", "0", "0"
61
+ mood, mood_color = "Hydrated and coping", "rgb(34, 211, 238)"
62
  anim = "bounce 2s infinite ease-in-out"
63
+ elif 3.0 <= water_level <= 7.0:
64
  g_start, g_end = "#38bdf8", "#0284c7"
65
  mouth_d = "M43 112 Q60 110 77 112"
66
  cracks_op, sweat_op, tear_op = "0", "1", "0"
 
144
 
145
  def process_query(user_input, selected_model, state):
146
  if state["game_over"] or not user_input.strip():
 
147
  return [state, gr.update()] + [gr.update()]*9 + [gr.update()]
148
 
149
  result = classifier(user_input, CATEGORIES)
 
182
  state["game_over"] = True
183
  return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(value="<div class='feedback-box'>Game Over! Check your score.</div>"), gr.update(visible=False), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(value=""))
184
 
 
185
  return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(value=feedback_text), gr.update(visible=show_alts),
186
  gr.update(value=alt_choices[0]), gr.update(value=alt_choices[1]), gr.update(value=alt_choices[2]), gr.update(value=""), gr.update(value=""))
187
 
 
245
  .custom-dropdown { background: rgba(30, 41, 59, 0.8) !important; border: 1px solid #38bdf8 !important; border-radius: 12px !important; }
246
  """
247
 
 
 
248
  with gr.Blocks(title="EcoQueryQuest") as demo:
249
+ # Set the starting game state back to 10L
250
  game_state = gr.State({
251
  "water": 10.0, "energy": 0.0, "co2": 0.0, "points": 0, "queries": 0,
252
  "history": [], "game_over": False, "current_best_alt": None, "current_shuffled_alts": []
 
255
  gr.Markdown("<h1>🌍 EcoQueryQuest</h1>")
256
  gr.Markdown("<div class='subtitle'>Select a model, type a query, and watch Drip react. Reach 500 points to win!</div>")
257
 
258
+ # Set the initial UI render to 10L
259
  stats_html = gr.HTML(get_stats_html(10.0, 0.0, 0.0, 0))
260
 
261
  with gr.Row():
262
  with gr.Column(scale=1, elem_classes=["drip-pod"]):
263
+ # Render initial Drip at 10L
264
  drip_html = gr.HTML(get_drip_visuals(10.0))
265
  drip_audio = gr.Audio(label="Drip's Voice", autoplay=True, interactive=False, elem_classes=["drip-audio"])
266
  drip_feedback = gr.HTML("<div class='feedback-box'>Waiting for your first query...</div>")
dialogues.py CHANGED
@@ -1,17 +1,17 @@
1
  DIALOGUES = {
2
- "energetic": { # >70L
3
  "simple factual question": "A simple fact! Look at you, saving my precious drops. Keep it up!",
4
  "mathematical calculation": "Math? Easy peasy! Barely broke a sweat, or, well, evaporated a drop.",
5
  "creative content generation": "Getting creative, are we? I'm feeling generous today, so I'll let it slide, but watch my levels!",
6
  "complex research query": "Deep dive! Okay, I've got the energy for this right now, but it's costing us!"
7
  },
8
- "tired": { # 30-70L
9
  "simple factual question": "*Sigh* Fine. Here's your fact. But maybe try a book next time?",
10
  "mathematical calculation": "I guess I can crunch those numbers. But my reserves are dropping...",
11
  "creative content generation": "Oh great, another essay request! I was planning to hydrate a small village, but your creativity is clearly more important.",
12
  "complex research query": "You're really draining me here. Do you *really* need me for this massive search?"
13
  },
14
- "raspy": { # <30L
15
  "simple factual question": "Barely... hanging... on... just Google it next time, please...",
16
  "mathematical calculation": "*Cough* Grab a calculator... I'm evaporating...",
17
  "creative content generation": "Evaporating... for a poem... what a cruel world...",
@@ -20,9 +20,10 @@ DIALOGUES = {
20
  }
21
 
22
  def get_dialogue(water_level, category):
23
- if water_level > 70:
 
24
  state = "energetic"
25
- elif 30 <= water_level <= 70:
26
  state = "tired"
27
  else:
28
  state = "raspy"
 
1
  DIALOGUES = {
2
+ "energetic": { # > 7.0L
3
  "simple factual question": "A simple fact! Look at you, saving my precious drops. Keep it up!",
4
  "mathematical calculation": "Math? Easy peasy! Barely broke a sweat, or, well, evaporated a drop.",
5
  "creative content generation": "Getting creative, are we? I'm feeling generous today, so I'll let it slide, but watch my levels!",
6
  "complex research query": "Deep dive! Okay, I've got the energy for this right now, but it's costing us!"
7
  },
8
+ "tired": { # 3.0L - 7.0L
9
  "simple factual question": "*Sigh* Fine. Here's your fact. But maybe try a book next time?",
10
  "mathematical calculation": "I guess I can crunch those numbers. But my reserves are dropping...",
11
  "creative content generation": "Oh great, another essay request! I was planning to hydrate a small village, but your creativity is clearly more important.",
12
  "complex research query": "You're really draining me here. Do you *really* need me for this massive search?"
13
  },
14
+ "raspy": { # < 3.0L
15
  "simple factual question": "Barely... hanging... on... just Google it next time, please...",
16
  "mathematical calculation": "*Cough* Grab a calculator... I'm evaporating...",
17
  "creative content generation": "Evaporating... for a poem... what a cruel world...",
 
20
  }
21
 
22
  def get_dialogue(water_level, category):
23
+ # Adjusted thresholds for a 10L maximum limit
24
+ if water_level > 7.0:
25
  state = "energetic"
26
+ elif 3.0 <= water_level <= 7.0:
27
  state = "tired"
28
  else:
29
  state = "raspy"