ZainMalik0925 commited on
Commit
b422580
·
verified ·
1 Parent(s): 6df0e79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -15
app.py CHANGED
@@ -3,13 +3,13 @@ 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
 
@@ -17,27 +17,28 @@ st.markdown(
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
@@ -101,10 +102,16 @@ user_inputs = {
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):
@@ -132,7 +139,7 @@ if fiber_df['Percentage'].sum() == 100:
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:
 
3
  import plotly.graph_objects as go
4
  import time
5
 
6
+ # Set Page Configurations
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
+ A Comprehensive Tool for Calculating Water, Energy, and Carbon Footprints of Textile Products 🌍
13
  </p>
14
  """, unsafe_allow_html=True)
15
 
 
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"])
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
+ cotton_percent = st.sidebar.slider("Cotton (%)", 0, 100, 50)
26
+ polyester_percent = st.sidebar.slider("Polyester (%)", 0, 100, 30)
27
+ nylon_percent = st.sidebar.slider("Nylon (%)", 0, 100, 10)
28
+ acrylic_percent = st.sidebar.slider("Acrylic (%)", 0, 100, 5)
29
+ viscose_percent = st.sidebar.slider("Viscose (%)", 0, 100, 5)
30
 
31
+ # Validation check: Percentages must add up to 100%
32
+ total_percentage = cotton_percent + polyester_percent + nylon_percent + acrylic_percent + viscose_percent
33
+ if total_percentage != 100:
34
+ st.sidebar.error("The total of all fiber percentages must equal 100%!")
 
 
 
35
 
36
  # Lifecycle Inputs
37
  st.sidebar.header("Lifecycle Details")
38
  washing_cycles = st.sidebar.number_input("Number of Washing Cycles", min_value=0, step=10, value=30)
39
  washing_temperature = st.sidebar.selectbox("Washing Temperature", ["Cold", "30°C", "40°C", "60°C"])
40
  use_dryer = st.sidebar.checkbox("Use Tumble Dryer?")
41
+ transport_mode = st.sidebar.selectbox("Transport Mode", ["Plane", "Ship", "Train", "Truck"])
42
  transport_distance = st.sidebar.number_input("Transport Distance (km)", min_value=0, step=50)
43
 
44
  # Fiber Impact Data
 
102
  }
103
 
104
  # Collect the composition dictionary
105
+ composition = {
106
+ "Cotton": cotton_percent,
107
+ "Polyester": polyester_percent,
108
+ "Nylon": nylon_percent,
109
+ "Acrylic": acrylic_percent,
110
+ "Viscose": viscose_percent,
111
+ }
112
 
113
  # Run Calculations and Display Progress Bar
114
+ if total_percentage == 100:
115
  progress_text = "Calculating Footprints..."
116
  progress_bar = st.progress(0)
117
  for i in range(1, 101):
 
139
  fig.update_layout(title="Footprint Breakdown (3D Visualization)",
140
  xaxis_title="Footprint Type",
141
  yaxis_title="Footprint Value",
142
+ template="plotly_white")
143
  st.plotly_chart(fig)
144
 
145
  else: