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( """ """, 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.") """