Update app.py
Browse files
app.py
CHANGED
|
@@ -9,8 +9,8 @@ load_dotenv()
|
|
| 9 |
# Configure Streamlit page settings
|
| 10 |
st.set_page_config(
|
| 11 |
page_title="Smart Waste Management System",
|
| 12 |
-
page_icon="
|
| 13 |
-
layout="centered",
|
| 14 |
)
|
| 15 |
|
| 16 |
# Retrieve the Google API key from the environment
|
|
@@ -18,27 +18,23 @@ GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
|
| 18 |
|
| 19 |
# Check if the API key is loaded
|
| 20 |
if not GOOGLE_API_KEY:
|
| 21 |
-
st.error("API key not found! Please set the GOOGLE_API_KEY in your .env file.")
|
| 22 |
st.stop()
|
| 23 |
|
| 24 |
# Configure the Generative AI model
|
| 25 |
try:
|
| 26 |
gen_ai.configure(api_key=GOOGLE_API_KEY)
|
| 27 |
-
model = gen_ai.GenerativeModel("gemini-pro")
|
| 28 |
except Exception as e:
|
| 29 |
-
st.error(f"Error initializing the Gemini-Pro model: {e}")
|
| 30 |
st.stop()
|
| 31 |
|
| 32 |
-
# Function to translate roles between Gemini-Pro and Streamlit terminology
|
| 33 |
-
def translate_role_for_streamlit(user_role):
|
| 34 |
-
return "assistant" if user_role == "model" else user_role
|
| 35 |
-
|
| 36 |
# Initialize the chat session if not already present in session state
|
| 37 |
if "chat_session" not in st.session_state:
|
| 38 |
try:
|
| 39 |
st.session_state.chat_session = model.start_chat(history=[])
|
| 40 |
except Exception as e:
|
| 41 |
-
st.error(f"Error initializing chat session: {e}")
|
| 42 |
st.stop()
|
| 43 |
|
| 44 |
# Display the app's title
|
|
@@ -47,10 +43,10 @@ st.title("♻️ Smart Waste Management System")
|
|
| 47 |
# Introduction and instructions
|
| 48 |
st.markdown(
|
| 49 |
"""
|
| 50 |
-
Welcome to the Smart Waste Management System
|
| 51 |
-
recycling companies, and biogas plants collaborate efficiently for
|
| 52 |
|
| 53 |
-
|
| 54 |
- **Citizen Role:** Report waste collection issues and track garbage pickup.
|
| 55 |
- **Municipal Workers:** Manage schedules and coordinate garbage segregation.
|
| 56 |
- **Recycling Companies:** View and respond to requests for plastic waste.
|
|
@@ -58,37 +54,40 @@ st.markdown(
|
|
| 58 |
"""
|
| 59 |
)
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
user_role = st.selectbox("Select Your Role:", ["Citizen", "Municipal Worker", "Recycling Company", "Biogas Plant"])
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
user_prompt = st.chat_input(f"[{user_role}] Enter your query or task...")
|
| 65 |
if user_prompt:
|
| 66 |
-
#
|
| 67 |
st.chat_message("user").markdown(f"**{user_role}:** {user_prompt}")
|
| 68 |
|
| 69 |
-
#
|
| 70 |
-
role_specific_prompt =
|
| 71 |
-
f"You are assisting a {user_role} in a waste management system. The user says: {user_prompt}"
|
| 72 |
-
)
|
| 73 |
|
| 74 |
# Send the prompt to Gemini-Pro and get the response
|
| 75 |
try:
|
| 76 |
gemini_response = st.session_state.chat_session.send_message(role_specific_prompt)
|
|
|
|
| 77 |
# Display Gemini-Pro's response
|
| 78 |
with st.chat_message("assistant"):
|
| 79 |
st.markdown(gemini_response.text)
|
|
|
|
| 80 |
except Exception as e:
|
| 81 |
-
st.error(f"Error processing your message: {e}")
|
| 82 |
|
| 83 |
-
#
|
| 84 |
-
st.sidebar.title("About")
|
| 85 |
st.sidebar.markdown(
|
| 86 |
"""
|
| 87 |
The **Smart Waste Management System** aims to:
|
| 88 |
-
-
|
| 89 |
-
-
|
| 90 |
-
-
|
|
|
|
| 91 |
|
| 92 |
-
**Need Help?** Use the chat to ask questions
|
| 93 |
"""
|
| 94 |
-
)
|
|
|
|
| 9 |
# Configure Streamlit page settings
|
| 10 |
st.set_page_config(
|
| 11 |
page_title="Smart Waste Management System",
|
| 12 |
+
page_icon="♻️",
|
| 13 |
+
layout="centered",
|
| 14 |
)
|
| 15 |
|
| 16 |
# Retrieve the Google API key from the environment
|
|
|
|
| 18 |
|
| 19 |
# Check if the API key is loaded
|
| 20 |
if not GOOGLE_API_KEY:
|
| 21 |
+
st.error("🚨 API key not found! Please set the GOOGLE_API_KEY in your .env file.")
|
| 22 |
st.stop()
|
| 23 |
|
| 24 |
# Configure the Generative AI model
|
| 25 |
try:
|
| 26 |
gen_ai.configure(api_key=GOOGLE_API_KEY)
|
| 27 |
+
model = gen_ai.GenerativeModel("gemini-1.5-pro") # Updated model version
|
| 28 |
except Exception as e:
|
| 29 |
+
st.error(f"❌ Error initializing the Gemini-Pro model: {e}")
|
| 30 |
st.stop()
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# Initialize the chat session if not already present in session state
|
| 33 |
if "chat_session" not in st.session_state:
|
| 34 |
try:
|
| 35 |
st.session_state.chat_session = model.start_chat(history=[])
|
| 36 |
except Exception as e:
|
| 37 |
+
st.error(f"❌ Error initializing chat session: {e}")
|
| 38 |
st.stop()
|
| 39 |
|
| 40 |
# Display the app's title
|
|
|
|
| 43 |
# Introduction and instructions
|
| 44 |
st.markdown(
|
| 45 |
"""
|
| 46 |
+
Welcome to the **Smart Waste Management System**! This tool helps **citizens, municipal workers,
|
| 47 |
+
recycling companies, and biogas plants** collaborate efficiently for **better waste management**.
|
| 48 |
|
| 49 |
+
### **🌟 Key Features**
|
| 50 |
- **Citizen Role:** Report waste collection issues and track garbage pickup.
|
| 51 |
- **Municipal Workers:** Manage schedules and coordinate garbage segregation.
|
| 52 |
- **Recycling Companies:** View and respond to requests for plastic waste.
|
|
|
|
| 54 |
"""
|
| 55 |
)
|
| 56 |
|
| 57 |
+
# User role selection
|
| 58 |
+
user_role = st.selectbox("🔹 Select Your Role:", ["Citizen", "Municipal Worker", "Recycling Company", "Biogas Plant"])
|
| 59 |
+
|
| 60 |
+
# Chat input
|
| 61 |
+
user_prompt = st.chat_input(f"💬 [{user_role}] Enter your query or task...")
|
| 62 |
|
|
|
|
| 63 |
if user_prompt:
|
| 64 |
+
# Display the user's message
|
| 65 |
st.chat_message("user").markdown(f"**{user_role}:** {user_prompt}")
|
| 66 |
|
| 67 |
+
# Generate a role-specific prompt
|
| 68 |
+
role_specific_prompt = f"You are assisting a {user_role} in a smart waste management system. The user says: {user_prompt}"
|
|
|
|
|
|
|
| 69 |
|
| 70 |
# Send the prompt to Gemini-Pro and get the response
|
| 71 |
try:
|
| 72 |
gemini_response = st.session_state.chat_session.send_message(role_specific_prompt)
|
| 73 |
+
|
| 74 |
# Display Gemini-Pro's response
|
| 75 |
with st.chat_message("assistant"):
|
| 76 |
st.markdown(gemini_response.text)
|
| 77 |
+
|
| 78 |
except Exception as e:
|
| 79 |
+
st.error(f"❌ Error processing your message: {e}")
|
| 80 |
|
| 81 |
+
# Sidebar Information
|
| 82 |
+
st.sidebar.title("📌 About")
|
| 83 |
st.sidebar.markdown(
|
| 84 |
"""
|
| 85 |
The **Smart Waste Management System** aims to:
|
| 86 |
+
- 🏡 **Improve waste collection efficiency** for citizens.
|
| 87 |
+
- 🚛 **Help municipal workers** manage schedules.
|
| 88 |
+
- 🔄 **Assist recycling companies** in waste processing.
|
| 89 |
+
- ⚡ **Support biogas plants** in energy production.
|
| 90 |
|
| 91 |
+
💡 **Need Help?** Use the chat to ask questions!
|
| 92 |
"""
|
| 93 |
+
)
|