-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
83 lines (65 loc) · 3.12 KB
/
app.py
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
import streamlit as st
# Define emission factors (example values, replace with accurate data)
EMISSION_FACTORS = {
"India": {
"Transportation": 0.14, # kgCO2/km
"Electricity": 0.82, # kgCO2/kWh
"Diet": 1.25, # kgCO2/meal, 2.5kgco2/kg
"Waste": 0.1 # kgCO2/kg
}
}
# Set wide layout and page name
st.set_page_config(layout="wide", page_title="Personal Carbon Calculator")
# Streamlit app code
st.title("Employee Carbon Calculator App ⚠️")
# User inputs
st.subheader("🌍 Your Country")
country = st.selectbox("Select", ["India"])
col1, col2 = st.columns(2)
with col1:
st.subheader("🚗 Daily commute distance (in km)")
distance = st.slider("Distance", 0.0, 100.0, key="distance_input")
st.subheader("💡 Monthly electricity consumption (in kWh)")
electricity = st.slider("Electricity", 0.0, 1000.0, key="electricity_input")
with col2:
st.subheader("🍽️ Waste generated per week (in kg)")
waste = st.slider("Waste", 0.0, 100.0, key="waste_input")
st.subheader("🍽️ Number of meals per day")
meals = st.number_input("Meals", 0, key="meals_input")
# Normalize inputs
if distance > 0:
distance = distance * 365 # Convert daily distance to yearly
if electricity > 0:
electricity = electricity * 12 # Convert monthly electricity to yearly
if meals > 0:
meals = meals * 365 # Convert daily meals to yearly
if waste > 0:
waste = waste * 52 # Convert weekly waste to yearly
# Calculate carbon emissions
transportation_emissions = EMISSION_FACTORS[country]["Transportation"] * distance
electricity_emissions = EMISSION_FACTORS[country]["Electricity"] * electricity
diet_emissions = EMISSION_FACTORS[country]["Diet"] * meals
waste_emissions = EMISSION_FACTORS[country]["Waste"] * waste
# Convert emissions to tonnes and round off to 2 decimal points
transportation_emissions = round(transportation_emissions / 1000, 2)
electricity_emissions = round(electricity_emissions / 1000, 2)
diet_emissions = round(diet_emissions / 1000, 2)
waste_emissions = round(waste_emissions / 1000, 2)
# Calculate total emissions
total_emissions = round(
transportation_emissions + electricity_emissions + diet_emissions + waste_emissions, 2
)
if st.button("Calculate CO2 Emissions"):
# Display results
st.header("Results")
col3, col4 = st.columns(2)
with col3:
st.subheader("Carbon Emissions by Category")
st.info(f"🚗 Transportation: {transportation_emissions} tonnes CO2 per year")
st.info(f"💡 Electricity: {electricity_emissions} tonnes CO2 per year")
st.info(f"🍽️ Diet: {diet_emissions} tonnes CO2 per year")
st.info(f"🗑️ Waste: {waste_emissions} tonnes CO2 per year")
with col4:
st.subheader("Total Carbon Footprint")
st.success(f"🌍 Your total carbon footprint is: {total_emissions} tonnes CO2 per year")
st.warning("In 2021, CO2 emissions per capita for India was 1.9 tons of CO2 per capita. Between 1972 and 2021, CO2 emissions per capita of India grew substantially from 0.39 to 1.9 tons of CO2 per capita rising at an increasing annual rate that reached a maximum of 9.41% in 2021")