ZainMalik0925 commited on
Commit
534710b
·
verified ·
1 Parent(s): ba73e4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -35
app.py CHANGED
@@ -1,42 +1,46 @@
1
  import streamlit as st
2
  import pandas as pd
 
 
3
 
4
  # Title of the Application
5
- st.title("Textile Lifecycle Footprint Calculator")
6
- st.markdown("""
7
- This tool calculates the **Water**, **Energy**, and **Carbon Footprints** for textile products dynamically.
8
- Provide product and lifecycle inputs to get precise results based on the dataset.
9
- """)
 
 
 
10
 
11
  # Sidebar for User Inputs
12
  st.sidebar.header("Input Product Details")
13
 
14
- # Product-specific inputs
15
- product_type = st.sidebar.selectbox("Product Type", ["T-shirt", "Jeans", "Shirt", "Carpet"])
16
  product_weight = st.sidebar.number_input("Product Weight (kg)", min_value=0.01, step=0.01, value=0.25)
17
 
18
- # Fiber composition (in %)
19
  st.sidebar.subheader("Material Composition (%)")
20
- cotton_percent = st.sidebar.slider("Cotton (%)", 0, 100, 50)
21
- polyester_percent = st.sidebar.slider("Polyester (%)", 0, 100, 30)
22
- nylon_percent = st.sidebar.slider("Nylon (%)", 0, 100, 10)
23
- acrylic_percent = st.sidebar.slider("Acrylic (%)", 0, 100, 5)
24
- viscose_percent = st.sidebar.slider("Viscose (%)", 0, 100, 5)
25
-
26
- # Validation check: Percentages must add up to 100%
27
- total_percentage = cotton_percent + polyester_percent + nylon_percent + acrylic_percent + viscose_percent
28
- if total_percentage != 100:
29
- st.sidebar.warning("Material composition percentages must sum up to 100.")
30
-
31
- # Lifecycle inputs
32
  st.sidebar.header("Lifecycle Details")
33
  washing_cycles = st.sidebar.number_input("Number of Washing Cycles", min_value=0, step=10, value=30)
34
  washing_temperature = st.sidebar.selectbox("Washing Temperature", ["Cold", "30°C", "40°C", "60°C"])
35
  use_dryer = st.sidebar.checkbox("Use Tumble Dryer?")
36
- transport_mode = st.sidebar.selectbox("Transport Mode", ["Plane", "Ship", "Train", "Truck"])
37
  transport_distance = st.sidebar.number_input("Transport Distance (km)", min_value=0, step=50)
38
 
