Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -121,10 +121,6 @@ st.markdown(
|
|
121 |
unsafe_allow_html=True,
|
122 |
)
|
123 |
|
124 |
-
# Session state to track clicked DIY suggestions
|
125 |
-
if "clicked_diy" not in st.session_state:
|
126 |
-
st.session_state.clicked_diy = ""
|
127 |
-
|
128 |
if action == "Upload Image":
|
129 |
st.markdown(
|
130 |
"""
|
@@ -161,12 +157,12 @@ if action == "Upload Image":
|
|
161 |
st.write(", ".join(combined_items))
|
162 |
|
163 |
total_carbon_reduction = 0
|
164 |
-
for item in combined_items:
|
165 |
st.markdown(f"**Recycling Idea for {item}:**")
|
166 |
response = get_recycling_suggestions_from_groq(item, 1)
|
167 |
suggestions = response.split("\n")
|
168 |
-
for suggestion in suggestions:
|
169 |
-
if st.button(f"{suggestion}", key=suggestion):
|
170 |
st.session_state.clicked_diy = get_diy_steps_from_groq(suggestion)
|
171 |
|
172 |
carbon_reduction = max(0.5, min(2.5, carbon_reduction_data.get(item.lower(), 0) * 1))
|
@@ -187,6 +183,49 @@ if action == "Upload Image":
|
|
187 |
else:
|
188 |
st.error("No recognizable waste items detected.")
|
189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
if st.session_state.clicked_diy:
|
191 |
st.markdown(
|
192 |
f"""<div style="padding: 10px; background-color: #f0f4c3; color: #33691e; border-radius: 5px;">
|
@@ -194,4 +233,4 @@ if st.session_state.clicked_diy:
|
|
194 |
{st.session_state.clicked_diy}
|
195 |
</div>""",
|
196 |
unsafe_allow_html=True,
|
197 |
-
)
|
|
|
121 |
unsafe_allow_html=True,
|
122 |
)
|
123 |
|
|
|
|
|
|
|
|
|
124 |
if action == "Upload Image":
|
125 |
st.markdown(
|
126 |
"""
|
|
|
157 |
st.write(", ".join(combined_items))
|
158 |
|
159 |
total_carbon_reduction = 0
|
160 |
+
for idx, item in enumerate(combined_items):
|
161 |
st.markdown(f"**Recycling Idea for {item}:**")
|
162 |
response = get_recycling_suggestions_from_groq(item, 1)
|
163 |
suggestions = response.split("\n")
|
164 |
+
for suggestion_idx, suggestion in enumerate(suggestions):
|
165 |
+
if st.button(f"{suggestion}", key=f"{suggestion}_{idx}_{suggestion_idx}"):
|
166 |
st.session_state.clicked_diy = get_diy_steps_from_groq(suggestion)
|
167 |
|
168 |
carbon_reduction = max(0.5, min(2.5, carbon_reduction_data.get(item.lower(), 0) * 1))
|
|
|
183 |
else:
|
184 |
st.error("No recognizable waste items detected.")
|
185 |
|
186 |
+
elif action == "Get Suggestions for Items":
|
187 |
+
st.markdown(
|
188 |
+
"""
|
189 |
+
<div style="text-align: center; background-color: #fff3e0; padding: 10px; border-radius: 5px;">
|
190 |
+
<h3 style="color: #ff6f00;">Select clutter items for recycling suggestions:</h3>
|
191 |
+
</div>
|
192 |
+
""",
|
193 |
+
unsafe_allow_html=True,
|
194 |
+
)
|
195 |
+
selected_items = []
|
196 |
+
quantities = {}
|
197 |
+
|
198 |
+
cols = st.columns(len(predefined_clutter_items))
|
199 |
+
for i, (item, emoji) in enumerate(predefined_clutter_items.items()):
|
200 |
+
with cols[i]:
|
201 |
+
if st.checkbox(f"{emoji} {item.title()}", key=item):
|
202 |
+
selected_items.append(item)
|
203 |
+
quantities[item] = st.number_input(f"{item} (kg):", min_value=0.0, step=0.1, key=f"qty_{item}")
|
204 |
+
|
205 |
+
if selected_items and st.button("Generate Suggestions"):
|
206 |
+
total_carbon_reduction = 0
|
207 |
+
st.write("### ♻️ Recycling Suggestions and Impact:")
|
208 |
+
for item, quantity in quantities.items():
|
209 |
+
if quantity > 0:
|
210 |
+
response = get_recycling_suggestions_from_groq(item, quantity)
|
211 |
+
carbon_reduction = max(0.5, min(2.5, carbon_reduction_data.get(item.lower(), 0) * quantity))
|
212 |
+
total_carbon_reduction += carbon_reduction
|
213 |
+
|
214 |
+
st.markdown(f"**{item} ({quantity} kg)**")
|
215 |
+
st.write(response)
|
216 |
+
st.markdown(
|
217 |
+
f"""<p style="color: #2e7d32;">🌍 Carbon Footprint Reduction: {carbon_reduction:.2f} kg CO₂</p>""",
|
218 |
+
unsafe_allow_html=True,
|
219 |
+
)
|
220 |
+
st.write("---")
|
221 |
+
|
222 |
+
st.markdown(
|
223 |
+
f"""<div style="padding: 15px; text-align: center; background-color: #004d40; color: #ffffff; border-radius: 5px;">
|
224 |
+
🌟 Total Carbon Footprint Reduction: <b>{total_carbon_reduction:.2f} kg CO₂ saved</b>
|
225 |
+
</div>""",
|
226 |
+
unsafe_allow_html=True,
|
227 |
+
)
|
228 |
+
|
229 |
if st.session_state.clicked_diy:
|
230 |
st.markdown(
|
231 |
f"""<div style="padding: 10px; background-color: #f0f4c3; color: #33691e; border-radius: 5px;">
|
|
|
233 |
{st.session_state.clicked_diy}
|
234 |
</div>""",
|
235 |
unsafe_allow_html=True,
|
236 |
+
)
|