File size: 3,744 Bytes
8f460b5
 
 
 
 
 
 
 
 
 
 
778f981
 
8f460b5
 
 
 
 
 
 
778f981
8f460b5
 
 
 
 
778f981
8f460b5
778f981
8f460b5
 
 
 
 
 
 
778f981
8f460b5
 
 
 
 
40c338c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f460b5
 
 
778f981
 
8f460b5
778f981
40c338c
 
 
 
8f460b5
 
 
778f981
 
 
 
 
8f460b5
 
778f981
8f460b5
 
778f981
 
8f460b5
 
 
 
778f981
8f460b5
 
 
778f981
8f460b5
778f981
8f460b5
778f981
 
8f460b5
 
40c338c
 
 
 
 
8f460b5
778f981
8f460b5
40c338c
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
import os
import streamlit as st
from dotenv import load_dotenv
import google.generativeai as gen_ai

# Load environment variables
load_dotenv()

# Configure Streamlit page settings
st.set_page_config(
    page_title="Smart Waste Management System",
    page_icon="♻️",
    layout="centered",
)

# Retrieve the Google API key from the environment
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")

# Check if the API key is loaded
if not GOOGLE_API_KEY:
    st.error("🚨 API key not found! Please set the GOOGLE_API_KEY in your .env file.")
    st.stop()

# Configure the Generative AI model
try:
    gen_ai.configure(api_key=GOOGLE_API_KEY)
    model = gen_ai.GenerativeModel("gemini-1.5-pro")  # Updated model version
except Exception as e:
    st.error(f"❌ Error initializing the Gemini-Pro model: {e}")
    st.stop()

# Initialize the chat session if not already present in session state
if "chat_session" not in st.session_state:
    try:
        st.session_state.chat_session = model.start_chat(history=[])
    except Exception as e:
        st.error(f"❌ Error initializing chat session: {e}")
        st.stop()

# Display the app's title
st.title("♻️ Smart Waste Management System")

# Back Button to Redirect to Dashboard
st.markdown(
    """
    <style>
        .back-button {
            display: flex;
            justify-content: center;
            padding: 10px;
        }
        .btn {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            text-align: center;
            text-decoration: none;
            font-size: 16px;
            border-radius: 5px;
            display: inline-block;
        }
    </style>
    <div class="back-button">
        <a href="https://binsight.onrender.com/dashboard.html" class="btn">🔙 Back to Dashboard</a>
    </div>
    """,
    unsafe_allow_html=True,
)

# Introduction and instructions
st.markdown(
    """
    Welcome to the **Smart Waste Management System**! This tool helps **citizens, municipal workers, 
    recycling companies, and biogas plants** collaborate efficiently for **better waste management**.

    ### **🌟 Key Features**
    - 🏡 **Improve waste collection efficiency** for citizens.
    - 🚛 **Help municipal workers** manage schedules.
    - 🔄 **Assist recycling companies** in waste processing.
    - ⚡ **Support biogas plants** in energy production.
    """
)

# User role selection
user_role = st.selectbox("🔹 Select Your Role:", ["Citizen", "Municipal Worker", "Recycling Company", "Biogas Plant"])

# Chat input
user_prompt = st.chat_input(f"💬 [{user_role}] Enter your query or task...")

if user_prompt:
    # Display the user's message
    st.chat_message("user").markdown(f"**{user_role}:** {user_prompt}")

    # Generate a role-specific prompt
    role_specific_prompt = f"You are assisting a {user_role} in a smart waste management system. The user says: {user_prompt}"

    # Send the prompt to Gemini-Pro and get the response
    try:
        gemini_response = st.session_state.chat_session.send_message(role_specific_prompt)

        # Display Gemini-Pro's response
        with st.chat_message("assistant"):
            st.markdown(gemini_response.text)

    except Exception as e:
        st.error(f"❌ Error processing your message: {e}")

# Sidebar Information
st.sidebar.title("📌 About")
st.sidebar.markdown(
    """
    **The Smart Waste Management System aims to:**
    - 🏡 Improve waste collection efficiency for citizens.
    - 🚛 Help municipal workers manage schedules.
    - 🔄 Assist recycling companies in waste processing.
    - ⚡ Support biogas plants in energy production.

    💡 **Need Help?** Use the chat to ask questions!
    """
)