ZainMalik0925 commited on
Commit
2587cb1
·
verified ·
1 Parent(s): 53b9d1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -24
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import streamlit as st
2
  import pandas as pd
3
- import plotly.graph_objects as go
4
  import plotly.express as px
5
 
6
  # Set page configurations
@@ -76,12 +75,11 @@ def calculate_footprints(weight, composition, lifecycle_inputs):
76
  carbon_fp += washing_carbon + (dryer_carbon * lifecycle_inputs["washing_cycles"])
77
 
78
  # Convert water footprint from liters to kiloliters for visualization
79
- water_fp_kL = water_fp / 1000
80
  return water_fp_kL, energy_fp, carbon_fp
81
 
82
  # Sidebar inputs for all scenarios
83
  def get_inputs(key_prefix):
84
- st.sidebar.subheader(f"Inputs for {key_prefix}")
85
  product_weight = st.sidebar.number_input(f"{key_prefix} - Product Weight (kg)", min_value=0.01, step=0.01, value=0.5, key=f"{key_prefix}_weight")
86
 
87
  st.sidebar.subheader(f"{key_prefix} - Material Composition (%)")
@@ -125,38 +123,38 @@ if uploaded_file and fiber_impact_data and transport_impact_data and washing_imp
125
  comparison_mode = st.sidebar.checkbox("Enable Comparison Mode")
126
 
127
  if comparison_mode:
128
- # Input for two scenarios
129
  col1, col2 = st.columns(2)
130
  with col1:
131
- st.subheader("Scenario 1")
132
- product_weight_1, composition_1, lifecycle_inputs_1 = get_inputs("Scenario 1")
133
  with col2:
134
- st.subheader("Scenario 2")
135
- product_weight_2, composition_2, lifecycle_inputs_2 = get_inputs("Scenario 2")
136
 
137
- # Calculations for both scenarios
138
  water_fp_1, energy_fp_1, carbon_fp_1 = calculate_footprints(product_weight_1, composition_1, lifecycle_inputs_1)
139
  water_fp_2, energy_fp_2, carbon_fp_2 = calculate_footprints(product_weight_2, composition_2, lifecycle_inputs_2)
140
 
141
- # Combined visualization
142
- st.subheader("Comparison Results")
143
- comparison_data = pd.DataFrame({
144
  "Footprint Type": ["Water (kL)", "Energy (MJ)", "Carbon (kg CO2e)"],
145
- "Scenario 1": [water_fp_1, energy_fp_1, carbon_fp_1],
146
- "Scenario 2": [water_fp_2, energy_fp_2, carbon_fp_2],
147
  })
148
- fig = px.bar(
149
- comparison_data,
150
- x="Footprint Type",
151
- y=["Scenario 1", "Scenario 2"],
152
- barmode="group",
153
- title="Comparison of Footprints"
 
154
  )
155
  st.plotly_chart(fig)
156
  else:
157
- # Input for single scenario
158
- st.subheader("Single Scenario")
159
- product_weight, composition, lifecycle_inputs = get_inputs("Single Scenario")
160
  water_fp, energy_fp, carbon_fp = calculate_footprints(product_weight, composition, lifecycle_inputs)
161
 
162
  # Display results
@@ -165,7 +163,7 @@ if uploaded_file and fiber_impact_data and transport_impact_data and washing_imp
165
  st.markdown(f"- **Energy Footprint**: {energy_fp:.2f} MJ")
166
  st.markdown(f"- **Carbon Footprint**: {carbon_fp:.2f} kg CO2e")
167
 
168
- # Visualization
169
  result_data = pd.DataFrame({
170
  "Footprint Type": ["Water (kL)", "Energy (MJ)", "Carbon (kg CO2e)"],
171
  "Value": [water_fp, energy_fp, carbon_fp],
 
1
  import streamlit as st
2
  import pandas as pd
 
3
  import plotly.express as px
4
 
5
  # Set page configurations
 
75
  carbon_fp += washing_carbon + (dryer_carbon * lifecycle_inputs["washing_cycles"])
76
 
77
  # Convert water footprint from liters to kiloliters for visualization
78
+ water_fp_kL = water_fp / 1000 # Convert liters to kiloliters
79
  return water_fp_kL, energy_fp, carbon_fp
80
 
81
  # Sidebar inputs for all scenarios
82
  def get_inputs(key_prefix):
 
83
  product_weight = st.sidebar.number_input(f"{key_prefix} - Product Weight (kg)", min_value=0.01, step=0.01, value=0.5, key=f"{key_prefix}_weight")
84
 
85
  st.sidebar.subheader(f"{key_prefix} - Material Composition (%)")
 
123
  comparison_mode = st.sidebar.checkbox("Enable Comparison Mode")
124
 
125
  if comparison_mode:
126
+ # Input for two assessments
127
  col1, col2 = st.columns(2)
128
  with col1:
129
+ st.subheader("Assessment 1")
130
+ product_weight_1, composition_1, lifecycle_inputs_1 = get_inputs("Assessment 1")
131
  with col2:
132
+ st.subheader("Assessment 2")
133
+ product_weight_2, composition_2, lifecycle_inputs_2 = get_inputs("Assessment 2")
134
 
135
+ # Calculations for both assessments
136
  water_fp_1, energy_fp_1, carbon_fp_1 = calculate_footprints(product_weight_1, composition_1, lifecycle_inputs_1)
137
  water_fp_2, energy_fp_2, carbon_fp_2 = calculate_footprints(product_weight_2, composition_2, lifecycle_inputs_2)
138
 
139
+ # Combined visualization with line chart
140
+ st.subheader("Comparison of Assessments")
141
+ assessment_data = pd.DataFrame({
142
  "Footprint Type": ["Water (kL)", "Energy (MJ)", "Carbon (kg CO2e)"],
143
+ "Assessment 1": [water_fp_1, energy_fp_1, carbon_fp_1],
144
+ "Assessment 2": [water_fp_2, energy_fp_2, carbon_fp_2],
145
  })
146
+ fig = px.line(
147
+ assessment_data.melt(id_vars="Footprint Type", var_name="Assessment", value_name="Value"),
148
+ x="Footprint Type",
149
+ y="Value",
150
+ color="Assessment",
151
+ markers=True,
152
+ title="Footprint Trends: Assessment 1 vs. Assessment 2"
153
  )
154
  st.plotly_chart(fig)
155
  else:
156
+ # Input for single calculation
157
+ product_weight, composition, lifecycle_inputs = get_inputs("")
 
158
  water_fp, energy_fp, carbon_fp = calculate_footprints(product_weight, composition, lifecycle_inputs)
159
 
160
  # Display results
 
163
  st.markdown(f"- **Energy Footprint**: {energy_fp:.2f} MJ")
164
  st.markdown(f"- **Carbon Footprint**: {carbon_fp:.2f} kg CO2e")
165
 
166
+ # Visualization for single scenario
167
  result_data = pd.DataFrame({
168
  "Footprint Type": ["Water (kL)", "Energy (MJ)", "Carbon (kg CO2e)"],
169
  "Value": [water_fp, energy_fp, carbon_fp],