Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,6 +19,129 @@ carbon_reduction_data = {
|
|
19 |
"Tires": 8.0,
|
20 |
}
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Function to call Groq LLM
|
23 |
def get_recycling_suggestions_from_groq(item, quantity):
|
24 |
prompt = (
|
@@ -91,3 +214,4 @@ if st.button("Ask Groq"):
|
|
91 |
st.write(follow_up_response)
|
92 |
else:
|
93 |
st.error("Please enter a question.")
|
|
|
|
19 |
"Tires": 8.0,
|
20 |
}
|
21 |
|
22 |
+
# Function to call Groq LLM
|
23 |
+
def get_recycling_suggestions_from_groq(item, quantity):
|
24 |
+
prompt = (
|
25 |
+
f"You are an expert in recycling and sustainability. "
|
26 |
+
f"Suggest profitable and eco-friendly uses for {quantity} kg of {item}, "
|
27 |
+
f"including household uses, ways to monetize them, and calculate carbon footprint reduction."
|
28 |
+
)
|
29 |
+
chat_completion = client.chat.completions.create(
|
30 |
+
messages=[{"role": "user", "content": prompt}],
|
31 |
+
model="llama-3.3-70b-versatile",
|
32 |
+
stream=False,
|
33 |
+
)
|
34 |
+
return chat_completion.choices[0].message.content
|
35 |
+
|
36 |
+
# Sidebar for Navigation
|
37 |
+
st.sidebar.title("π RecycleSmart-PK")
|
38 |
+
st.sidebar.markdown("### Navigation")
|
39 |
+
section = st.sidebar.radio(
|
40 |
+
"Choose a section:",
|
41 |
+
["Home", "Recycle Suggestions", "Carbon Impact", "FAQs"]
|
42 |
+
)
|
43 |
+
st.sidebar.markdown("---")
|
44 |
+
st.sidebar.image("https://media.giphy.com/media/26xBI73gWquCBBCDe/giphy.gif", use_column_width=True)
|
45 |
+
|
46 |
+
# Main Content Based on Section
|
47 |
+
if section == "Home":
|
48 |
+
st.title("β»οΈ Welcome to RecycleSmart-PK!")
|
49 |
+
st.markdown(
|
50 |
+
"""
|
51 |
+
### π Your Smart Recycling Assistant π
|
52 |
+
Transform your clutter into profits while saving the planet.
|
53 |
+
Select items to recycle, get creative suggestions, and see how much COβ you can reduce!
|
54 |
+
"""
|
55 |
+
)
|
56 |
+
st.image("https://media.giphy.com/media/3oEjI6SIIHBdRxXI40/giphy.gif", use_column_width=True)
|
57 |
+
|
58 |
+
elif section == "Recycle Suggestions":
|
59 |
+
st.title("π‘ Recycling Suggestions")
|
60 |
+
selected_items = st.multiselect(
|
61 |
+
"π¦ Select items to recycle:",
|
62 |
+
list(carbon_reduction_data.keys())
|
63 |
+
)
|
64 |
+
quantities = {item: st.number_input(f"Enter quantity for {item} (in kg):", min_value=0, step=1, format="%d") for item in selected_items}
|
65 |
+
|
66 |
+
if st.button("Get Suggestions"):
|
67 |
+
if selected_items:
|
68 |
+
total_carbon_reduction = 0
|
69 |
+
st.write("### β»οΈ Suggestions and Impact:")
|
70 |
+
for item, quantity in quantities.items():
|
71 |
+
if quantity > 0:
|
72 |
+
llm_response = get_recycling_suggestions_from_groq(item, quantity)
|
73 |
+
carbon_reduction = carbon_reduction_data.get(item, 0) * quantity
|
74 |
+
total_carbon_reduction += carbon_reduction
|
75 |
+
st.write(f"**π¦ {item} ({quantity} kg)**")
|
76 |
+
st.write(f"π‘ {llm_response}")
|
77 |
+
st.write(f"π **Carbon Footprint Reduction**: {carbon_reduction:.2f} kg COβ")
|
78 |
+
st.markdown("---")
|
79 |
+
|
80 |
+
st.write("### π Total Carbon Footprint Reduction π")
|
81 |
+
st.write(f"π **{total_carbon_reduction:.2f} kg COβ saved**")
|
82 |
+
st.success("π Great job contributing to a greener planet!")
|
83 |
+
else:
|
84 |
+
st.error("β Please select at least one item and specify its quantity.")
|
85 |
+
|
86 |
+
elif section == "Carbon Impact":
|
87 |
+
st.title("π Carbon Impact Analysis")
|
88 |
+
st.markdown(
|
89 |
+
"""
|
90 |
+
### πΏ Why Recycling Matters
|
91 |
+
Recycling reduces waste in landfills, conserves natural resources, and lowers greenhouse gas emissions.
|
92 |
+
"""
|
93 |
+
)
|
94 |
+
st.image("https://media.giphy.com/media/l4FGn8AsM9v6KAcYE/giphy.gif", use_column_width=True)
|
95 |
+
st.markdown(
|
96 |
+
"""
|
97 |
+
#### π‘ Fun Fact:
|
98 |
+
Recycling one ton of plastic bottles saves **3.8 tons of COβ**!
|
99 |
+
Imagine the difference you can make!
|
100 |
+
"""
|
101 |
+
)
|
102 |
+
|
103 |
+
elif section == "FAQs":
|
104 |
+
st.title("π€ FAQs")
|
105 |
+
st.markdown(
|
106 |
+
"""
|
107 |
+
### Common Questions
|
108 |
+
**Q: How does RecycleSmart-PK calculate COβ reduction?**
|
109 |
+
A: We use predefined data for each item type based on average recycling benefits.
|
110 |
+
|
111 |
+
**Q: Can I suggest new items?**
|
112 |
+
A: Yes! Reach out to us, and we'll add more items to the list.
|
113 |
+
|
114 |
+
**Q: How do I recycle items near me?**
|
115 |
+
A: Visit local recycling centers or community initiatives.
|
116 |
+
"""
|
117 |
+
)
|
118 |
+
st.image("https://media.giphy.com/media/3ohzdQ1IynzclJldUQ/giphy.gif", use_column_width=True)
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
"""
|
124 |
+
import os
|
125 |
+
import streamlit as st
|
126 |
+
from groq import Groq
|
127 |
+
|
128 |
+
# Set the Groq API key
|
129 |
+
os.environ["GROQ_API_KEY"] = "key"
|
130 |
+
|
131 |
+
# Initialize Groq client
|
132 |
+
client = Groq(api_key=os.environ.get("key"))
|
133 |
+
|
134 |
+
# Carbon footprint reduction data (kg CO2 per kg recycled)
|
135 |
+
carbon_reduction_data = {
|
136 |
+
"Plastic Bottles": 3.8,
|
137 |
+
"Glass Bottles": 0.5,
|
138 |
+
"Metal Cans": 9.0,
|
139 |
+
"Old Clothes": 2.0,
|
140 |
+
"Paper and Cardboard": 1.3,
|
141 |
+
"E-Waste": 15.0,
|
142 |
+
"Tires": 8.0,
|
143 |
+
}
|
144 |
+
|
145 |
# Function to call Groq LLM
|
146 |
def get_recycling_suggestions_from_groq(item, quantity):
|
147 |
prompt = (
|
|
|
214 |
st.write(follow_up_response)
|
215 |
else:
|
216 |
st.error("Please enter a question.")
|
217 |
+
"""
|