Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| import random | |
| # Load the DistilGPT-2 model for text generation | |
| model = pipeline("text-generation", model="distilgpt2") | |
| def get_recycling_advice(product): | |
| # Crafting a specific prompt for generating recycling advice | |
| prompt = (f"As an environmental expert, provide detailed, actionable steps on how to recycle or " | |
| f"properly dispose of the following product: '{product}'. " | |
| "Include methods, potential hazards, and any specific recycling processes.") | |
| # Generate the response from the model | |
| response = model(prompt, max_length=150, num_return_sequences=1) | |
| return response[0]['generated_text'].strip() | |
| # List of daily sustainability tips | |
| SUSTAINABILITY_TIPS = [ | |
| "Reduce single-use plastics by opting for reusable bags and containers.", | |
| "Compost your kitchen waste to create nutrient-rich soil for gardening.", | |
| "Choose energy-efficient appliances to reduce electricity consumption.", | |
| "Always carry a reusable water bottle to minimize plastic waste.", | |
| "Participate in local clean-up events to contribute to your community's cleanliness.", | |
| ] | |
| # Get a random sustainability tip | |
| daily_tip = random.choice(SUSTAINABILITY_TIPS) | |
| # Streamlit UI | |
| st.title("Recycling Advisor") | |
| st.subheader("Get expert advice on how to recycle or dispose of your products!") | |
| product = st.text_input("Enter a product you'd like to recycle:") | |
| if st.button("Get Advice"): | |
| if product: | |
| advice = get_recycling_advice(product) | |
| st.write(advice) | |
| else: | |
| st.error("Please enter a product name.") | |
| # Additional features for a better user experience | |
| st.sidebar.title("About") | |
| st.sidebar.info("This application provides actionable suggestions on how to recycle and dispose of various products, promoting environmental sustainability.") | |
| st.sidebar.subheader("Recycling Resources:") | |
| st.sidebar.write("For proper recycling and disposal of waste, refer to the following resources:") | |
| st.sidebar.write("[India: Central Pollution Control Board (CPCB)](https://cpcb.nic.in/recycling-and-disposal-of-waste/)") | |
| st.sidebar.write("[Pakistan: Pakistan Environmental Protection Agency](http://www.environment.gov.pk/)") | |
| st.sidebar.write("[Bangladesh: Department of Environment](http://www.doe.gov.bd/)") | |
| st.sidebar.write("[USA: Environmental Protection Agency (EPA)](https://www.epa.gov/recycle)") | |
| st.sidebar.write("[UK: Recycle Now](https://www.recyclenow.com/)") | |
| st.sidebar.write("[Canada: Government of Canada - Recycling](https://www.canada.ca/en/services/environment/conservation/recycling.html)") | |
| st.sidebar.write("[Germany: Federal Ministry for the Environment](https://www.bmu.de/en/topics/water-waste-soil/waste-management/recycling/)") | |
| st.sidebar.write("[China: National Development and Reform Commission](http://en.ndrc.gov.cn/)") | |
| st.sidebar.write("[Japan: Ministry of the Environment](https://www.env.go.jp/en/recycle/)") | |
| st.sidebar.subheader("Daily Sustainability Tip:") | |
| st.sidebar.write(daily_tip) |