File size: 6,998 Bytes
23eb8aa
 
 
 
 
f1f08fd
23eb8aa
 
f1f08fd
23eb8aa
 
 
 
 
 
 
 
 
 
 
 
f1f08fd
49b3888
 
 
 
f1f08fd
49b3888
 
 
 
 
 
 
 
f1f08fd
49b3888
 
 
 
 
 
6d6075d
f1f08fd
6d6075d
e61851e
3ff9818
 
e61851e
6d6075d
 
49b3888
6d6075d
 
e61851e
6d6075d
 
3ff9818
 
 
 
6d6075d
 
3ff9818
49b3888
6d6075d
 
 
 
 
 
49b3888
6d6075d
49b3888
 
 
 
 
 
6d6075d
 
 
 
 
 
 
49b3888
 
 
 
 
 
 
 
 
 
6d6075d
 
49b3888
6d6075d
49b3888
 
 
6d6075d
 
 
 
 
 
 
e61851e
6d6075d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23eb8aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d6075d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import os
import streamlit as st
from groq import Groq

# Set the Groq API key
os.environ["GROQ_API_KEY"] = "key"

# Initialize Groq client
client = Groq(api_key=os.environ.get("key"))

# Carbon footprint reduction data (kg CO2 per kg recycled)
carbon_reduction_data = {
    "Plastic Bottles": 3.8,
    "Glass Bottles": 0.5,
    "Metal Cans": 9.0,
    "Old Clothes": 2.0,
    "Paper and Cardboard": 1.3,
    "E-Waste": 15.0,
    "Tires": 8.0,
}

# Custom CSS for colors and layout
st.markdown(
    """
    <style>
    body {
        background-color: #f5f5f5;
    }
    .main {
        background-color: #ffffff;
        border-radius: 10px;
        padding: 20px;
        color: #333333;
    }
    .sidebar .sidebar-content {
        background-color: #dceefb;
        border-radius: 10px;
    }
    </style>
    """,
    unsafe_allow_html=True,
)

# Sidebar for navigation
st.sidebar.title("🌍 RecycleSmart-PK")
st.sidebar.image(
    "https://via.placeholder.com/300x200?text=RecycleSmart+Logo",
    use_container_width=True,
)
st.sidebar.markdown("### Navigation")
section = st.sidebar.radio(
    "Choose a section:", ["Home", "Recycle Suggestions"]
)

# Main Content
if section == "Home":
    st.title("♻️ Welcome to RecycleSmart-PK!")
    st.image(
        "https://via.placeholder.com/800x400?text=Recycle+Smartly%2C+Save+Our+Planet",
        use_container_width=True,
    )
    st.markdown(
        """
        RecycleSmart-PK helps you turn waste into opportunities while reducing your carbon footprint.  
        Navigate to **Recycle Suggestions** to start recycling smartly!
        """
    )

elif section == "Recycle Suggestions":
    st.title("πŸ’‘ Recycling Suggestions")
    selected_items = st.multiselect(
        "Select items to recycle:", list(carbon_reduction_data.keys())
    )
    quantities = {
        item: st.number_input(
            f"Enter quantity for {item} (in kg):", min_value=0, step=1
        )
        for item in selected_items
    }

    if st.button("Get Suggestions"):
        if selected_items:
            total_carbon_reduction = 0
            st.write("### ♻️ Suggestions and Impact:")
            for item, quantity in quantities.items():
                if quantity > 0:
                    prompt = (
                        f"Suggest profitable and eco-friendly uses for {quantity} kg of {item}, "
                        f"including household uses and ways to monetize them."
                    )
                    chat_completion = client.chat.completions.create(
                        messages=[{"role": "user", "content": prompt}],
                        model="llama-3.3-70b-versatile",
                        stream=False,
                    )
                    llm_response = chat_completion.choices[0].message.content
                    carbon_reduction = carbon_reduction_data.get(item, 0) * quantity
                    total_carbon_reduction += carbon_reduction
                    st.write(f"**{item} ({quantity} kg)**")
                    st.write(f"πŸ’‘ {llm_response}")
                    st.write(
                        f"🌍 **Carbon Footprint Reduction**: {carbon_reduction:.2f} kg COβ‚‚"
                    )
                    st.markdown("---")
            st.write("### 🌟 Total Carbon Footprint Reduction 🌟")
            st.write(f"🌍 **{total_carbon_reduction:.2f} kg COβ‚‚ saved**")
            st.success("πŸŽ‰ Great job contributing to a greener planet!")
        else:
            st.error("❗ Please select at least one item and specify its quantity.")






