Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -121,6 +121,10 @@ st.markdown(
|
|
121 |
unsafe_allow_html=True,
|
122 |
)
|
123 |
|
|
|
|
|
|
|
|
|
124 |
if action == "Upload Image":
|
125 |
st.markdown(
|
126 |
"""
|
@@ -160,10 +164,14 @@ if action == "Upload Image":
|
|
160 |
for item in combined_items:
|
161 |
st.markdown(f"**Recycling Idea for {item}:**")
|
162 |
response = get_recycling_suggestions_from_groq(item, 1)
|
|
|
|
|
|
|
|
|
|
|
163 |
carbon_reduction = max(0.5, min(2.5, carbon_reduction_data.get(item.lower(), 0) * 1))
|
164 |
total_carbon_reduction += carbon_reduction
|
165 |
|
166 |
-
st.write(response)
|
167 |
st.markdown(
|
168 |
f"""<p style="color: #2e7d32;">π Carbon Footprint Reduction: {carbon_reduction:.2f} kg COβ</p>""",
|
169 |
unsafe_allow_html=True,
|
@@ -179,74 +187,11 @@ if action == "Upload Image":
|
|
179 |
else:
|
180 |
st.error("No recognizable waste items detected.")
|
181 |
|
182 |
-
|
183 |
st.markdown(
|
184 |
-
"""
|
185 |
-
|
186 |
-
|
187 |
-
</div>
|
188 |
-
""",
|
189 |
unsafe_allow_html=True,
|
190 |
-
)
|
191 |
-
selected_items = []
|
192 |
-
quantities = {}
|
193 |
-
|
194 |
-
cols = st.columns(len(predefined_clutter_items))
|
195 |
-
for i, (item, emoji) in enumerate(predefined_clutter_items.items()):
|
196 |
-
with cols[i]:
|
197 |
-
if st.checkbox(f"{emoji} {item.title()}", key=item):
|
198 |
-
selected_items.append(item)
|
199 |
-
quantities[item] = st.number_input(f"{item} (kg):", min_value=0.0, step=0.1, key=f"qty_{item}")
|
200 |
-
|
201 |
-
if selected_items and st.button("Generate Suggestions"):
|
202 |
-
total_carbon_reduction = 0
|
203 |
-
st.write("### β»οΈ Recycling Suggestions and Impact:")
|
204 |
-
for item, quantity in quantities.items():
|
205 |
-
if quantity > 0:
|
206 |
-
response = get_recycling_suggestions_from_groq(item, quantity)
|
207 |
-
carbon_reduction = max(0.5, min(2.5, carbon_reduction_data.get(item.lower(), 0) * quantity))
|
208 |
-
total_carbon_reduction += carbon_reduction
|
209 |
-
|
210 |
-
st.markdown(f"**{item} ({quantity} kg)**")
|
211 |
-
st.write(response)
|
212 |
-
st.markdown(
|
213 |
-
f"""<p style="color: #2e7d32;">π Carbon Footprint Reduction: {carbon_reduction:.2f} kg COβ</p>""",
|
214 |
-
unsafe_allow_html=True,
|
215 |
-
)
|
216 |
-
st.write("---")
|
217 |
-
|
218 |
-
st.markdown(
|
219 |
-
f"""<div style="padding: 15px; text-align: center; background-color: #004d40; color: #ffffff; border-radius: 5px;">
|
220 |
-
π Total Carbon Footprint Reduction: <b>{total_carbon_reduction:.2f} kg COβ saved</b>
|
221 |
-
</div>""",
|
222 |
-
unsafe_allow_html=True,
|
223 |
-
)
|
224 |
-
|
225 |
-
# Add session state for DIY instructions
|
226 |
-
if "diy_suggestion" not in st.session_state:
|
227 |
-
st.session_state.diy_suggestion = ""
|
228 |
-
|
229 |
-
suggestion = st.text_input("DIY Guide: Please cCopy and Paste any Idea generated above you wish to materilize:", key="diy_input")
|
230 |
-
if st.button("Generate DIY Instructions"):
|
231 |
-
if suggestion:
|
232 |
-
st.session_state.diy_suggestion = get_diy_steps_from_groq(suggestion)
|
233 |
-
|
234 |
-
if st.session_state.diy_suggestion:
|
235 |
-
st.markdown(
|
236 |
-
f"""<div style="padding: 10px; background-color: #f0f4c3; color: #33691e; border-radius: 5px;">
|
237 |
-
<h4>π DIY Instructions:</h4>
|
238 |
-
{st.session_state.diy_suggestion}
|
239 |
-
</div>""",
|
240 |
-
unsafe_allow_html=True,
|
241 |
-
)
|
242 |
-
|
243 |
-
# Motivational Message
|
244 |
-
st.markdown(
|
245 |
-
"""
|
246 |
-
<div style="text-align: center; padding: 20px; background-color: #dcedc8; border-radius: 10px;">
|
247 |
-
<h3 style="color: #33691e;">π Let's Keep Our Planet Green!</h3>
|
248 |
-
<p style="color: #2e7d32;">Recycling is not just an action but a responsibility. Together, we can make a difference. β»οΈπ</p>
|
249 |
-
</div>
|
250 |
-
""",
|
251 |
-
unsafe_allow_html=True,
|
252 |
-
)
|
|
|
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 |
"""
|
|
|
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))
|
173 |
total_carbon_reduction += carbon_reduction
|
174 |
|
|
|
175 |
st.markdown(
|
176 |
f"""<p style="color: #2e7d32;">π Carbon Footprint Reduction: {carbon_reduction:.2f} kg COβ</p>""",
|
177 |
unsafe_allow_html=True,
|
|
|
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;">
|
193 |
+
<h4>π DIY Instructions:</h4>
|
194 |
+
{st.session_state.clicked_diy}
|
195 |
+
</div>""",
|
|
|
196 |
unsafe_allow_html=True,
|
197 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|