|
import os |
|
import streamlit as st |
|
from dotenv import load_dotenv |
|
import google.generativeai as gen_ai |
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
st.set_page_config( |
|
page_title="Smart Waste Management System", |
|
page_icon="♻️", |
|
layout="centered", |
|
) |
|
|
|
|
|
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY") |
|
|
|
|
|
if not GOOGLE_API_KEY: |
|
st.error("🚨 API key not found! Please set the GOOGLE_API_KEY in your .env file.") |
|
st.stop() |
|
|
|
|
|
try: |
|
gen_ai.configure(api_key=GOOGLE_API_KEY) |
|
model = gen_ai.GenerativeModel("gemini-1.5-pro") |
|
except Exception as e: |
|
st.error(f"❌ Error initializing the Gemini-Pro model: {e}") |
|
st.stop() |
|
|
|
|
|
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() |
|
|
|
|
|
st.title("♻️ Smart Waste Management System") |
|
|
|
|
|
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, |
|
) |
|
|
|
|
|
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 = st.selectbox("🔹 Select Your Role:", ["Citizen", "Municipal Worker", "Recycling Company", "Biogas Plant"]) |
|
|
|
|
|
user_prompt = st.chat_input(f"💬 [{user_role}] Enter your query or task...") |
|
|
|
if user_prompt: |
|
|
|
st.chat_message("user").markdown(f"**{user_role}:** {user_prompt}") |
|
|
|
|
|
role_specific_prompt = f"You are assisting a {user_role} in a smart waste management system. The user says: {user_prompt}" |
|
|
|
|
|
try: |
|
gemini_response = st.session_state.chat_session.send_message(role_specific_prompt) |
|
|
|
|
|
with st.chat_message("assistant"): |
|
st.markdown(gemini_response.text) |
|
|
|
except Exception as e: |
|
st.error(f"❌ Error processing your message: {e}") |
|
|
|
|
|
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! |
|
""" |
|
) |
|
|