Spaces:
Sleeping
Sleeping
vighnesh-shetty-vs commited on
Commit ·
a27643c
1
Parent(s): 488b318
Add updated files
Browse files
app.py
CHANGED
|
@@ -95,7 +95,8 @@ def calculate_impact(category, confidence_score, query_text, model_name):
|
|
| 95 |
}
|
| 96 |
|
| 97 |
def get_dialogue(water_level, category):
|
| 98 |
-
|
|
|
|
| 99 |
return DIALOGUES[state].get(category, "I have no words left for this.")
|
| 100 |
|
| 101 |
def generate_audio(text):
|
|
@@ -116,10 +117,11 @@ def get_relatable_translations(impact):
|
|
| 116 |
return w_ex, e_ex, c_ex
|
| 117 |
|
| 118 |
def get_stats_html(water, energy, co2, points):
|
| 119 |
-
|
|
|
|
| 120 |
return f"""
|
| 121 |
<div class="stats-container">
|
| 122 |
-
<div class="stat-card water-card"><div class="stat-label">WATER TANK (
|
| 123 |
<div class="stat-card energy-card"><div class="stat-label">ENERGY WASTED</div><div class="stat-value">{energy:.4f} <span style="font-size: 0.5em;">kWh</span></div></div>
|
| 124 |
<div class="stat-card co2-card"><div class="stat-label">CARBON (CO₂e)</div><div class="stat-value">{co2:.2f}g</div></div>
|
| 125 |
<div class="stat-card points-card"><div class="stat-label">SCORE</div><div class="stat-value">{points}</div></div>
|
|
@@ -127,12 +129,13 @@ def get_stats_html(water, energy, co2, points):
|
|
| 127 |
"""
|
| 128 |
|
| 129 |
def get_drip_visuals(water_level):
|
| 130 |
-
|
|
|
|
| 131 |
g_start, g_end = "#7dd3fc", "#0369a1"
|
| 132 |
mouth_d = "M43 112 Q60 122 77 112"
|
| 133 |
cracks_op, sweat_op, tear_op = "0", "0", "0"
|
| 134 |
mood, mood_color, anim = "Hydrated and coping", "rgb(34, 211, 238)", "bounce 2s infinite ease-in-out"
|
| 135 |
-
elif
|
| 136 |
g_start, g_end = "#38bdf8", "#0284c7"
|
| 137 |
mouth_d = "M43 112 Q60 110 77 112"
|
| 138 |
cracks_op, sweat_op, tear_op = "0", "1", "0"
|
|
@@ -166,7 +169,7 @@ def get_drip_visuals(water_level):
|
|
| 166 |
<path id="tear" d="M38 104 C37 108,33 108,33 112 C33 115,36 117,38 114 C40 117,43 115,43 112 C43 108,39 108,38 104Z" fill="#93c5fd" opacity="{tear_op}" style="transition: opacity 0.5s;"></path>
|
| 167 |
</svg>
|
| 168 |
<div class="drip-mood" id="drip-mood" style="color: {mood_color}; font-weight: 500; font-size: 1.1rem; margin-top: 15px;">{mood}</div>
|
| 169 |
-
<div style="text-align:center; margin-top:10px;"><div style="font-size:10px; color:#94a3b8; text-transform:uppercase; letter-spacing:1px;">Water Left</div><div style="font-size:26px; font-weight:700; color:{mood_color};" id="d-water">{water_level:.
|
| 170 |
</div>
|
| 171 |
"""
|
| 172 |
|
|
@@ -222,6 +225,7 @@ def generate_victory_dashboard(state):
|
|
| 222 |
"""
|
| 223 |
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)])
|
| 224 |
|
|
|
|
| 225 |
return f"""
|
| 226 |
<div class="endgame-wrapper">
|
| 227 |
{confetti_elements}
|
|
@@ -237,7 +241,7 @@ def generate_victory_dashboard(state):
|
|
| 237 |
</div>
|
| 238 |
<div class="v-stat-box" style="border-top: 4px solid #fca5a5;">
|
| 239 |
<h4 style="color: #fca5a5;">Total Wasted</h4>
|
| 240 |
-
<p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">💧 {
|
| 241 |
<p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">⚡ {state.get('energy', 0):.4f} kWh</p>
|
| 242 |
<p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">☁️ {state.get('co2', 0):.2f} g</p>
|
| 243 |
</div>
|
|
@@ -269,6 +273,7 @@ def generate_defeat_dashboard(state):
|
|
| 269 |
"""
|
| 270 |
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)])
|
| 271 |
|
|
|
|
| 272 |
return f"""
|
| 273 |
<div class="endgame-wrapper">
|
| 274 |
{ash_elements}
|
|
@@ -278,7 +283,7 @@ def generate_defeat_dashboard(state):
|
|
| 278 |
<div class="victory-stats-row">
|
| 279 |
<div class="v-stat-box" style="border-top: 4px solid #ef4444; background: rgba(239, 68, 68, 0.1);">
|
| 280 |
<h4 style="color: #ef4444;">Total Resources Wasted</h4>
|
| 281 |
-
<p style="color: #fca5a5; font-size: 1.3em; font-weight: bold; margin: 8px 0;">💧
|
| 282 |
<p style="color: #fca5a5; font-size: 1.3em; font-weight: bold; margin: 8px 0;">⚡ {state.get('energy', 0):.4f} kWh</p>
|
| 283 |
<p style="color: #fca5a5; font-size: 1.3em; font-weight: bold; margin: 8px 0;">☁️ {state.get('co2', 0):.2f} g</p>
|
| 284 |
</div>
|
|
@@ -305,7 +310,6 @@ def generate_defeat_dashboard(state):
|
|
| 305 |
# --- 3. EVENT HANDLERS ---
|
| 306 |
|
| 307 |
def process_query(user_input, selected_model, state):
|
| 308 |
-
# CRITICAL FIX: If game is over, return without changing visibility to avoid hiding endgame screen
|
| 309 |
if state["game_over"] or not user_input.strip():
|
| 310 |
return [state] + [gr.update()]*13
|
| 311 |
|
|
@@ -367,7 +371,6 @@ def process_query(user_input, selected_model, state):
|
|
| 367 |
gr.update(visible=True), gr.update())
|
| 368 |
|
| 369 |
def select_alternative(choice_text, state):
|
| 370 |
-
# CRITICAL FIX: If game is over, return without changing visibility
|
| 371 |
if state["game_over"] or not state.get("current_best_alt"):
|
| 372 |
return [state] + [gr.update()]*5
|
| 373 |
|
|
@@ -456,21 +459,23 @@ h1 { text-align: center; color: #38bdf8; text-shadow: 0 0 15px rgba(56, 189, 248
|
|
| 456 |
"""
|
| 457 |
|
| 458 |
with gr.Blocks(css=custom_css, title="EcoQueryQuest") as demo:
|
|
|
|
| 459 |
game_state = gr.State({
|
| 460 |
-
"water":
|
| 461 |
"history": [], "game_over": False, "current_best_alt": None, "current_shuffled_alts": []
|
| 462 |
})
|
| 463 |
|
| 464 |
gr.Markdown("<h1>🌍 EcoQueryQuest</h1>")
|
| 465 |
gr.Markdown("<div class='subtitle'>Select a model, type a query, and watch Drip react. Reach 500 points to win!</div>")
|
| 466 |
|
| 467 |
-
|
|
|
|
| 468 |
|
| 469 |
-
# Using standard column; when game is over, we set this to visible=False
|
| 470 |
with gr.Column(visible=True) as main_game_ui:
|
| 471 |
with gr.Row():
|
| 472 |
with gr.Column(scale=1, elem_classes=["drip-pod"]):
|
| 473 |
-
|
|
|
|
| 474 |
drip_audio = gr.Audio(label="Drip's Voice", autoplay=True, interactive=False, elem_classes=["hidden-audio"])
|
| 475 |
drip_feedback = gr.HTML("<div class='feedback-box'>Waiting for your first query...</div>")
|
| 476 |
|
|
@@ -489,8 +494,6 @@ with gr.Blocks(css=custom_css, title="EcoQueryQuest") as demo:
|
|
| 489 |
alt_btn_3 = gr.Button("", elem_classes=["alt-card"])
|
| 490 |
alt_feedback = gr.Markdown()
|
| 491 |
|
| 492 |
-
# The Victory/Defeat screen is ALWAYS attached to the DOM but empty.
|
| 493 |
-
# When game is over, this populates directly, avoiding Gradio's nested visibility bugs.
|
| 494 |
endgame_display = gr.HTML("")
|
| 495 |
|
| 496 |
user_input.submit(
|
|
|
|
| 95 |
}
|
| 96 |
|
| 97 |
def get_dialogue(water_level, category):
|
| 98 |
+
# Adjusted dialogue thresholds back to 10L max (7.0 and 3.0)
|
| 99 |
+
state = "energetic" if water_level > 7.0 else ("tired" if water_level >= 3.0 else "raspy")
|
| 100 |
return DIALOGUES[state].get(category, "I have no words left for this.")
|
| 101 |
|
| 102 |
def generate_audio(text):
|
|
|
|
| 117 |
return w_ex, e_ex, c_ex
|
| 118 |
|
| 119 |
def get_stats_html(water, energy, co2, points):
|
| 120 |
+
# Updated progress bar logic for a 10.0L maximum
|
| 121 |
+
water_percent = max(0, min(100, (water / 10.0) * 100))
|
| 122 |
return f"""
|
| 123 |
<div class="stats-container">
|
| 124 |
+
<div class="stat-card water-card"><div class="stat-label">WATER TANK (10L MAX)</div><div class="stat-value">{water:.2f}L</div><div class="progress-bar-bg"><div class="progress-bar-fill" style="width: {water_percent}%;"></div></div></div>
|
| 125 |
<div class="stat-card energy-card"><div class="stat-label">ENERGY WASTED</div><div class="stat-value">{energy:.4f} <span style="font-size: 0.5em;">kWh</span></div></div>
|
| 126 |
<div class="stat-card co2-card"><div class="stat-label">CARBON (CO₂e)</div><div class="stat-value">{co2:.2f}g</div></div>
|
| 127 |
<div class="stat-card points-card"><div class="stat-label">SCORE</div><div class="stat-value">{points}</div></div>
|
|
|
|
| 129 |
"""
|
| 130 |
|
| 131 |
def get_drip_visuals(water_level):
|
| 132 |
+
# Adjusted visual state thresholds back to 10.0L maximum (7.0 and 3.0)
|
| 133 |
+
if water_level > 7.0:
|
| 134 |
g_start, g_end = "#7dd3fc", "#0369a1"
|
| 135 |
mouth_d = "M43 112 Q60 122 77 112"
|
| 136 |
cracks_op, sweat_op, tear_op = "0", "0", "0"
|
| 137 |
mood, mood_color, anim = "Hydrated and coping", "rgb(34, 211, 238)", "bounce 2s infinite ease-in-out"
|
| 138 |
+
elif 3.0 <= water_level <= 7.0:
|
| 139 |
g_start, g_end = "#38bdf8", "#0284c7"
|
| 140 |
mouth_d = "M43 112 Q60 110 77 112"
|
| 141 |
cracks_op, sweat_op, tear_op = "0", "1", "0"
|
|
|
|
| 169 |
<path id="tear" d="M38 104 C37 108,33 108,33 112 C33 115,36 117,38 114 C40 117,43 115,43 112 C43 108,39 108,38 104Z" fill="#93c5fd" opacity="{tear_op}" style="transition: opacity 0.5s;"></path>
|
| 170 |
</svg>
|
| 171 |
<div class="drip-mood" id="drip-mood" style="color: {mood_color}; font-weight: 500; font-size: 1.1rem; margin-top: 15px;">{mood}</div>
|
| 172 |
+
<div style="text-align:center; margin-top:10px;"><div style="font-size:10px; color:#94a3b8; text-transform:uppercase; letter-spacing:1px;">Water Left</div><div style="font-size:26px; font-weight:700; color:{mood_color};" id="d-water">{water_level:.2f}L</div></div>
|
| 173 |
</div>
|
| 174 |
"""
|
| 175 |
|
|
|
|
| 225 |
"""
|
| 226 |
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)])
|
| 227 |
|
| 228 |
+
# Updated "Total Wasted" formula to 10.0 to reflect the 10L tank
|
| 229 |
return f"""
|
| 230 |
<div class="endgame-wrapper">
|
| 231 |
{confetti_elements}
|
|
|
|
| 241 |
</div>
|
| 242 |
<div class="v-stat-box" style="border-top: 4px solid #fca5a5;">
|
| 243 |
<h4 style="color: #fca5a5;">Total Wasted</h4>
|
| 244 |
+
<p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">💧 {10.0 - state.get('water', 10.0):.2f} L</p>
|
| 245 |
<p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">⚡ {state.get('energy', 0):.4f} kWh</p>
|
| 246 |
<p style="color: #fca5a5; font-size: 1.1em; margin: 8px 0;">☁️ {state.get('co2', 0):.2f} g</p>
|
| 247 |
</div>
|
|
|
|
| 273 |
"""
|
| 274 |
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)])
|
| 275 |
|
| 276 |
+
# Updated "Total Wasted" to reflect the empty 10L tank
|
| 277 |
return f"""
|
| 278 |
<div class="endgame-wrapper">
|
| 279 |
{ash_elements}
|
|
|
|
| 283 |
<div class="victory-stats-row">
|
| 284 |
<div class="v-stat-box" style="border-top: 4px solid #ef4444; background: rgba(239, 68, 68, 0.1);">
|
| 285 |
<h4 style="color: #ef4444;">Total Resources Wasted</h4>
|
| 286 |
+
<p style="color: #fca5a5; font-size: 1.3em; font-weight: bold; margin: 8px 0;">💧 10.0 L (Tank Empty)</p>
|
| 287 |
<p style="color: #fca5a5; font-size: 1.3em; font-weight: bold; margin: 8px 0;">⚡ {state.get('energy', 0):.4f} kWh</p>
|
| 288 |
<p style="color: #fca5a5; font-size: 1.3em; font-weight: bold; margin: 8px 0;">☁️ {state.get('co2', 0):.2f} g</p>
|
| 289 |
</div>
|
|
|
|
| 310 |
# --- 3. EVENT HANDLERS ---
|
| 311 |
|
| 312 |
def process_query(user_input, selected_model, state):
|
|
|
|
| 313 |
if state["game_over"] or not user_input.strip():
|
| 314 |
return [state] + [gr.update()]*13
|
| 315 |
|
|
|
|
| 371 |
gr.update(visible=True), gr.update())
|
| 372 |
|
| 373 |
def select_alternative(choice_text, state):
|
|
|
|
| 374 |
if state["game_over"] or not state.get("current_best_alt"):
|
| 375 |
return [state] + [gr.update()]*5
|
| 376 |
|
|
|
|
| 459 |
"""
|
| 460 |
|
| 461 |
with gr.Blocks(css=custom_css, title="EcoQueryQuest") as demo:
|
| 462 |
+
# 1. State initialized with 10.0L
|
| 463 |
game_state = gr.State({
|
| 464 |
+
"water": 10.0, "energy": 0.0, "co2": 0.0, "points": 0, "queries": 0,
|
| 465 |
"history": [], "game_over": False, "current_best_alt": None, "current_shuffled_alts": []
|
| 466 |
})
|
| 467 |
|
| 468 |
gr.Markdown("<h1>🌍 EcoQueryQuest</h1>")
|
| 469 |
gr.Markdown("<div class='subtitle'>Select a model, type a query, and watch Drip react. Reach 500 points to win!</div>")
|
| 470 |
|
| 471 |
+
# 2. Stats initialized with 10.0L
|
| 472 |
+
stats_html = gr.HTML(get_stats_html(10.0, 0.0, 0.0, 0))
|
| 473 |
|
|
|
|
| 474 |
with gr.Column(visible=True) as main_game_ui:
|
| 475 |
with gr.Row():
|
| 476 |
with gr.Column(scale=1, elem_classes=["drip-pod"]):
|
| 477 |
+
# 3. Drip visual initialized with 10.0L
|
| 478 |
+
drip_html = gr.HTML(get_drip_visuals(10.0))
|
| 479 |
drip_audio = gr.Audio(label="Drip's Voice", autoplay=True, interactive=False, elem_classes=["hidden-audio"])
|
| 480 |
drip_feedback = gr.HTML("<div class='feedback-box'>Waiting for your first query...</div>")
|
| 481 |
|
|
|
|
| 494 |
alt_btn_3 = gr.Button("", elem_classes=["alt-card"])
|
| 495 |
alt_feedback = gr.Markdown()
|
| 496 |
|
|
|
|
|
|
|
| 497 |
endgame_display = gr.HTML("")
|
| 498 |
|
| 499 |
user_input.submit(
|