MLDeveloper commited on
Commit
d481617
·
verified ·
1 Parent(s): 40c338c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -113
app.py CHANGED
@@ -1,120 +1,52 @@
1
- import os
2
  import streamlit as st
3
- from dotenv import load_dotenv
4
- import google.generativeai as gen_ai
5
-
6
- # Load environment variables
7
- load_dotenv()
8
-
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
17
- 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-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
41
- st.title("♻️ Smart Waste Management System")
42
-
43
- # Back Button to Redirect to Dashboard
44
- st.markdown(
45
- """
46
- <style>
47
- .back-button {
48
- display: flex;
49
- justify-content: center;
50
- padding: 10px;
51
- }
52
- .btn {
53
- background-color: #4CAF50;
54
- color: white;
55
- padding: 10px 20px;
56
- text-align: center;
57
- text-decoration: none;
58
- font-size: 16px;
59
- border-radius: 5px;
60
- display: inline-block;
61
- }
62
- </style>
63
- <div class="back-button">
64
- <a href="https://binsight.onrender.com/dashboard.html" class="btn">🔙 Back to Dashboard</a>
65
- </div>
66
- """,
67
- unsafe_allow_html=True,
68
- )
69
-
70
- # Introduction and instructions
71
- st.markdown(
72
- """
73
- Welcome to the **Smart Waste Management System**! This tool helps **citizens, municipal workers,
74
- recycling companies, and biogas plants** collaborate efficiently for **better waste management**.
75
-
76
- ### **🌟 Key Features**
77
- - 🏡 **Improve waste collection efficiency** for citizens.
78
- - 🚛 **Help municipal workers** manage schedules.
79
- - 🔄 **Assist recycling companies** in waste processing.
80
- - ⚡ **Support biogas plants** in energy production.
81
- """
82
- )
83
-
84
- # User role selection
85
- user_role = st.selectbox("🔹 Select Your Role:", ["Citizen", "Municipal Worker", "Recycling Company", "Biogas Plant"])
86
-
87
- # Chat input
88
- user_prompt = st.chat_input(f"💬 [{user_role}] Enter your query or task...")
89
-
90
- if user_prompt:
91
- # Display the user's message
92
- st.chat_message("user").markdown(f"**{user_role}:** {user_prompt}")
93
-
94
- # Generate a role-specific prompt
95
- role_specific_prompt = f"You are assisting a {user_role} in a smart waste management system. The user says: {user_prompt}"
96
-
97
- # Send the prompt to Gemini-Pro and get the response
98
- try:
99
- gemini_response = st.session_state.chat_session.send_message(role_specific_prompt)
100
-
101
- # Display Gemini-Pro's response
102
- with st.chat_message("assistant"):
103
- st.markdown(gemini_response.text)
104
-
105
- except Exception as e:
106
- st.error(f"❌ Error processing your message: {e}")
107
-
108
- # Sidebar Information
109
  st.sidebar.title("📌 About")
110
  st.sidebar.markdown(
111
  """
112
- **The Smart Waste Management System aims to:**
113
- - 🏡 Improve waste collection efficiency for citizens.
114
- - 🚛 Help municipal workers manage schedules.
115
- - 🔄 Assist recycling companies in waste processing.
116
- - ⚡ Support biogas plants in energy production.
117
 
118
- 💡 **Need Help?** Use the chat to ask questions!
119
  """
120
  )
 
 
1
  import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ from sklearn.linear_model import LinearRegression
5
+
6
+ # Streamlit page config
7
+ st.set_page_config(page_title="BigMart Sales Predictor", page_icon="🛒", layout="centered")
8
+
9
+ st.title("🛒 BigMart Sales Prediction")
10
+ st.markdown("Enter item details below to predict sales:")
11
+
12
+ # Input fields
13
+ project_name = st.text_input("📦 Project Name")
14
+ item_weight = st.number_input("⚖️ Item Weight (kg)", min_value=0.0, step=0.1)
15
+ item_visibility = st.slider("👀 Item Visibility", 0.0, 1.0, 0.1)
16
+ item_mrp = st.number_input("💰 Item MRP (Max Retail Price)", min_value=0.0, step=1.0)
17
+
18
+ # Predict button
19
+ if st.button("Predict Sales"):
20
+ if not project_name:
21
+ st.warning("Please enter a project name.")
22
+ else:
23
+ # Dummy ML Model: Replace with your actual trained model
24
+ X_train = np.array([
25
+ [9.3, 0.016, 249.8],
26
+ [5.92, 0.019, 48.27],
27
+ [17.5, 0.016, 141.62],
28
+ [19.2, 0.0075, 182.095],
29
+ ])
30
+ y_train = np.array([3735.14, 443.42, 2233.6, 3612.47]) # example sales
31
+
32
+ model = LinearRegression()
33
+ model.fit(X_train, y_train)
34
+
35
+ # Prepare input
36
+ user_input = np.array([[item_weight, item_visibility, item_mrp]])
37
+ prediction = model.predict(user_input)[0]
38
+
39
+ st.success(f"📈 Predicted Sales for '{project_name}': ₹{prediction:,.2f}")
40
+
41
+ # Sidebar info
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  st.sidebar.title("📌 About")
43
  st.sidebar.markdown(
44
  """
45
+ This app uses a simple ML model to estimate sales based on:
46
+ - Item weight
47
+ - Item visibility
48
+ - Item MRP
 
49
 
50
+ Replace with a trained BigMart dataset model for production use.
51
  """
52
  )