Spaces:
Sleeping
Sleeping
File size: 3,140 Bytes
2fbcfac cc1a0c6 a6cbad6 b7f50c7 97430d2 cc1a0c6 a6cbad6 cc1a0c6 7b0f92a cc1a0c6 7b0f92a cc1a0c6 7b0f92a cc1a0c6 7b0f92a cc1a0c6 a6cbad6 70a19a9 cc1a0c6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import streamlit as st
import plotly.express as px
from model.predictor import predict_footprint
from utils.reducer import suggest_reduction
st.set_page_config(page_title="GreenPrint AI ๐ฑ", layout="centered")
# Custom CSS for green button
st.markdown("""
<style>
div.stButton > button:first-child {
background-color: #4CAF50;
color: white;
border: none;
padding: 8px 20px;
border-radius: 8px;
font-size: 16px;
transition: 0.3s;
}
div.stButton > button:first-child:hover {
background-color: #45a049;
color: white;
border: none;
}
</style>
""", unsafe_allow_html=True)
st.markdown("""
<h1 style='text-align: center; white-space: nowrap; overflow-x: auto; font-size: 2.2rem;'>
๐ฟ GreenPrint AI: Carbon Footprint Detector
</h1>
""", unsafe_allow_html=True)
# Emission factors (same as used in dataset creation)
EMISSION_FACTORS = {
"Car Travel": 0.2, # kg COโ per km
"Electricity": 0.5, # kg COโ per unit (kWh)
"Meat Consumption": 27 / 7, # Assuming avg 1 kg per 7 meals
"Flights": 250 # kg COโ per flight
}
# User Input
with st.form("activity_form"):
car_km = st.number_input("๐ Car travel per week (km)", 0, 1000, 50)
electricity = st.number_input("๐ก Electricity usage per month (units)", 0, 1000, 200)
meat = st.number_input("๐ Meat meals per week", 0, 21, 7)
flights = st.number_input("โ๏ธ Flights per year", 0, 20, 1)
submitted = st.form_submit_button("Calculate")
if submitted:
user_input = {
"car_km_per_week": car_km,
"electricity_units_per_month": electricity,
"meat_meals_per_week": meat,
"flights_per_year": flights
}
result = predict_footprint(user_input)
st.success(f"Estimated Annual Carbon Footprint: **{result:.2f} kg COโ**")
# Activity-wise contribution calculation
yearly_values = {
"Car Travel": car_km * 52 * EMISSION_FACTORS["Car Travel"],
"Electricity": electricity * 12 * EMISSION_FACTORS["Electricity"],
"Meat Consumption": meat * 52 * EMISSION_FACTORS["Meat Consumption"],
"Flights": flights * EMISSION_FACTORS["Flights"]
}
# Pie chart with green shades and percent labels
st.markdown("### ๐งพ Activity-wise Contribution to Your Footprint")
green_colors = ['#006400', '#228B22', '#32CD32', '#7CFC00'] # dark to light green
fig = px.pie(
names=yearly_values.keys(),
values=yearly_values.values(),
title="Your Carbon Footprint Breakdown",
color_discrete_sequence=green_colors,
hole=0.3
)
fig.update_traces(textinfo='label+percent', textfont_size=16)
st.plotly_chart(fig, use_container_width=True)
st.markdown("---")
st.subheader("โป๏ธ Suggestions to Reduce Your Footprint")
for tip in suggest_reduction(user_input):
st.markdown(f"- {tip}")
st.markdown("---")
st.markdown("<div style='text-align:center;'>Made with ๐ by Parishri</div>", unsafe_allow_html=True)
|