Spaces:
Sleeping
Sleeping
vighnesh-shetty-vs commited on
Commit ·
ab096dd
1
Parent(s): 1715ba7
Add updated files
Browse files
app.py
CHANGED
|
@@ -4,6 +4,10 @@ import random
|
|
| 4 |
from gtts import gTTS
|
| 5 |
import os
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
print("Loading classification model...", flush=True)
|
| 8 |
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
| 9 |
|
|
@@ -55,7 +59,6 @@ DIALOGUES = {
|
|
| 55 |
}
|
| 56 |
}
|
| 57 |
|
| 58 |
-
# UPDATED: Added alternatives for "complex research query" so buttons ALWAYS show!
|
| 59 |
ALTERNATIVES = {
|
| 60 |
"simple factual question": [
|
| 61 |
{"text": "Search Engine (Google)", "url": "https://www.google.com"},
|
|
@@ -85,7 +88,6 @@ def calculate_impact(category, confidence_score, query_text, model_name):
|
|
| 85 |
|
| 86 |
conf_mult = 1.0 if confidence_score > 0.8 else (1.2 if confidence_score > 0.5 else 1.5)
|
| 87 |
word_count = len(query_text.split())
|
| 88 |
-
# Dynamic continuous scaling based on exact word count
|
| 89 |
len_factor = max(0.5, 1.0 + ((word_count - 15) * 0.015))
|
| 90 |
|
| 91 |
water_ml = model_cost["water_ml"] * cat_mult * conf_mult * len_factor
|
|
@@ -303,12 +305,9 @@ def process_query(user_input, selected_model, state):
|
|
| 303 |
state["energy"] += impact["energy_kwh"]
|
| 304 |
state["co2"] += impact["co2_g"]
|
| 305 |
|
| 306 |
-
# If the user selects a complex research query, they get +50 points instantly,
|
| 307 |
-
# but we ALSO show the alternatives now so they can see the savings.
|
| 308 |
if category == "complex research query":
|
| 309 |
state["points"] += 50
|
| 310 |
|
| 311 |
-
# We now fetch alternatives for EVERY category.
|
| 312 |
raw_alts = ALTERNATIVES.get(category, ALTERNATIVES["simple factual question"])
|
| 313 |
best_alt_name = raw_alts[0]["text"]
|
| 314 |
|
|
@@ -317,7 +316,6 @@ def process_query(user_input, selected_model, state):
|
|
| 317 |
state["current_shuffled_alts"] = shuffled_alts
|
| 318 |
state["current_best_alt"] = raw_alts[0]
|
| 319 |
|
| 320 |
-
# Ensure exact 3 buttons are generated and explicitly shown
|
| 321 |
alt_choices = [format_alt_button(a["text"], impact) for a in shuffled_alts]
|
| 322 |
while len(alt_choices) < 3: alt_choices.append("")
|
| 323 |
|
|
@@ -340,7 +338,6 @@ def process_query(user_input, selected_model, state):
|
|
| 340 |
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(value=""),
|
| 341 |
gr.update(visible=False), gr.update(visible=True), gr.update(value=generate_victory_dashboard(state)))
|
| 342 |
|
| 343 |
-
# CRITICAL FIX: Ensure the entire group and individual buttons are explicitly updated to be visible=True
|
| 344 |
return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(value=feedback_text), gr.update(visible=True),
|
| 345 |
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=""),
|
| 346 |
gr.update(visible=True), gr.update(visible=False), gr.update())
|
|
@@ -411,6 +408,8 @@ h1 { text-align: center; color: #38bdf8; text-shadow: 0 0 15px rgba(56, 189, 248
|
|
| 411 |
.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);}
|
| 412 |
.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;}
|
| 413 |
.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;}
|
|
|
|
|
|
|
| 414 |
.custom-dropdown { background: rgba(30, 41, 59, 0.8) !important; border: 1px solid #38bdf8 !important; border-radius: 12px !important; }
|
| 415 |
|
| 416 |
/* Victory Dashboard & Celebration */
|
|
@@ -431,7 +430,7 @@ h1 { text-align: center; color: #38bdf8; text-shadow: 0 0 15px rgba(56, 189, 248
|
|
| 431 |
|
| 432 |
with gr.Blocks(css=custom_css, title="EcoQueryQuest") as demo:
|
| 433 |
game_state = gr.State({
|
| 434 |
-
"water":
|
| 435 |
"history": [], "game_over": False, "current_best_alt": None, "current_shuffled_alts": []
|
| 436 |
})
|
| 437 |
|
|
@@ -444,17 +443,19 @@ with gr.Blocks(css=custom_css, title="EcoQueryQuest") as demo:
|
|
| 444 |
with gr.Row():
|
| 445 |
with gr.Column(scale=1, elem_classes=["drip-pod"]):
|
| 446 |
drip_html = gr.HTML(get_drip_visuals(10.0))
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
| 452 |
with gr.Row(elem_classes=["input-row"]):
|
| 453 |
user_input = gr.Textbox(show_label=False, placeholder="Type your query here...", elem_classes=["custom-textbox"], scale=4, lines=3)
|
| 454 |
submit_btn = gr.Button("Send Query", elem_classes=["custom-btn"], scale=1)
|
| 455 |
impact_display = gr.HTML()
|
| 456 |
|
| 457 |
-
# The Group is hidden initially, but explicitly forced open upon query
|
| 458 |
with gr.Group(visible=False, elem_classes=["alt-group"]) as alternatives_group:
|
| 459 |
gr.Markdown("<h3 style='text-align:center; color:#34d399; margin-bottom: 20px;'>🌱 Drip says: 'Quick! Pick a greener tool to earn points!'</h3>")
|
| 460 |
with gr.Row():
|
|
|
|
| 4 |
from gtts import gTTS
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
from game_data import calculate_impact, MODELS
|
| 8 |
+
from dialogues import get_dialogue
|
| 9 |
+
from alternatives import ALTERNATIVES
|
| 10 |
+
|
| 11 |
print("Loading classification model...", flush=True)
|
| 12 |
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
| 13 |
|
|
|
|
| 59 |
}
|
| 60 |
}
|
| 61 |
|
|
|
|
| 62 |
ALTERNATIVES = {
|
| 63 |
"simple factual question": [
|
| 64 |
{"text": "Search Engine (Google)", "url": "https://www.google.com"},
|
|
|
|
| 88 |
|
| 89 |
conf_mult = 1.0 if confidence_score > 0.8 else (1.2 if confidence_score > 0.5 else 1.5)
|
| 90 |
word_count = len(query_text.split())
|
|
|
|
| 91 |
len_factor = max(0.5, 1.0 + ((word_count - 15) * 0.015))
|
| 92 |
|
| 93 |
water_ml = model_cost["water_ml"] * cat_mult * conf_mult * len_factor
|
|
|
|
| 305 |
state["energy"] += impact["energy_kwh"]
|
| 306 |
state["co2"] += impact["co2_g"]
|
| 307 |
|
|
|
|
|
|
|
| 308 |
if category == "complex research query":
|
| 309 |
state["points"] += 50
|
| 310 |
|
|
|
|
| 311 |
raw_alts = ALTERNATIVES.get(category, ALTERNATIVES["simple factual question"])
|
| 312 |
best_alt_name = raw_alts[0]["text"]
|
| 313 |
|
|
|
|
| 316 |
state["current_shuffled_alts"] = shuffled_alts
|
| 317 |
state["current_best_alt"] = raw_alts[0]
|
| 318 |
|
|
|
|
| 319 |
alt_choices = [format_alt_button(a["text"], impact) for a in shuffled_alts]
|
| 320 |
while len(alt_choices) < 3: alt_choices.append("")
|
| 321 |
|
|
|
|
| 338 |
gr.update(), gr.update(), gr.update(), gr.update(), gr.update(value=""),
|
| 339 |
gr.update(visible=False), gr.update(visible=True), gr.update(value=generate_victory_dashboard(state)))
|
| 340 |
|
|
|
|
| 341 |
return (state, stats_ui, drip_ui, audio_path, impact_ui, gr.update(value=feedback_text), gr.update(visible=True),
|
| 342 |
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=""),
|
| 343 |
gr.update(visible=True), gr.update(visible=False), gr.update())
|
|
|
|
| 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 */
|
|
|
|
| 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": []
|
| 435 |
})
|
| 436 |
|
|
|
|
| 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)
|
| 457 |
impact_display = gr.HTML()
|
| 458 |
|
|
|
|
| 459 |
with gr.Group(visible=False, elem_classes=["alt-group"]) as alternatives_group:
|
| 460 |
gr.Markdown("<h3 style='text-align:center; color:#34d399; margin-bottom: 20px;'>🌱 Drip says: 'Quick! Pick a greener tool to earn points!'</h3>")
|
| 461 |
with gr.Row():
|