ZainMalik0925 commited on
Commit
ed6c776
·
verified ·
1 Parent(s): 3b7ba3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -35
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.express as px
4
- import plotly.graph_objects as go
5
 
6
  # Add custom CSS for the background
7
  def add_background():
@@ -14,6 +13,12 @@ def add_background():
14
  background-position: center;
15
  background-attachment: fixed;
16
  }}
 
 
 
 
 
 
17
  </style>
18
  """
19
  st.markdown(css, unsafe_allow_html=True)
@@ -116,8 +121,8 @@ def get_inputs(prefix):
116
  # Adjust graph styling
117
  def style_figure(fig):
118
  fig.update_layout(
119
- plot_bgcolor="rgba(0,0,0,0.8)", # 20% transparency
120
- paper_bgcolor="rgba(0,0,0,0.8)", # 20% transparency
121
  font=dict(color="white"), # Font color set to white
122
  title_font=dict(size=18, color="white"), # Title font white
123
  xaxis=dict(title_font=dict(color="white"), tickfont=dict(color="white")),
@@ -145,24 +150,13 @@ if fiber_impact_data and transport_impact_data and washing_impact_data:
145
  water2, energy2, carbon2 = calculate_footprints(weight2, composition2, lifecycle2)
146
 
147
  # Display numerical comparison
148
- st.subheader("Numerical Comparison")
149
- st.markdown(f"<p style='color: white;'>**Assessment 1**: Water: {water1:.2f} kL, Energy: {energy1:.2f} MJ, Carbon: {carbon1:.2f} kg CO2e</p>", unsafe_allow_html=True)
150
- st.markdown(f"<p style='color: white;'>**Assessment 2**: Water: {water2:.2f} kL, Energy: {energy2:.2f} MJ, Carbon: {carbon2:.2f} kg CO2e</p>", unsafe_allow_html=True)
151
-
152
- # Bar chart comparison
153
- comparison_data = pd.DataFrame({
154
- "Footprint Type": ["Water (kL)", "Energy (MJ)", "Carbon (kg CO2e)"],
155
- "Assessment 1": [water1, energy1, carbon1],
156
- "Assessment 2": [water2, energy2, carbon2],
157
- })
158
- fig = px.bar(
159
- comparison_data.melt(id_vars="Footprint Type", var_name="Assessment", value_name="Value"),
160
- x="Footprint Type",
161
- y="Value",
162
- color_discrete_sequence=["white"],
163
- title="Comparison of Assessments"
164
- )
165
- st.plotly_chart(style_figure(fig))
166
 
167
  else:
168
  # Input for a single assessment
@@ -170,17 +164,11 @@ if fiber_impact_data and transport_impact_data and washing_impact_data:
170
  water, energy, carbon = calculate_footprints(weight, composition, lifecycle)
171
 
172
  # Display results
173
- st.subheader("Single Assessment Results")
174
- st.markdown(f"<p style='color: white;'>- **Water Footprint**: {water:.2f} kL</p>", unsafe_allow_html=True)
175
- st.markdown(f"<p style='color: white;'>- **Energy Footprint**: {energy:.2f} MJ</p>", unsafe_allow_html=True)
176
- st.markdown(f"<p style='color: white;'>- **Carbon Footprint**: {carbon:.2f} kg CO2e</p>", unsafe_allow_html=True)
177
-
178
- # Bar chart for single assessment
179
- result_data = pd.DataFrame({
180
- "Footprint Type": ["Water (kL)", "Energy (MJ)", "Carbon (kg CO2e)"],
181
- "Value": [water, energy, carbon]
182
- })
183
- fig = px.bar(result_data, x="Footprint Type", y="Value", title="Single Assessment Footprint Breakdown")
184
- st.plotly_chart(style_figure(fig))
185
- else:
186
- st.error("Failed to load dataset.")
 
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.express as px
 
4
 
5
  # Add custom CSS for the background
6
  def add_background():
 
13
  background-position: center;
14
  background-attachment: fixed;
15
  }}
16
+ .highlight {{
17
+ background-color: rgba(27, 27, 27, 0.7); /* 70% Opaque Black Background */
18
+ padding: 10px;
19
+ border-radius: 5px;
20
+ color: white;
21
+ }}
22
  </style>
23
  """
24
  st.markdown(css, unsafe_allow_html=True)
 
121
  # Adjust graph styling
122
  def style_figure(fig):
123
  fig.update_layout(
124
+ plot_bgcolor="rgba(27,27,27,0.8)", # 20% transparency
125
+ paper_bgcolor="rgba(27,27,27,0.8)", # 20% transparency
126
  font=dict(color="white"), # Font color set to white
127
  title_font=dict(size=18, color="white"), # Title font white
128
  xaxis=dict(title_font=dict(color="white"), tickfont=dict(color="white")),
 
150
  water2, energy2, carbon2 = calculate_footprints(weight2, composition2, lifecycle2)
151
 
152
  # Display numerical comparison
153
+ st.markdown(f"""
154
+ <div class="highlight">
155
+ <h2>Numerical Comparison</h2>
156
+ <p>**Assessment 1**: Water: {water1:.2f} kL, Energy: {energy1:.2f} MJ, Carbon: {carbon1:.2f} kg CO2e</p>
157
+ <p>**Assessment 2**: Water: {water2:.2f} kL, Energy: {energy2:.2f} MJ, Carbon: {carbon2:.2f} kg CO2e</p>
158
+ </div>
159
+ """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
160
 
161
  else:
162
  # Input for a single assessment
 
164
  water, energy, carbon = calculate_footprints(weight, composition, lifecycle)
165
 
166
  # Display results
167
+ st.markdown(f"""
168
+ <div class="highlight">
169
+ <h2>Single Assessment Results</h2>
170
+ <p>- **Water Footprint**: {water:.2f} kL</p>
171
+ <p>- **Energy Footprint**: {energy:.2f} MJ</p>
172
+ <p>- **Carbon Footprint**: {carbon:.2f} kg CO2e</p>
173
+ </div>
174
+ """, unsafe_allow_html=True)