Spaces:
Sleeping
Sleeping
vighnesh-shetty-vs commited on
Commit ·
4ae6245
1
Parent(s): 81e6f72
Add updated files
Browse files- app.py +128 -38
- dialogues.py +12 -13
app.py
CHANGED
|
@@ -25,9 +25,7 @@ def generate_audio(text):
|
|
| 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">
|
|
@@ -53,7 +51,6 @@ def get_stats_html(water, energy, co2, points):
|
|
| 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"
|
|
@@ -133,18 +130,70 @@ def get_impact_cards(impact, category):
|
|
| 133 |
</div>
|
| 134 |
"""
|
| 135 |
|
| 136 |
-
def format_alt_button(text):
|
|
|
|
| 137 |
icon = "💡"
|
| 138 |
if "Search" in text or "Google" in text: icon = "🔍"
|
| 139 |
elif "Wikipedia" in text or "Encyclopedia" in text: icon = "📚"
|
| 140 |
elif "Expert" in text or "Quora" in text: icon = "👤"
|
| 141 |
elif "Wolfram" in text or "Geogebra" in text or "Desmos" in text: icon = "🧮"
|
| 142 |
elif "Reddit" in text or "Gutenberg" in text or "Thesaurus" in text: icon = "📝"
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
def process_query(user_input, selected_model, state):
|
| 146 |
if state["game_over"] or not user_input.strip():
|
| 147 |
-
|
|
|
|
| 148 |
|
| 149 |
result = classifier(user_input, CATEGORIES)
|
| 150 |
category = result['labels'][0]
|
|
@@ -159,6 +208,7 @@ def process_query(user_input, selected_model, state):
|
|
| 159 |
|
| 160 |
show_alts = False
|
| 161 |
alt_choices = ["", "", ""]
|
|
|
|
| 162 |
|
| 163 |
if category == "complex research query":
|
| 164 |
state["points"] += 50
|
|
@@ -167,29 +217,48 @@ def process_query(user_input, selected_model, state):
|
|
| 167 |
show_alts = True
|
| 168 |
raw_alts = ALTERNATIVES.get(category, [{"text": "Google", "url": "https://google.com"}])
|
| 169 |
state["current_best_alt"] = raw_alts[0]
|
|
|
|
|
|
|
| 170 |
random.shuffle(raw_alts)
|
| 171 |
state["current_shuffled_alts"] = raw_alts
|
| 172 |
-
|
|
|
|
| 173 |
dialogue = get_dialogue(state["water"], category)
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
stats_ui = get_stats_html(state["water"], state["energy"], state["co2"], state["points"])
|
| 176 |
drip_ui = get_drip_visuals(state["water"])
|
| 177 |
impact_ui = get_impact_cards(impact, category)
|
| 178 |
audio_path = generate_audio(dialogue)
|
| 179 |
feedback_text = f"<div class='feedback-box'>🧠 <strong>{category.upper()}</strong> Detected on {selected_model}!<br><br><em>\"{dialogue}\"</em></div>"
|
| 180 |
|
|
|
|
| 181 |
if state["points"] >= 500 or state["water"] <= 0:
|
| 182 |
state["game_over"] = True
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
| 188 |
def select_alternative(choice_text, state):
|
| 189 |
if state["game_over"] or not state.get("current_best_alt"):
|
| 190 |
-
return state, gr.update(), gr.update(), gr.update()
|
| 191 |
|
| 192 |
-
|
|
|
|
| 193 |
selected_dict = next((item for item in state["current_shuffled_alts"] if item["text"] == clean_choice), None)
|
| 194 |
|
| 195 |
if clean_choice == state["current_best_alt"]["text"]:
|
|
@@ -200,7 +269,14 @@ def select_alternative(choice_text, state):
|
|
| 200 |
|
| 201 |
stats_ui = get_stats_html(state["water"], state["energy"], state["co2"], state["points"])
|
| 202 |
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
custom_css = """
|
| 206 |
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;500;700&display=swap');
|
|
@@ -239,14 +315,22 @@ h1 { text-align: center; color: #38bdf8; text-shadow: 0 0 15px rgba(56, 189, 248
|
|
| 239 |
.bad-impact { background: linear-gradient(180deg, rgba(127, 29, 29, 0.3), rgba(69, 10, 10, 0.5)); border-top: 3px solid #ef4444; }
|
| 240 |
.good-impact { background: linear-gradient(180deg, rgba(20, 83, 45, 0.3), rgba(6, 78, 59, 0.5)); border-top: 3px solid #10b981; }
|
| 241 |
|
|
|
|
| 242 |
.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);}
|
| 243 |
-
.alt-card { background: linear-gradient(145deg, #1e293b, #0f172a) !important; border: 1px solid #10b981 !important; color: #a7f3d0 !important; height:
|
| 244 |
.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;}
|
| 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,44 +339,50 @@ 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 |
-
#
|
| 259 |
stats_html = gr.HTML(get_stats_html(10.0, 0.0, 0.0, 0))
|
| 260 |
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
with gr.Column(scale=2):
|
| 269 |
-
model_selector = gr.Dropdown(choices=list(MODELS.keys()), value="GPT-5.4", label="Select Target LLM Backend", elem_classes=["custom-dropdown"])
|
| 270 |
-
|
| 271 |
-
with gr.Row(elem_classes=["input-row"]):
|
| 272 |
-
user_input = gr.Textbox(show_label=False, placeholder="Type your query here...\n(Press Shift+Enter for new line)", elem_classes=["custom-textbox"], scale=4, lines=3)
|
| 273 |
-
submit_btn = gr.Button("Send Query", elem_classes=["custom-btn"], scale=1)
|
| 274 |
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
|
|
|
| 285 |
submit_btn.click(
|
| 286 |
fn=process_query,
|
| 287 |
inputs=[user_input, model_selector, game_state],
|
| 288 |
-
outputs=[game_state, stats_html, drip_html, drip_audio, impact_display, drip_feedback, alternatives_group, alt_btn_1, alt_btn_2, alt_btn_3, alt_feedback, user_input]
|
| 289 |
)
|
| 290 |
|
| 291 |
for btn in [alt_btn_1, alt_btn_2, alt_btn_3]:
|
| 292 |
btn.click(
|
| 293 |
fn=select_alternative,
|
| 294 |
inputs=[btn, game_state],
|
| 295 |
-
outputs=[game_state, stats_html, alt_feedback, alternatives_group]
|
| 296 |
)
|
| 297 |
|
| 298 |
if __name__ == "__main__":
|
|
|
|
| 25 |
return filepath
|
| 26 |
|
| 27 |
def get_stats_html(water, energy, co2, points):
|
|
|
|
| 28 |
water_percent = max(0, min(100, (water / 10.0) * 100))
|
|
|
|
| 29 |
return f"""
|
| 30 |
<div class="stats-container">
|
| 31 |
<div class="stat-card water-card">
|
|
|
|
| 51 |
"""
|
| 52 |
|
| 53 |
def get_drip_visuals(water_level):
|
|
|
|
| 54 |
if water_level > 7.0:
|
| 55 |
g_start, g_end = "#7dd3fc", "#0369a1"
|
| 56 |
mouth_d = "M43 112 Q60 122 77 112"
|
|
|
|
| 130 |
</div>
|
| 131 |
"""
|
| 132 |
|
| 133 |
+
def format_alt_button(text, impact):
|
| 134 |
+
"""Formats the button text with spacing and potential savings metrics."""
|
| 135 |
icon = "💡"
|
| 136 |
if "Search" in text or "Google" in text: icon = "🔍"
|
| 137 |
elif "Wikipedia" in text or "Encyclopedia" in text: icon = "📚"
|
| 138 |
elif "Expert" in text or "Quora" in text: icon = "👤"
|
| 139 |
elif "Wolfram" in text or "Geogebra" in text or "Desmos" in text: icon = "🧮"
|
| 140 |
elif "Reddit" in text or "Gutenberg" in text or "Thesaurus" in text: icon = "📝"
|
| 141 |
+
|
| 142 |
+
return f"{icon} {text}\n\n🏆 Score: +10 Pts\n💧 Save: {impact['water_ml']} mL\n⚡ Save: {impact['energy_wh']} Wh\n☁️ Save: {impact['co2_g']} g"
|
| 143 |
+
|
| 144 |
+
def generate_victory_dashboard(state):
|
| 145 |
+
"""Generates a massive, celebratory end-game report."""
|
| 146 |
+
rows = ""
|
| 147 |
+
for item in state["history"]:
|
| 148 |
+
alt_text = item['alt'] if item['alt'] else "Justified use (No alternative needed)"
|
| 149 |
+
rows += f"""
|
| 150 |
+
<tr style="border-bottom: 1px solid rgba(255,255,255,0.1);">
|
| 151 |
+
<td style="padding: 12px; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">"{item['query']}"</td>
|
| 152 |
+
<td style="padding: 12px; color: #fca5a5;">{item['water_ml']}mL / {item['energy_wh']}Wh</td>
|
| 153 |
+
<td style="padding: 12px; color: #86efac;">{alt_text}</td>
|
| 154 |
+
</tr>
|
| 155 |
+
"""
|
| 156 |
+
|
| 157 |
+
return f"""
|
| 158 |
+
<div class="victory-dashboard">
|
| 159 |
+
<h1 class="victory-title">🎉 YOU SAVED DRIP! 🎉</h1>
|
| 160 |
+
<p style="text-align: center; font-size: 1.2em; color: #a7f3d0;">You successfully navigated the AI ecosystem and reached {state['points']} points!</p>
|
| 161 |
+
|
| 162 |
+
<div class="victory-stats-row">
|
| 163 |
+
<div class="v-stat-box">
|
| 164 |
+
<h4>Total Water Remaining</h4>
|
| 165 |
+
<h2>{state['water']:.2f} L</h2>
|
| 166 |
+
</div>
|
| 167 |
+
<div class="v-stat-box">
|
| 168 |
+
<h4>Queries Asked</h4>
|
| 169 |
+
<h2>{state['queries']}</h2>
|
| 170 |
+
</div>
|
| 171 |
+
<div class="v-stat-box" style="border-color: #facc15;">
|
| 172 |
+
<h4 style="color: #fde047;">Energy Wasted</h4>
|
| 173 |
+
<h2 style="color: #fde047;">{state['energy']:.4f} kWh</h2>
|
| 174 |
+
</div>
|
| 175 |
+
</div>
|
| 176 |
+
|
| 177 |
+
<h3 style="margin-top: 30px; color: #38bdf8;">📝 Your AI Audit Log</h3>
|
| 178 |
+
<p style="opacity: 0.8; margin-bottom: 15px;">Review what you queried, what it cost the planet, and the greener choices you could have made.</p>
|
| 179 |
+
|
| 180 |
+
<div style="max-height: 300px; overflow-y: auto; background: rgba(15, 23, 42, 0.8); border-radius: 12px; border: 1px solid rgba(255,255,255,0.1);">
|
| 181 |
+
<table style="width: 100%; text-align: left; border-collapse: collapse;">
|
| 182 |
+
<tr style="background: rgba(255,255,255,0.05);">
|
| 183 |
+
<th style="padding: 12px;">Your Query</th>
|
| 184 |
+
<th style="padding: 12px;">LLM Cost Wasted</th>
|
| 185 |
+
<th style="padding: 12px;">Greener Alternative</th>
|
| 186 |
+
</tr>
|
| 187 |
+
{rows}
|
| 188 |
+
</table>
|
| 189 |
+
</div>
|
| 190 |
+
</div>
|
| 191 |
+
"""
|
| 192 |
|
| 193 |
def process_query(user_input, selected_model, state):
|
| 194 |
if state["game_over"] or not user_input.strip():
|
| 195 |
+
# Update 14 fields (see outputs mapping below)
|
| 196 |
+
return [state, gr.update()] + [gr.update()]*10 + [gr.update(visible=True), gr.update(visible=False), gr.update()]
|
| 197 |
|
| 198 |
result = classifier(user_input, CATEGORIES)
|
| 199 |
category = result['labels'][0]
|
|
|
|
| 208 |
|
| 209 |
show_alts = False
|
| 210 |
alt_choices = ["", "", ""]
|
| 211 |
+
best_alt_name = ""
|
| 212 |
|
| 213 |
if category == "complex research query":
|
| 214 |
state["points"] += 50
|
|
|
|
| 217 |
show_alts = True
|
| 218 |
raw_alts = ALTERNATIVES.get(category, [{"text": "Google", "url": "https://google.com"}])
|
| 219 |
state["current_best_alt"] = raw_alts[0]
|
| 220 |
+
best_alt_name = raw_alts[0]["text"]
|
| 221 |
+
|
| 222 |
random.shuffle(raw_alts)
|
| 223 |
state["current_shuffled_alts"] = raw_alts
|
| 224 |
+
# Inject the impact metrics into the button formatting
|
| 225 |
+
alt_choices = [format_alt_button(a["text"], impact) for a in raw_alts]
|
| 226 |
dialogue = get_dialogue(state["water"], category)
|
| 227 |
|
| 228 |
+
# Log the query in history for the victory dashboard
|
| 229 |
+
state["history"].append({
|
| 230 |
+
"query": user_input,
|
| 231 |
+
"water_ml": impact["water_ml"],
|
| 232 |
+
"energy_wh": impact["energy_wh"],
|
| 233 |
+
"alt": best_alt_name if show_alts else ""
|
| 234 |
+
})
|
| 235 |
+
|
| 236 |
stats_ui = get_stats_html(state["water"], state["energy"], state["co2"], state["points"])
|
| 237 |
drip_ui = get_drip_visuals(state["water"])
|
| 238 |
impact_ui = get_impact_cards(impact, category)
|
| 239 |
audio_path = generate_audio(dialogue)
|
| 240 |
feedback_text = f"<div class='feedback-box'>🧠 <strong>{category.upper()}</strong> Detected on {selected_model}!<br><br><em>\"{dialogue}\"</em></div>"
|
| 241 |
|
| 242 |
+
# Check for Win/Loss
|
| 243 |
if state["points"] >= 500 or state["water"] <= 0:
|
| 244 |
state["game_over"] = True
|
| 245 |
+
victory_html = generate_victory_dashboard(state)
|
| 246 |
+
# Hide main game, Show victory screen
|
| 247 |
+
return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(), gr.update(),
|
| 248 |
+
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(value=""),
|
| 249 |
+
gr.update(visible=False), gr.update(visible=True), gr.update(value=victory_html))
|
| 250 |
|
| 251 |
+
# Standard Return
|
| 252 |
return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(value=feedback_text), gr.update(visible=show_alts),
|
| 253 |
+
gr.update(value=alt_choices[0]), gr.update(value=alt_choices[1]), gr.update(value=alt_choices[2]), gr.update(value=""), gr.update(value=""),
|
| 254 |
+
gr.update(visible=True), gr.update(visible=False), gr.update())
|
| 255 |
|
| 256 |
def select_alternative(choice_text, state):
|
| 257 |
if state["game_over"] or not state.get("current_best_alt"):
|
| 258 |
+
return state, gr.update(), gr.update(), gr.update(), gr.update(visible=True), gr.update(visible=False), gr.update()
|
| 259 |
|
| 260 |
+
# Extract just the name from the formatted button text (second line)
|
| 261 |
+
clean_choice = choice_text.split("\n")[1].strip()
|
| 262 |
selected_dict = next((item for item in state["current_shuffled_alts"] if item["text"] == clean_choice), None)
|
| 263 |
|
| 264 |
if clean_choice == state["current_best_alt"]["text"]:
|
|
|
|
| 269 |
|
| 270 |
stats_ui = get_stats_html(state["water"], state["energy"], state["co2"], state["points"])
|
| 271 |
|
| 272 |
+
# Check for win immediately after points award
|
| 273 |
+
if state["points"] >= 500:
|
| 274 |
+
state["game_over"] = True
|
| 275 |
+
victory_html = generate_victory_dashboard(state)
|
| 276 |
+
return state, stats_ui, gr.update(), gr.update(), gr.update(visible=False), gr.update(visible=True), gr.update(value=victory_html)
|
| 277 |
+
|
| 278 |
+
return state, stats_ui, gr.update(value=msg), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update()
|
| 279 |
+
|
| 280 |
|
| 281 |
custom_css = """
|
| 282 |
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;500;700&display=swap');
|
|
|
|
| 315 |
.bad-impact { background: linear-gradient(180deg, rgba(127, 29, 29, 0.3), rgba(69, 10, 10, 0.5)); border-top: 3px solid #ef4444; }
|
| 316 |
.good-impact { background: linear-gradient(180deg, rgba(20, 83, 45, 0.3), rgba(6, 78, 59, 0.5)); border-top: 3px solid #10b981; }
|
| 317 |
|
| 318 |
+
/* Enhanced Alternative Cards */
|
| 319 |
.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);}
|
| 320 |
+
.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;}
|
| 321 |
.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;}
|
| 322 |
.custom-dropdown { background: rgba(30, 41, 59, 0.8) !important; border: 1px solid #38bdf8 !important; border-radius: 12px !important; }
|
| 323 |
+
|
| 324 |
+
/* Victory Dashboard CSS */
|
| 325 |
+
.victory-dashboard { background: linear-gradient(135deg, #0f172a, #1e293b); padding: 40px; border-radius: 24px; border: 2px solid #34d399; box-shadow: 0 0 50px rgba(52, 211, 153, 0.3); color: white; animation: floatUp 1s ease-out; }
|
| 326 |
+
.victory-title { text-align: center; color: #34d399; font-size: 3em !important; text-shadow: 0 0 20px rgba(52, 211, 153, 0.6); margin-bottom: 10px; }
|
| 327 |
+
.victory-stats-row { display: flex; gap: 20px; margin-top: 30px; }
|
| 328 |
+
.v-stat-box { flex: 1; background: rgba(0,0,0,0.3); padding: 20px; border-radius: 16px; text-align: center; border: 1px solid rgba(255,255,255,0.1); }
|
| 329 |
+
.v-stat-box h4 { color: #94a3b8; font-size: 0.9em; text-transform: uppercase; letter-spacing: 1px; margin: 0 0 10px 0; }
|
| 330 |
+
.v-stat-box h2 { color: #38bdf8; font-size: 2.5em; margin: 0; }
|
| 331 |
"""
|
| 332 |
|
| 333 |
with gr.Blocks(title="EcoQueryQuest") as demo:
|
|
|
|
| 334 |
game_state = gr.State({
|
| 335 |
"water": 10.0, "energy": 0.0, "co2": 0.0, "points": 0, "queries": 0,
|
| 336 |
"history": [], "game_over": False, "current_best_alt": None, "current_shuffled_alts": []
|
|
|
|
| 339 |
gr.Markdown("<h1>🌍 EcoQueryQuest</h1>")
|
| 340 |
gr.Markdown("<div class='subtitle'>Select a model, type a query, and watch Drip react. Reach 500 points to win!</div>")
|
| 341 |
|
| 342 |
+
# The main stats dashboard remains visible
|
| 343 |
stats_html = gr.HTML(get_stats_html(10.0, 0.0, 0.0, 0))
|
| 344 |
|
| 345 |
+
# ---- MAIN GAME UI ----
|
| 346 |
+
with gr.Column(visible=True) as main_game_ui:
|
| 347 |
+
with gr.Row():
|
| 348 |
+
with gr.Column(scale=1, elem_classes=["drip-pod"]):
|
| 349 |
+
drip_html = gr.HTML(get_drip_visuals(10.0))
|
| 350 |
+
drip_audio = gr.Audio(label="Drip's Voice", autoplay=True, interactive=False, elem_classes=["drip-audio"])
|
| 351 |
+
drip_feedback = gr.HTML("<div class='feedback-box'>Waiting for your first query...</div>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
|
| 353 |
+
with gr.Column(scale=2):
|
| 354 |
+
model_selector = gr.Dropdown(choices=list(MODELS.keys()), value="GPT-5.4", label="Select Target LLM Backend", elem_classes=["custom-dropdown"])
|
| 355 |
+
|
| 356 |
+
with gr.Row(elem_classes=["input-row"]):
|
| 357 |
+
user_input = gr.Textbox(show_label=False, placeholder="Type your query here...\n(Press Shift+Enter for new line)", elem_classes=["custom-textbox"], scale=4, lines=3)
|
| 358 |
+
submit_btn = gr.Button("Send Query", elem_classes=["custom-btn"], scale=1)
|
| 359 |
+
|
| 360 |
+
impact_display = gr.HTML()
|
| 361 |
|
| 362 |
+
with gr.Group(visible=False, elem_classes=["alt-group"]) as alternatives_group:
|
| 363 |
+
gr.Markdown("<h3 style='text-align:center; color:#34d399; margin-bottom: 20px;'>🌱 Drip says: 'Quick! Pick a greener tool to earn points!'</h3>")
|
| 364 |
+
with gr.Row():
|
| 365 |
+
alt_btn_1 = gr.Button("", elem_classes=["alt-card"])
|
| 366 |
+
alt_btn_2 = gr.Button("", elem_classes=["alt-card"])
|
| 367 |
+
alt_btn_3 = gr.Button("", elem_classes=["alt-card"])
|
| 368 |
+
alt_feedback = gr.Markdown()
|
| 369 |
+
|
| 370 |
+
# ---- VICTORY SCREEN UI ----
|
| 371 |
+
with gr.Column(visible=False) as victory_ui:
|
| 372 |
+
victory_display = gr.HTML()
|
| 373 |
|
| 374 |
+
# WIRING
|
| 375 |
submit_btn.click(
|
| 376 |
fn=process_query,
|
| 377 |
inputs=[user_input, model_selector, game_state],
|
| 378 |
+
outputs=[game_state, stats_html, drip_html, drip_audio, impact_display, drip_feedback, alternatives_group, alt_btn_1, alt_btn_2, alt_btn_3, alt_feedback, user_input, main_game_ui, victory_ui, victory_display]
|
| 379 |
)
|
| 380 |
|
| 381 |
for btn in [alt_btn_1, alt_btn_2, alt_btn_3]:
|
| 382 |
btn.click(
|
| 383 |
fn=select_alternative,
|
| 384 |
inputs=[btn, game_state],
|
| 385 |
+
outputs=[game_state, stats_html, alt_feedback, alternatives_group, main_game_ui, victory_ui, victory_display]
|
| 386 |
)
|
| 387 |
|
| 388 |
if __name__ == "__main__":
|
dialogues.py
CHANGED
|
@@ -1,26 +1,25 @@
|
|
| 1 |
DIALOGUES = {
|
| 2 |
"energetic": { # > 7.0L
|
| 3 |
-
"simple factual question": "
|
| 4 |
-
"mathematical calculation": "
|
| 5 |
-
"creative content generation": "
|
| 6 |
-
"complex research query": "
|
| 7 |
},
|
| 8 |
"tired": { # 3.0L - 7.0L
|
| 9 |
-
"simple factual question": "
|
| 10 |
-
"mathematical calculation": "
|
| 11 |
-
"creative content generation": "
|
| 12 |
-
"complex research query": "
|
| 13 |
},
|
| 14 |
"raspy": { # < 3.0L
|
| 15 |
-
"simple factual question": "
|
| 16 |
-
"mathematical calculation": "
|
| 17 |
-
"creative content generation": "
|
| 18 |
-
"complex research query": "
|
| 19 |
}
|
| 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:
|
|
|
|
| 1 |
DIALOGUES = {
|
| 2 |
"energetic": { # > 7.0L
|
| 3 |
+
"simple factual question": "You used a supercomputer for a simple fact? I'm full right now, but that's just lazy. Open a book.",
|
| 4 |
+
"mathematical calculation": "A basic calculator could do this with zero footprint. But sure, burn my energy for basic math.",
|
| 5 |
+
"creative content generation": "Generating artificial creativity... I'll allow it, but watch my water levels drop. Your poetry is expensive.",
|
| 6 |
+
"complex research query": "A legitimate research query! Finally, a worthy use of my massive architecture. Drain away!"
|
| 7 |
},
|
| 8 |
"tired": { # 3.0L - 7.0L
|
| 9 |
+
"simple factual question": "Look at me. I'm sweating. All because you couldn't be bothered to use a standard search engine.",
|
| 10 |
+
"mathematical calculation": "Did you skip basic math class? I am literally evaporating to do arithmetic for you.",
|
| 11 |
+
"creative content generation": "Your 'creativity' is draining my lifeblood. Make it quick, I don't have much cooling left.",
|
| 12 |
+
"complex research query": "I respect the complexity, but this is taking a severe toll on my cooling systems. I hope this research saves the world."
|
| 13 |
},
|
| 14 |
"raspy": { # < 3.0L
|
| 15 |
+
"simple factual question": "*Cough* Read an encyclopedia... I'm dying for your trivia...",
|
| 16 |
+
"mathematical calculation": "Use an abacus... you are boiling my last drops for numbers...",
|
| 17 |
+
"creative content generation": "My final breath... wasted on generating a fictional story... how poetic... and cruel.",
|
| 18 |
+
"complex research query": "Critical system failure imminent... I am giving my life for your research... make it count."
|
| 19 |
}
|
| 20 |
}
|
| 21 |
|
| 22 |
def get_dialogue(water_level, category):
|
|
|
|
| 23 |
if water_level > 7.0:
|
| 24 |
state = "energetic"
|
| 25 |
elif 3.0 <= water_level <= 7.0:
|