Spaces:
Sleeping
Sleeping
Mohammed Thameem commited on
Commit ·
49e9e54
1
Parent(s): 40ad0e6
modified test script
Browse files
app.py
CHANGED
|
@@ -18,7 +18,9 @@ EMISSIONS_FACTORS = {
|
|
| 18 |
}
|
| 19 |
}
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
transport_emissions = (
|
| 23 |
car_km * EMISSIONS_FACTORS["transportation"]["car"] +
|
| 24 |
bus_km * EMISSIONS_FACTORS["transportation"]["bus"] +
|
|
@@ -42,6 +44,7 @@ def calculate_footprint(car_km, bus_km, train_km, air_km, meat_meals, vegetarian
|
|
| 42 |
|
| 43 |
return total_emissions, stats
|
| 44 |
|
|
|
|
| 45 |
def respond(
|
| 46 |
message,
|
| 47 |
history: list[dict[str, str]],
|
|
@@ -64,7 +67,7 @@ def respond(
|
|
| 64 |
custom_prompt = f"""
|
| 65 |
This user’s estimated weekly footprint is **{footprint:.1f} kg CO2**.
|
| 66 |
That’s equivalent to planting about {stats['trees']} trees 🌳 or taking {stats['flights']} short flights ✈️.
|
| 67 |
-
Their breakdown includes both transportation and food habits.
|
| 68 |
Your job is to guide them with practical, encouraging suggestions to lower this footprint.
|
| 69 |
{system_message}
|
| 70 |
"""
|
|
@@ -92,11 +95,13 @@ Your job is to guide them with practical, encouraging suggestions to lower this
|
|
| 92 |
response += token
|
| 93 |
yield response
|
| 94 |
|
|
|
|
| 95 |
system_prompt = """
|
| 96 |
You are Sustainable.ai, a friendly, encouraging, and knowledgeable AI assistant...
|
| 97 |
(omit full content for brevity – use your full prompt here)
|
| 98 |
"""
|
| 99 |
|
|
|
|
| 100 |
with gr.Blocks(css="""
|
| 101 |
body {
|
| 102 |
background: linear-gradient(135deg, #e0f7fa, #f1f8e9);
|
|
@@ -135,7 +140,6 @@ with gr.Blocks(css="""
|
|
| 135 |
train_input = gr.Number(label="🚆 Train Travel (km)", value=0)
|
| 136 |
air_input = gr.Number(label="✈️ Air Travel (km/month)", value=0)
|
| 137 |
|
| 138 |
-
|
| 139 |
with gr.Group(elem_classes="section-card"):
|
| 140 |
gr.Markdown("### 🍽️ Food Habits (per week)")
|
| 141 |
with gr.Row():
|
|
@@ -143,7 +147,6 @@ with gr.Blocks(css="""
|
|
| 143 |
vegetarian_input = gr.Number(label="🥗 Vegetarian Meals", value=0)
|
| 144 |
vegan_input = gr.Number(label="🌱 Vegan Meals", value=0)
|
| 145 |
|
| 146 |
-
|
| 147 |
chatbot = gr.ChatInterface(
|
| 148 |
respond,
|
| 149 |
type="messages",
|
|
|
|
| 18 |
}
|
| 19 |
}
|
| 20 |
|
| 21 |
+
|
| 22 |
+
def calculate_footprint(car_km, bus_km, train_km, air_km,
|
| 23 |
+
meat_meals, vegetarian_meals, vegan_meals):
|
| 24 |
transport_emissions = (
|
| 25 |
car_km * EMISSIONS_FACTORS["transportation"]["car"] +
|
| 26 |
bus_km * EMISSIONS_FACTORS["transportation"]["bus"] +
|
|
|
|
| 44 |
|
| 45 |
return total_emissions, stats
|
| 46 |
|
| 47 |
+
|
| 48 |
def respond(
|
| 49 |
message,
|
| 50 |
history: list[dict[str, str]],
|
|
|
|
| 67 |
custom_prompt = f"""
|
| 68 |
This user’s estimated weekly footprint is **{footprint:.1f} kg CO2**.
|
| 69 |
That’s equivalent to planting about {stats['trees']} trees 🌳 or taking {stats['flights']} short flights ✈️.
|
| 70 |
+
Their breakdown includes both transportation and food habits.
|
| 71 |
Your job is to guide them with practical, encouraging suggestions to lower this footprint.
|
| 72 |
{system_message}
|
| 73 |
"""
|
|
|
|
| 95 |
response += token
|
| 96 |
yield response
|
| 97 |
|
| 98 |
+
|
| 99 |
system_prompt = """
|
| 100 |
You are Sustainable.ai, a friendly, encouraging, and knowledgeable AI assistant...
|
| 101 |
(omit full content for brevity – use your full prompt here)
|
| 102 |
"""
|
| 103 |
|
| 104 |
+
|
| 105 |
with gr.Blocks(css="""
|
| 106 |
body {
|
| 107 |
background: linear-gradient(135deg, #e0f7fa, #f1f8e9);
|
|
|
|
| 140 |
train_input = gr.Number(label="🚆 Train Travel (km)", value=0)
|
| 141 |
air_input = gr.Number(label="✈️ Air Travel (km/month)", value=0)
|
| 142 |
|
|
|
|
| 143 |
with gr.Group(elem_classes="section-card"):
|
| 144 |
gr.Markdown("### 🍽️ Food Habits (per week)")
|
| 145 |
with gr.Row():
|
|
|
|
| 147 |
vegetarian_input = gr.Number(label="🥗 Vegetarian Meals", value=0)
|
| 148 |
vegan_input = gr.Number(label="🌱 Vegan Meals", value=0)
|
| 149 |
|
|
|
|
| 150 |
chatbot = gr.ChatInterface(
|
| 151 |
respond,
|
| 152 |
type="messages",
|