"""
import os
import streamlit as st
from groq import Groq

# Set the Groq API key
os.environ["GROQ_API_KEY"] = "key"

# Initialize Groq client
client = Groq(api_key=os.environ.get("key"))

# Carbon footprint reduction data (kg CO2 per kg recycled)
carbon_reduction_data = {
    "Plastic Bottles": 3.8,
    "Glass Bottles": 0.5,
    "Metal Cans": 9.0,
    "Old Clothes": 2.0,
    "Paper and Cardboard": 1.3,
    "E-Waste": 15.0,
    "Tires": 8.0,
}

# Function to call Groq LLM
def get_recycling_suggestions_from_groq(item, quantity):
    prompt = (
        f"You are an expert in recycling and sustainability. "
        f"Suggest profitable and eco-friendly uses for {quantity} kg of {item}, "
        f"including household uses, ways to monetize them, and calculate carbon footprint reduction."
    )
    chat_completion = client.chat.completions.create(
        messages=[{"role": "user", "content": prompt}],
        model="llama-3.3-70b-versatile",
        stream=False,
    )
    return chat_completion.choices[0].message.content

# App title
st.title("♻️ Recycle with Groq LLM 🌍")
st.write("Select clutter items, specify quantities, and get tailored, profitable recycling suggestions along with carbon footprint reduction scores!")

# Multi-select input for clutter items
selected_items = st.multiselect(
    "Select items to recycle:",
    list(carbon_reduction_data.keys())
)

# Quantity input for selected items
quantities = {}
for item in selected_items:
    quantities[item] = st.number_input(
        f"Enter quantity for {item} (in kg):", min_value=0, step=1
    )

# Process and display results
if st.button("Get Recycling Suggestions"):
    if selected_items:
        total_carbon_reduction = 0
        st.write("### ♻️ Recycling Suggestions and Impact:")
        for item, quantity in quantities.items():
            if quantity > 0:
                # Call Groq LLM for dynamic suggestions
                llm_response = get_recycling_suggestions_from_groq(item, quantity)

                # Fetch carbon footprint reduction
                carbon_reduction = carbon_reduction_data.get(item, 0) * quantity
                total_carbon_reduction += carbon_reduction

                # Display results for each item
                st.write(f"**{item} ({quantity} kg)**")
                st.write(llm_response)
                st.write(f"🌍 **Carbon Footprint Reduction**: {carbon_reduction:.2f} kg COβ‚‚")
                st.write("---")

        # Display total carbon footprint reduction credit score
        st.write("### 🌟 Your Total Carbon Footprint Reduction 🌟")
        st.write(f"🌍 **{total_carbon_reduction:.2f} kg COβ‚‚ saved**")
        st.success("Great job contributing to a greener planet! πŸŒ±πŸ’š")
    else:
        st.error("Please select at least one item and specify its quantity.")

# Follow-up Q&A with Groq LLM
st.write("### πŸ€” Have more questions about recycling?")
user_query = st.text_input("Ask the Groq LLM about recycling:")
if st.button("Ask Groq"):
    if user_query:
        follow_up_response = client.chat.completions.create(
            messages=[{"role": "user", "content": user_query}],
            model="llama-3.3-70b-versatile",
            stream=False,
        ).choices[0].message.content
        st.write("### 🧠 Groq LLM's Answer:")
        st.write(follow_up_response)
    else:
        st.error("Please enter a question.")
        """