Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ import numpy as np
|
|
10 |
os.environ["GROQ_API_KEY"] = "key"
|
11 |
|
12 |
# Initialize Groq client
|
13 |
-
client = Groq(api_key=os.environ.get("
|
14 |
|
15 |
# Carbon footprint reduction data (kg CO2 per kg recycled)
|
16 |
carbon_reduction_data = {
|
@@ -98,10 +98,6 @@ def get_diy_steps_from_groq(item):
|
|
98 |
except Exception as e:
|
99 |
return f"Error fetching DIY instructions: {e}"
|
100 |
|
101 |
-
# Initialize session state for clicked DIY
|
102 |
-
if "clicked_diy" not in st.session_state:
|
103 |
-
st.session_state.clicked_diy = ""
|
104 |
-
|
105 |
# Sidebar
|
106 |
st.sidebar.markdown(
|
107 |
"""
|
@@ -161,17 +157,13 @@ if action == "Upload Image":
|
|
161 |
st.write(", ".join(combined_items))
|
162 |
|
163 |
total_carbon_reduction = 0
|
164 |
-
for
|
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_idx, suggestion in enumerate(suggestions):
|
169 |
-
if st.button(f"{suggestion}", key=f"{suggestion}_{idx}_{suggestion_idx}"):
|
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,
|
@@ -230,12 +222,31 @@ elif action == "Get Suggestions for Items":
|
|
230 |
unsafe_allow_html=True,
|
231 |
)
|
232 |
|
233 |
-
#
|
234 |
-
if st.session_state
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
os.environ["GROQ_API_KEY"] = "key"
|
11 |
|
12 |
# Initialize Groq client
|
13 |
+
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
14 |
|
15 |
# Carbon footprint reduction data (kg CO2 per kg recycled)
|
16 |
carbon_reduction_data = {
|
|
|
98 |
except Exception as e:
|
99 |
return f"Error fetching DIY instructions: {e}"
|
100 |
|
|
|
|
|
|
|
|
|
101 |
# Sidebar
|
102 |
st.sidebar.markdown(
|
103 |
"""
|
|
|
157 |
st.write(", ".join(combined_items))
|
158 |
|
159 |
total_carbon_reduction = 0
|
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,
|
|
|
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("Enter a suggestion to get DIY instructions:", 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 |
+
)
|