Spaces:
Sleeping
Sleeping
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120import osimport streamlit as stfrom dotenv import load_dotenvimport google.generativeai as gen_ai# Load environment variablesload_dotenv()# Configure Streamlit page settingsst.set_page_config(page_title="Smart Waste Management System",page_icon="♻️",layout="centered",)# Retrieve the Google API key from the environmentGOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")# Check if the API key is loadedif 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 modeltry:gen_ai.configure(api_key=GOOGLE_API_KEY)model = gen_ai.GenerativeModel("gemini-1.5-pro") # Updated model versionexcept 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 stateif "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 titlest.title("♻️ Smart Waste Management System")# Back Button to Redirect to Dashboardst.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 instructionsst.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 selectionuser_role = st.selectbox("🔹 Select Your Role:", ["Citizen", "Municipal Worker", "Recycling Company", "Biogas Plant"])# Chat inputuser_prompt = st.chat_input(f"💬 [{user_role}] Enter your query or task...")if user_prompt:# Display the user's messagest.chat_message("user").markdown(f"**{user_role}:** {user_prompt}")# Generate a role-specific promptrole_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 responsetry:gemini_response = st.session_state.chat_session.send_message(role_specific_prompt)# Display Gemini-Pro's responsewith st.chat_message("assistant"):st.markdown(gemini_response.text)except Exception as e:st.error(f"❌ Error processing your message: {e}")# Sidebar Informationst.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!""")12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import streamlit as stimport numpy as npimport pandas as pdfrom sklearn.linear_model import LinearRegression# Streamlit page configst.set_page_config(page_title="BigMart Sales Predictor", page_icon="🛒", layout="centered")st.title("🛒 BigMart Sales Prediction")st.markdown("Enter item details below to predict sales:")# Input fieldsproject_name = st.text_input("📦 Project Name")item_weight = st.number_input("⚖️ Item Weight (kg)", min_value=0.0, step=0.1)item_visibility = st.slider("👀 Item Visibility", 0.0, 1.0, 0.1)item_mrp = st.number_input("💰 Item MRP (Max Retail Price)", min_value=0.0, step=1.0)# Predict buttonif st.button("Predict Sales"):if not project_name:st.warning("Please enter a project name.")else:# Dummy ML Model: Replace with your actual trained modelX_train = np.array([[9.3, 0.016, 249.8],[5.92, 0.019, 48.27],[17.5, 0.016, 141.62],[19.2, 0.0075, 182.095],])y_train = np.array([3735.14, 443.42, 2233.6, 3612.47]) # example salesmodel = LinearRegression()model.fit(X_train, y_train)# Prepare inputuser_input = np.array([[item_weight, item_visibility, item_mrp]])prediction = model.predict(user_input)[0]st.success(f"📈 Predicted Sales for '{project_name}': ₹{prediction:,.2f}")# Sidebar infost.sidebar.title("📌 About")st.sidebar.markdown("""This app uses a simple ML model to estimate sales based on:- Item weight- Item visibility- Item MRPReplace with a trained BigMart dataset model for production use.""")
app.py+45-113