Krish-Upgrix commited on
Commit
9a8f12c
·
verified ·
1 Parent(s): 51123b0

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +339 -0
  2. firebase_credentials.json +13 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,339 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import firebase_admin
3
+ from firebase_admin import credentials, db
4
+
5
+ # Initialize Firebase
6
+ if not firebase_admin._apps:
7
+ cred = credentials.Certificate("firebase_credentials.json")
8
+ firebase_admin.initialize_app(cred, {
9
+ 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
10
+ })
11
+
12
+ # Streamlit Dashboard
13
+ st.title("Binsight Admin Dashboard")
14
+ st.sidebar.header("Filters")
15
+
16
+ filter_status = st.sidebar.selectbox("Filter by Status", ["All", "Pending", "Allocated", "Completed"], index=0)
17
+
18
+ dustbins_ref = db.reference("dustbins")
19
+ dustbins = dustbins_ref.get() or {}
20
+
21
+ filtered_dustbins = {
22
+ key: value for key, value in dustbins.items()
23
+ if filter_status == "All" or value["status"] == filter_status
24
+ }
25
+
26
+ st.subheader(f"Showing {filter_status.lower()} dustbins ({len(filtered_dustbins)})")
27
+
28
+ for key, value in filtered_dustbins.items():
29
+ with st.expander(f"📍 {value['address']}"):
30
+ st.write(f"**Latitude**: {value['latitude']}")
31
+ st.write(f"**Longitude**: {value['longitude']}")
32
+ st.write(f"**Status**: {value['status']}")
33
+ st.write(f"**User**: {value['user_email']}")
34
+ if value["status"] == "Pending":
35
+ truck_email = st.text_input(f"Allocate Truck Email for {key}", key=f"truck_{key}")
36
+ if st.button(f"Allocate Truck", key=f"allocate_{key}"):
37
+ if truck_email:
38
+ dustbins_ref.child(key).update({
39
+ "allocated_truck": truck_email,
40
+ "status": "Allocated"
41
+ })
42
+ st.success("Truck allocated successfully!")
43
+ else:
44
+ st.error("Please enter a valid truck email.")
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+ # import streamlit as st
55
+ # import firebase_admin
56
+ # from firebase_admin import credentials, db
57
+ # import requests
58
+ # from datetime import datetime
59
+
60
+ # # Initialize Firebase
61
+ # if not firebase_admin._apps:
62
+ # cred = credentials.Certificate("firebase_credentials.json") # Path to your Firebase JSON
63
+ # firebase_admin.initialize_app(cred, {
64
+ # 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/' # Replace with your Firebase Realtime Database URL
65
+ # })
66
+
67
+ # # Function to send email using Mailgun
68
+ # def send_email(recipient_email, subject, message):
69
+ # MAILGUN_API_KEY = "9530f415a53e78317892af32cf3c4b93-79295dd0-b3f02e29"
70
+ # MAILGUN_DOMAIN = "sandboxb2e22240ec8a4b468825577fcb967a85.mailgun.org"
71
+
72
+ # response = requests.post(
73
+ # f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN}/messages",
74
+ # auth=("api", MAILGUN_API_KEY),
75
+ # data={
76
+ # "from": f"Binsight Admin <mailgun@{MAILGUN_DOMAIN}>",
77
+ # "to": recipient_email,
78
+ # "subject": subject,
79
+ # "text": message,
80
+ # },
81
+ # )
82
+ # return response.status_code == 200
83
+
84
+ # # Streamlit Dashboard
85
+ # st.title("Binsight Admin Dashboard")
86
+ # st.sidebar.header("Filters")
87
+
88
+ # # Filter status
89
+ # filter_status = st.sidebar.selectbox("Filter by Status", ["All", "Pending", "Allocated", "Completed"], index=0)
90
+
91
+ # # Firebase Reference
92
+ # dustbins_ref = db.reference("dustbins")
93
+ # dustbins = dustbins_ref.get()
94
+
95
+ # # Filter dustbins
96
+ # if dustbins:
97
+ # filtered_dustbins = {
98
+ # key: value
99
+ # for key, value in dustbins.items()
100
+ # if filter_status == "All" or value["status"] == filter_status
101
+ # }
102
+ # else:
103
+ # filtered_dustbins = {}
104
+
105
+ # if filtered_dustbins:
106
+ # st.subheader(f"Showing {filter_status.lower()} dustbins ({len(filtered_dustbins)})")
107
+
108
+ # for key, value in filtered_dustbins.items():
109
+ # with st.expander(f"📍 Dustbin at {value['address']}"):
110
+ # st.write(f"**Latitude**: {value['latitude']}")
111
+ # st.write(f"**Longitude**: {value['longitude']}")
112
+ # st.write(f"**Classification**: {', '.join([f'{k} ({v:.2f})' for k, v in value['classification'].items()])}")
113
+ # st.write(f"**Status**: {value['status']}")
114
+
115
+ # if value["status"] == "Completed":
116
+ # st.write(f"**Completed By**: {value['completed_by']}")
117
+ # st.write(f"**Completed At**: {value.get('completed_at', 'N/A')}")
118
+
119
+ # # Send Thank-You Email
120
+ # user_email = st.text_input("User Email", key=f"user_email_{key}")
121
+ # if st.button("Send Thank-You Email", key=f"thank_you_{key}"):
122
+ # if user_email:
123
+ # subject = "Binsight - Thank You!"
124
+ # message = f"Dear User,\n\nThank you for providing dustbin details! The dustbin at {value['address']} has been cleaned successfully.\n\nBest regards,\nBinsight Team"
125
+ # email_sent = send_email(user_email, subject, message)
126
+ # if email_sent:
127
+ # st.success("Thank-you email sent successfully!")
128
+ # else:
129
+ # st.error("Failed to send email. Please check Mailgun credentials.")
130
+ # else:
131
+ # st.error("Please enter a valid user email.")
132
+ # else:
133
+ # st.info(f"No dustbins found for the selected status: {filter_status}.")
134
+
135
+ # # About Section
136
+ # st.sidebar.write("---")
137
+ # st.sidebar.write("👨‍💻 **Developed by Binsight Team**")
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+ # working best without firebase
153
+
154
+ # import streamlit as st
155
+ # import pandas as pd
156
+ # import requests
157
+
158
+ # # Function to send email using Mailgun API
159
+ # def send_email(driver_email, longitude, latitude, location):
160
+ # MAILGUN_API_KEY = "9530f415a53e78317892af32cf3c4b93-79295dd0-b3f02e29"
161
+ # MAILGUN_DOMAIN = "sandboxb2e22240ec8a4b468825577fcb967a85.mailgun.org"
162
+
163
+ # response = requests.post(
164
+ # f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN}/messages",
165
+ # auth=("api", MAILGUN_API_KEY),
166
+ # data={
167
+ # "from": f"Binsight Admin <mailgun@{MAILGUN_DOMAIN}>",
168
+ # "to": driver_email,
169
+ # "subject": "Truck Allocation Details",
170
+ # "text": f"Dear Driver,\n\nYou have been allocated to a new dustbin location. Here are the details:\n\nLongitude: {longitude}\nLatitude: {latitude}\nLocation: {location}\n\nThank you,\nBinsight Team",
171
+ # },
172
+ # )
173
+
174
+ # if response.status_code == 200:
175
+ # st.success(f"Email sent successfully to {driver_email}!")
176
+ # else:
177
+ # st.error(f"Failed to send email: {response.text}")
178
+
179
+ # # Streamlit app configuration
180
+ # st.set_page_config(page_title="Binsight Admin Dashboard", layout="wide")
181
+
182
+ # # App title
183
+ # st.title("Binsight Admin Dashboard")
184
+
185
+ # # Dummy data for the dashboard (replace this with your database or API connection)
186
+ # data = [
187
+ # {"Truck No": "TR001", "Driver Name": "Krishna K", "Driver Number": "1234567890", "Driver Email": "krishnaproject23@gmail.com"},
188
+ # {"Truck No": "TR002", "Driver Name": "Jane Smith", "Driver Number": "0987654321", "Driver Email": "jane@example.com"},
189
+ # {"Truck No": "TR003", "Driver Name": "Mike Ross", "Driver Number": "1122334455", "Driver Email": "mike@example.com"},
190
+ # ]
191
+
192
+ # df = pd.DataFrame(data)
193
+
194
+ # # Initialize session state for truck allocation details
195
+ # if "allocation_details" not in st.session_state:
196
+ # st.session_state["allocation_details"] = {}
197
+
198
+ # # Display the data in a tabular format
199
+ # st.subheader("Truck and Driver Details")
200
+ # for index, row in df.iterrows():
201
+ # col1, col2, col3, col4, col5 = st.columns([1, 2, 2, 3, 2])
202
+
203
+ # with col1:
204
+ # st.write(row["Truck No"])
205
+
206
+ # with col2:
207
+ # st.write(row["Driver Name"])
208
+
209
+ # with col3:
210
+ # st.write(row["Driver Number"])
211
+
212
+ # with col4:
213
+ # st.write(row["Driver Email"])
214
+
215
+ # with col5:
216
+ # if st.button(f"Allocate Truck {row['Truck No']}", key=f"allocate_{index}"):
217
+ # # Store allocation state for this truck
218
+ # st.session_state["allocation_details"][row["Truck No"]] = {
219
+ # "longitude": "",
220
+ # "latitude": "",
221
+ # "location": ""
222
+ # }
223
+
224
+ # # Display allocation inputs for each truck
225
+ # if st.session_state["allocation_details"]:
226
+ # for truck_no, details in st.session_state["allocation_details"].items():
227
+ # st.subheader(f"Allocation Details for Truck {truck_no}")
228
+
229
+ # longitude = st.text_input("Enter Longitude", value=details["longitude"], key=f"longitude_{truck_no}")
230
+ # latitude = st.text_input("Enter Latitude", value=details["latitude"], key=f"latitude_{truck_no}")
231
+ # location = st.text_input("Enter Location", value=details["location"], key=f"location_{truck_no}")
232
+
233
+ # # Update session state with new values
234
+ # st.session_state["allocation_details"][truck_no] = {
235
+ # "longitude": longitude,
236
+ # "latitude": latitude,
237
+ # "location": location
238
+ # }
239
+
240
+ # if st.button("Send Email", key=f"send_email_{truck_no}"):
241
+ # if longitude and latitude and location:
242
+ # driver_email = df.loc[df["Truck No"] == truck_no, "Driver Email"].values[0]
243
+ # send_email(driver_email, longitude, latitude, location)
244
+ # else:
245
+ # st.error("Please fill all the details before sending the email.")
246
+
247
+ # # Footer
248
+ # st.markdown("---")
249
+ # st.markdown(
250
+ # "**Binsight Admin Dashboard**: Manage your waste management operations efficiently and allocate trucks seamlessly."
251
+ # )
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+ # import streamlit as st
264
+ # import pandas as pd
265
+ # import requests
266
+
267
+ # # Function to send email using Mailgun API
268
+ # def send_email(driver_email, longitude, latitude, location):
269
+ # MAILGUN_API_KEY = "9530f415a53e78317892af32cf3c4b93-79295dd0-b3f02e29"
270
+ # MAILGUN_DOMAIN = "sandboxb2e22240ec8a4b468825577fcb967a85.mailgun.org"
271
+
272
+ # response = requests.post(
273
+ # f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN}/messages",
274
+ # auth=("api", MAILGUN_API_KEY),
275
+ # data={
276
+ # "from": f"Binsight Admin <mailgun@{MAILGUN_DOMAIN}>",
277
+ # "to": driver_email,
278
+ # "subject": "Truck Allocation Details",
279
+ # "text": f"Dear Driver,\n\nYou have been allocated to a new dustbin location. Here are the details:\n\nLongitude: {longitude}\nLatitude: {latitude}\nLocation: {location}\n\nThank you,\nBinsight Team",
280
+ # },
281
+ # )
282
+
283
+ # if response.status_code == 200:
284
+ # st.success(f"Email sent successfully to {driver_email}!")
285
+ # else:
286
+ # st.error(f"Failed to send email: {response.text}")
287
+
288
+ # # Streamlit app configuration
289
+ # st.set_page_config(page_title="Binsight Admin Dashboard", layout="wide")
290
+
291
+ # # App title
292
+ # st.title("Binsight Admin Dashboard")
293
+
294
+ # # Dummy data for the dashboard (replace this with your database or API connection)
295
+ # data = [
296
+ # {"Truck No": "TR001", "Driver Name": "Krishna K", "Driver Number": "1234567890", "Driver Email": "krishnaproject23@gmail.com"},
297
+ # {"Truck No": "TR002", "Driver Name": "Jane Smith", "Driver Number": "0987654321", "Driver Email": "jane@example.com"},
298
+ # {"Truck No": "TR003", "Driver Name": "Mike Ross", "Driver Number": "1122334455", "Driver Email": "mike@example.com"},
299
+ # ]
300
+
301
+ # df = pd.DataFrame(data)
302
+
303
+ # # Display the data in a tabular format
304
+ # st.subheader("Truck and Driver Details")
305
+ # for index, row in df.iterrows():
306
+ # col1, col2, col3, col4, col5 = st.columns([1, 2, 2, 3, 2])
307
+
308
+ # with col1:
309
+ # st.write(row["Truck No"])
310
+
311
+ # with col2:
312
+ # st.write(row["Driver Name"])
313
+
314
+ # with col3:
315
+ # st.write(row["Driver Number"])
316
+
317
+ # with col4:
318
+ # st.write(row["Driver Email"])
319
+
320
+ # with col5:
321
+ # if st.button(f"Allocate Truck {row['Truck No']}", key=f"allocate_{index}"):
322
+ # # Inputs for longitude, latitude, and location
323
+ # st.write(f"Allocating truck {row['Truck No']}...")
324
+
325
+ # longitude = st.text_input("Enter Longitude", key=f"longitude_{index}")
326
+ # latitude = st.text_input("Enter Latitude", key=f"latitude_{index}")
327
+ # location = st.text_input("Enter Location", key=f"location_{index}")
328
+
329
+ # if st.button("Send Email", key=f"send_email_{index}"):
330
+ # if longitude and latitude and location:
331
+ # send_email(row["Driver Email"], longitude, latitude, location)
332
+ # else:
333
+ # st.error("Please fill all the details before sending the email.")
334
+
335
+ # # Footer
336
+ # st.markdown("---")
337
+ # st.markdown(
338
+ # "**Binsight Admin Dashboard**: Manage your waste management operations efficiently and allocate trucks seamlessly."
339
+ # )
firebase_credentials.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "service_account",
3
+ "project_id": "binsight-beda0",
4
+ "private_key_id": "86c2e13649ff195cab006525a8ce7bef4cc4f058",
5
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhk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OiZOg7G8ddA1Dw2Vh8xs0Ds7hufMlCz81uXoac42b\nr5UFsrLAvwKBgEl2bw5+HKPi5Y2plWeKOtF+4502gWAtQqL1pPKSXQc397bI6MHo\nX52CET9pqUhWcvGYyak5Byi2iJ2NOgzFpaFsIweaTbrJDFUxFXT0pTtufx+vfwAw\nz/PHGvkBKi7xhi2wS4YcM5ZWA2qF8gSzfmDmYe2aoTKxk7f+ijsmS6fFAoGAUr0o\nCIMWTfH/GZSP2HgfrUfiGi1qxG6xfCZCIRPY/Id0xf/TW2u3VakDm2nVadxDrARq\nHR6a/O+wSFjI0R4ECt5z7uyC0PP/nL+IvVtvhWXQN4m43nUnrG7itkKezKelJ4lF\nFvXjWhs9sKwFc8B1KxJvMlRgq/Q2Pl+Hqxe1lEUCgYEAw1edm/iMOK4M+Uu1cMjR\nY1Ebv0krcgq7c1xww0uwbNzbaULNQ/WA0VjCRr2vQIvwvl/vvzFS22y05YYRpIkd\nRrE//iuTHvT9dWQ0LwdwmQGLw5D+2aUra4r4oxFJSee227GReVZzVJLMdBzN6Nlf\nc90EgNm0/XVwiU8ffvVNKvI=\n-----END PRIVATE KEY-----\n",
6
+ "client_email": "firebase-adminsdk-fbsvc@binsight-beda0.iam.gserviceaccount.com",
7
+ "client_id": "117807845711034166542",
8
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
+ "token_uri": "https://oauth2.googleapis.com/token",
10
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fbsvc%40binsight-beda0.iam.gserviceaccount.com",
12
+ "universe_domain": "googleapis.com"
13
+ }
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ requests
4
+ firebase_admin