39
- # Fiber Impact Data (from Parameter.pdf)
40
  fiber_impact_data = {
41
  "Cotton": {"Water": 10000, "Energy": 60, "Carbon": 3.18},
42
  "Polyester": {"Water": 62, "Energy": 125, "Carbon": 4.8},
@@ -96,18 +100,18 @@ user_inputs = {
96
  "use_dryer": use_dryer,
97
  }
98
 
99
- # Composition dictionary
100
- composition = {
101
- "Cotton": cotton_percent,
102
- "Polyester": polyester_percent,
103
- "Nylon": nylon_percent,
104
- "Acrylic": acrylic_percent,
105
- "Viscose": viscose_percent,
106
- }
107
 
108
- # Perform calculations
109
- if total_percentage == 100:
110
- # Perform footprint calculation
 
 
 
 
 
 
111
  water_fp, energy_fp, carbon_fp = calculate_footprints(product_weight, composition, user_inputs)
112
 
113
  # Display results
@@ -117,6 +121,19 @@ if total_percentage == 100:
117
  - **Energy Footprint**: {energy_fp:.2f} MJ
118
  - **Carbon Footprint**: {carbon_fp:.2f} kgCO2e
119
  """)
120
- else:
121
- st.warning("Ensure that the material composition sums up to 100%.")
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import plotly.graph_objects as go
4
+ import time
5
 
6
  # Title of the Application
7
+ st.set_page_config(page_title="GreenLens-AI", layout="wide")
8
+ st.markdown("<h1 style='text-align: center; color: #4CAF50;'>GreenLens-AI</h1>", unsafe_allow_html=True)
9
+ st.markdown(
10
+ """
11
+ <p style='text-align: center; color: #4CAF50; font-size: 18px;'>
12
+ Analyze the Water, Energy, and Carbon Footprints of Textile Products for a Sustainable Future 🌍
13
+ </p>
14
+ """, unsafe_allow_html=True)
15
 
16
  # Sidebar for User Inputs
17
  st.sidebar.header("Input Product Details")
18
 
19
+ # Input Section: Product-Specific Inputs
20
+ product_type = st.sidebar.selectbox("Product Type", ["T-shirt", "Jeans", "Shirt", "Carpet"], index=0)
21
  product_weight = st.sidebar.number_input("Product Weight (kg)", min_value=0.01, step=0.01, value=0.25)
22
 
23
+ # Fiber Composition Input
24
  st.sidebar.subheader("Material Composition (%)")
25
+ st.sidebar.markdown("Enter the composition manually (sum to 100%) or use default values:")
26
+
27
+ # Create a DataFrame for interactive input
28
+ default_composition = {'Cotton': 50, 'Polyester': 30, 'Nylon': 10, 'Acrylic': 5, 'Viscose': 5}
29
+ fiber_df = pd.DataFrame.from_dict(default_composition, orient='index', columns=['Percentage'])
30
+ fiber_df = st.sidebar.experimental_data_editor(fiber_df, num_rows="fixed", key="fiber_editor")
31
+
32
+ if fiber_df['Percentage'].sum() != 100:
33
+ st.sidebar.error("The total of all fiber percentages must equal 100%.")
34
+
35
+ # Lifecycle Inputs
 
36
  st.sidebar.header("Lifecycle Details")
37
  washing_cycles = st.sidebar.number_input("Number of Washing Cycles", min_value=0, step=10, value=30)
38
  washing_temperature = st.sidebar.selectbox("Washing Temperature", ["Cold", "30°C", "40°C", "60°C"])
39
  use_dryer = st.sidebar.checkbox("Use Tumble Dryer?")
40
+ transport_mode = st.sidebar.selectbox("Transport Mode", ["Plane", "Ship", "Train", "Truck"], index=1)
41
  transport_distance = st.sidebar.number_input("Transport Distance (km)", min_value=0, step=50)
42
 
43
+ # Fiber Impact Data
44
  fiber_impact_data = {
45
  "Cotton": {"Water": 10000, "Energy": 60, "Carbon": 3.18},
46
  "Polyester": {"Water": 62, "Energy": 125, "Carbon": 4.8},
 
100
  "use_dryer": use_dryer,
101
  }
102
 
103
+ # Collect the composition dictionary
104
+ composition = fiber_df['Percentage'].to_dict()
 
 
 
 
 
 
105
 
106
+ # Run Calculations and Display Progress Bar
107
+ if fiber_df['Percentage'].sum() == 100:
108
+ progress_text = "Calculating Footprints..."
109
+ progress_bar = st.progress(0)
110
+ for i in range(1, 101):
111
+ time.sleep(0.01)
112
+ progress_bar.progress(i, text=progress_text)
113
+
114
+ # Call the calculation function
115
  water_fp, energy_fp, carbon_fp = calculate_footprints(product_weight, composition, user_inputs)
116
 
117
  # Display results
 
121
  - **Energy Footprint**: {energy_fp:.2f} MJ
122
  - **Carbon Footprint**: {carbon_fp:.2f} kgCO2e
123
  """)
 
 
124
 
125
+ # 3D Visualization
126
+ fig = go.Figure()
127
+ fig.add_trace(go.Bar(x=["Water Footprint", "Energy Footprint", "Carbon Footprint"],
128
+ y=[water_fp, energy_fp, carbon_fp],
129
+ text=[f"{water_fp:.2f} L", f"{energy_fp:.2f} MJ", f"{carbon_fp:.2f} kgCO2e"],
130
+ textposition='auto',
131
+ marker=dict(color=["blue", "orange", "green"])))
132
+ fig.update_layout(title="Footprint Breakdown (3D Visualization)",
133
+ xaxis_title="Footprint Type",
134
+ yaxis_title="Footprint Value",
135
+ template="plotly_dark")
136
+ st.plotly_chart(fig)
137
+
138
+ else:
139
+ st.error("Ensure that the material composition sums up to 100%.")