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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +402 -339
app.py CHANGED
@@ -1,339 +1,402 @@
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
- # )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import firebase_admin
3
+ from firebase_admin import credentials, db
4
+ import base64
5
+ from io import BytesIO
6
+ from PIL import Image
7
+
8
+ # Initialize Firebase (Check if already initialized)
9
+ if not firebase_admin._apps:
10
+ cred = credentials.Certificate("firebase_credentials.json")
11
+ firebase_admin.initialize_app(cred, {
12
+ 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
13
+ })
14
+
15
+
16
+ st.title("Binsight Admin Dashboard")
17
+ st.sidebar.header("Filters")
18
+
19
+ filter_status = st.sidebar.selectbox("Filter by Status", ["All", "Pending", "Allocated", "Completed"], index=0)
20
+
21
+ dustbins_ref = db.reference("dustbins")
22
+ dustbins = dustbins_ref.get() or {}
23
+
24
+ filtered_dustbins = {
25
+ key: value for key, value in dustbins.items()
26
+ if filter_status == "All" or value["status"] == filter_status
27
+ }
28
+
29
+ st.subheader(f"Showing {filter_status.lower()} dustbins ({len(filtered_dustbins)})")
30
+
31
+ for key, value in filtered_dustbins.items():
32
+ with st.expander(f"📍 {value['address']}"):
33
+ st.write(f"**Latitude**: {value['latitude']}")
34
+ st.write(f"**Longitude**: {value['longitude']}")
35
+ st.write(f"**Status**: {value['status']}")
36
+ st.write(f"**User**: {value['user_email']}")
37
+
38
+ # Display Image
39
+ if "image" in value:
40
+ image_data = base64.b64decode(value["image"])
41
+ st.image(Image.open(BytesIO(image_data)), caption="Dustbin Image", use_column_width=True)
42
+
43
+ if value["status"] == "Pending":
44
+ truck_email = st.text_input(f"Allocate Truck Email for {key}", key=f"truck_{key}")
45
+ if st.button(f"Allocate Truck", key=f"allocate_{key}"):
46
+ if truck_email:
47
+ dustbins_ref.child(key).update({
48
+ "allocated_truck": truck_email,
49
+ "status": "Allocated"
50
+ })
51
+ st.success("Truck allocated successfully!")
52
+ else:
53
+ st.error("Please enter a valid truck email.")
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+ # Best without Image
63
+
64
+ # import streamlit as st
65
+ # import firebase_admin
66
+ # from firebase_admin import credentials, db
67
+
68
+ # # Initialize Firebase
69
+ # if not firebase_admin._apps:
70
+ # cred = credentials.Certificate("firebase_credentials.json")
71
+ # firebase_admin.initialize_app(cred, {
72
+ # 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
73
+ # })
74
+
75
+ # # Streamlit Dashboard
76
+ # st.title("Binsight Admin Dashboard")
77
+ # st.sidebar.header("Filters")
78
+
79
+ # filter_status = st.sidebar.selectbox("Filter by Status", ["All", "Pending", "Allocated", "Completed"], index=0)
80
+
81
+ # dustbins_ref = db.reference("dustbins")
82
+ # dustbins = dustbins_ref.get() or {}
83
+
84
+ # filtered_dustbins = {
85
+ # key: value for key, value in dustbins.items()
86
+ # if filter_status == "All" or value["status"] == filter_status
87
+ # }
88
+
89
+ # st.subheader(f"Showing {filter_status.lower()} dustbins ({len(filtered_dustbins)})")
90
+
91
+ # for key, value in filtered_dustbins.items():
92
+ # with st.expander(f"📍 {value['address']}"):
93
+ # st.write(f"**Latitude**: {value['latitude']}")
94
+ # st.write(f"**Longitude**: {value['longitude']}")
95
+ # st.write(f"**Status**: {value['status']}")
96
+ # st.write(f"**User**: {value['user_email']}")
97
+ # if value["status"] == "Pending":
98
+ # truck_email = st.text_input(f"Allocate Truck Email for {key}", key=f"truck_{key}")
99
+ # if st.button(f"Allocate Truck", key=f"allocate_{key}"):
100
+ # if truck_email:
101
+ # dustbins_ref.child(key).update({
102
+ # "allocated_truck": truck_email,
103
+ # "status": "Allocated"
104
+ # })
105
+ # st.success("Truck allocated successfully!")
106
+ # else:
107
+ # st.error("Please enter a valid truck email.")
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+ # import streamlit as st
118
+ # import firebase_admin
119
+ # from firebase_admin import credentials, db
120
+ # import requests
121
+ # from datetime import datetime
122
+
123
+ # # Initialize Firebase
124
+ # if not firebase_admin._apps:
125
+ # cred = credentials.Certificate("firebase_credentials.json") # Path to your Firebase JSON
126
+ # firebase_admin.initialize_app(cred, {
127
+ # 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/' # Replace with your Firebase Realtime Database URL
128
+ # })
129
+
130
+ # # Function to send email using Mailgun
131
+ # def send_email(recipient_email, subject, message):
132
+ # MAILGUN_API_KEY = "9530f415a53e78317892af32cf3c4b93-79295dd0-b3f02e29"
133
+ # MAILGUN_DOMAIN = "sandboxb2e22240ec8a4b468825577fcb967a85.mailgun.org"
134
+
135
+ # response = requests.post(
136
+ # f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN}/messages",
137
+ # auth=("api", MAILGUN_API_KEY),
138
+ # data={
139
+ # "from": f"Binsight Admin <mailgun@{MAILGUN_DOMAIN}>",
140
+ # "to": recipient_email,
141
+ # "subject": subject,
142
+ # "text": message,
143
+ # },
144
+ # )
145
+ # return response.status_code == 200
146
+
147
+ # # Streamlit Dashboard
148
+ # st.title("Binsight Admin Dashboard")
149
+ # st.sidebar.header("Filters")
150
+
151
+ # # Filter status
152
+ # filter_status = st.sidebar.selectbox("Filter by Status", ["All", "Pending", "Allocated", "Completed"], index=0)
153
+
154
+ # # Firebase Reference
155
+ # dustbins_ref = db.reference("dustbins")
156
+ # dustbins = dustbins_ref.get()
157
+
158
+ # # Filter dustbins
159
+ # if dustbins:
160
+ # filtered_dustbins = {
161
+ # key: value
162
+ # for key, value in dustbins.items()
163
+ # if filter_status == "All" or value["status"] == filter_status
164
+ # }
165
+ # else:
166
+ # filtered_dustbins = {}
167
+
168
+ # if filtered_dustbins:
169
+ # st.subheader(f"Showing {filter_status.lower()} dustbins ({len(filtered_dustbins)})")
170
+
171
+ # for key, value in filtered_dustbins.items():
172
+ # with st.expander(f"📍 Dustbin at {value['address']}"):
173
+ # st.write(f"**Latitude**: {value['latitude']}")
174
+ # st.write(f"**Longitude**: {value['longitude']}")
175
+ # st.write(f"**Classification**: {', '.join([f'{k} ({v:.2f})' for k, v in value['classification'].items()])}")
176
+ # st.write(f"**Status**: {value['status']}")
177
+
178
+ # if value["status"] == "Completed":
179
+ # st.write(f"**Completed By**: {value['completed_by']}")
180
+ # st.write(f"**Completed At**: {value.get('completed_at', 'N/A')}")
181
+
182
+ # # Send Thank-You Email
183
+ # user_email = st.text_input("User Email", key=f"user_email_{key}")
184
+ # if st.button("Send Thank-You Email", key=f"thank_you_{key}"):
185
+ # if user_email:
186
+ # subject = "Binsight - Thank You!"
187
+ # 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"
188
+ # email_sent = send_email(user_email, subject, message)
189
+ # if email_sent:
190
+ # st.success("Thank-you email sent successfully!")
191
+ # else:
192
+ # st.error("Failed to send email. Please check Mailgun credentials.")
193
+ # else:
194
+ # st.error("Please enter a valid user email.")
195
+ # else:
196
+ # st.info(f"No dustbins found for the selected status: {filter_status}.")
197
+
198
+ # # About Section
199
+ # st.sidebar.write("---")
200
+ # st.sidebar.write("👨‍💻 **Developed by Binsight Team**")
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+ # working best without firebase
216
+
217
+ # import streamlit as st
218
+ # import pandas as pd
219
+ # import requests
220
+
221
+ # # Function to send email using Mailgun API
222
+ # def send_email(driver_email, longitude, latitude, location):
223
+ # MAILGUN_API_KEY = "9530f415a53e78317892af32cf3c4b93-79295dd0-b3f02e29"
224
+ # MAILGUN_DOMAIN = "sandboxb2e22240ec8a4b468825577fcb967a85.mailgun.org"
225
+
226
+ # response = requests.post(
227
+ # f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN}/messages",
228
+ # auth=("api", MAILGUN_API_KEY),
229
+ # data={
230
+ # "from": f"Binsight Admin <mailgun@{MAILGUN_DOMAIN}>",
231
+ # "to": driver_email,
232
+ # "subject": "Truck Allocation Details",
233
+ # "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",
234
+ # },
235
+ # )
236
+
237
+ # if response.status_code == 200:
238
+ # st.success(f"Email sent successfully to {driver_email}!")
239
+ # else:
240
+ # st.error(f"Failed to send email: {response.text}")
241
+
242
+ # # Streamlit app configuration
243
+ # st.set_page_config(page_title="Binsight Admin Dashboard", layout="wide")
244
+
245
+ # # App title
246
+ # st.title("Binsight Admin Dashboard")
247
+
248
+ # # Dummy data for the dashboard (replace this with your database or API connection)
249
+ # data = [
250
+ # {"Truck No": "TR001", "Driver Name": "Krishna K", "Driver Number": "1234567890", "Driver Email": "krishnaproject23@gmail.com"},
251
+ # {"Truck No": "TR002", "Driver Name": "Jane Smith", "Driver Number": "0987654321", "Driver Email": "jane@example.com"},
252
+ # {"Truck No": "TR003", "Driver Name": "Mike Ross", "Driver Number": "1122334455", "Driver Email": "mike@example.com"},
253
+ # ]
254
+
255
+ # df = pd.DataFrame(data)
256
+
257
+ # # Initialize session state for truck allocation details
258
+ # if "allocation_details" not in st.session_state:
259
+ # st.session_state["allocation_details"] = {}
260
+
261
+ # # Display the data in a tabular format
262
+ # st.subheader("Truck and Driver Details")
263
+ # for index, row in df.iterrows():
264
+ # col1, col2, col3, col4, col5 = st.columns([1, 2, 2, 3, 2])
265
+
266
+ # with col1:
267
+ # st.write(row["Truck No"])
268
+
269
+ # with col2:
270
+ # st.write(row["Driver Name"])
271
+
272
+ # with col3:
273
+ # st.write(row["Driver Number"])
274
+
275
+ # with col4:
276
+ # st.write(row["Driver Email"])
277
+
278
+ # with col5:
279
+ # if st.button(f"Allocate Truck {row['Truck No']}", key=f"allocate_{index}"):
280
+ # # Store allocation state for this truck
281
+ # st.session_state["allocation_details"][row["Truck No"]] = {
282
+ # "longitude": "",
283
+ # "latitude": "",
284
+ # "location": ""
285
+ # }
286
+
287
+ # # Display allocation inputs for each truck
288
+ # if st.session_state["allocation_details"]:
289
+ # for truck_no, details in st.session_state["allocation_details"].items():
290
+ # st.subheader(f"Allocation Details for Truck {truck_no}")
291
+
292
+ # longitude = st.text_input("Enter Longitude", value=details["longitude"], key=f"longitude_{truck_no}")
293
+ # latitude = st.text_input("Enter Latitude", value=details["latitude"], key=f"latitude_{truck_no}")
294
+ # location = st.text_input("Enter Location", value=details["location"], key=f"location_{truck_no}")
295
+
296
+ # # Update session state with new values
297
+ # st.session_state["allocation_details"][truck_no] = {
298
+ # "longitude": longitude,
299
+ # "latitude": latitude,
300
+ # "location": location
301
+ # }
302
+
303
+ # if st.button("Send Email", key=f"send_email_{truck_no}"):
304
+ # if longitude and latitude and location:
305
+ # driver_email = df.loc[df["Truck No"] == truck_no, "Driver Email"].values[0]
306
+ # send_email(driver_email, longitude, latitude, location)
307
+ # else:
308
+ # st.error("Please fill all the details before sending the email.")
309
+
310
+ # # Footer
311
+ # st.markdown("---")
312
+ # st.markdown(
313
+ # "**Binsight Admin Dashboard**: Manage your waste management operations efficiently and allocate trucks seamlessly."
314
+ # )
315
+
316
+
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+ # import streamlit as st
327
+ # import pandas as pd
328
+ # import requests
329
+
330
+ # # Function to send email using Mailgun API
331
+ # def send_email(driver_email, longitude, latitude, location):
332
+ # MAILGUN_API_KEY = "9530f415a53e78317892af32cf3c4b93-79295dd0-b3f02e29"
333
+ # MAILGUN_DOMAIN = "sandboxb2e22240ec8a4b468825577fcb967a85.mailgun.org"
334
+
335
+ # response = requests.post(
336
+ # f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN}/messages",
337
+ # auth=("api", MAILGUN_API_KEY),
338
+ # data={
339
+ # "from": f"Binsight Admin <mailgun@{MAILGUN_DOMAIN}>",
340
+ # "to": driver_email,
341
+ # "subject": "Truck Allocation Details",
342
+ # "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",
343
+ # },
344
+ # )
345
+
346
+ # if response.status_code == 200:
347
+ # st.success(f"Email sent successfully to {driver_email}!")
348
+ # else:
349
+ # st.error(f"Failed to send email: {response.text}")
350
+
351
+ # # Streamlit app configuration
352
+ # st.set_page_config(page_title="Binsight Admin Dashboard", layout="wide")
353
+
354
+ # # App title
355
+ # st.title("Binsight Admin Dashboard")
356
+
357
+ # # Dummy data for the dashboard (replace this with your database or API connection)
358
+ # data = [
359
+ # {"Truck No": "TR001", "Driver Name": "Krishna K", "Driver Number": "1234567890", "Driver Email": "krishnaproject23@gmail.com"},
360
+ # {"Truck No": "TR002", "Driver Name": "Jane Smith", "Driver Number": "0987654321", "Driver Email": "jane@example.com"},
361
+ # {"Truck No": "TR003", "Driver Name": "Mike Ross", "Driver Number": "1122334455", "Driver Email": "mike@example.com"},
362
+ # ]
363
+
364
+ # df = pd.DataFrame(data)
365
+
366
+ # # Display the data in a tabular format
367
+ # st.subheader("Truck and Driver Details")
368
+ # for index, row in df.iterrows():
369
+ # col1, col2, col3, col4, col5 = st.columns([1, 2, 2, 3, 2])
370
+
371
+ # with col1:
372
+ # st.write(row["Truck No"])
373
+
374
+ # with col2:
375
+ # st.write(row["Driver Name"])
376
+
377
+ # with col3:
378
+ # st.write(row["Driver Number"])
379
+
380
+ # with col4:
381
+ # st.write(row["Driver Email"])
382
+
383
+ # with col5:
384
+ # if st.button(f"Allocate Truck {row['Truck No']}", key=f"allocate_{index}"):
385
+ # # Inputs for longitude, latitude, and location
386
+ # st.write(f"Allocating truck {row['Truck No']}...")
387
+
388
+ # longitude = st.text_input("Enter Longitude", key=f"longitude_{index}")
389
+ # latitude = st.text_input("Enter Latitude", key=f"latitude_{index}")
390
+ # location = st.text_input("Enter Location", key=f"location_{index}")
391
+
392
+ # if st.button("Send Email", key=f"send_email_{index}"):
393
+ # if longitude and latitude and location:
394
+ # send_email(row["Driver Email"], longitude, latitude, location)
395
+ # else:
396
+ # st.error("Please fill all the details before sending the email.")
397
+
398
+ # # Footer
399
+ # st.markdown("---")
400
+ # st.markdown(
401
+ # "**Binsight Admin Dashboard**: Manage your waste management operations efficiently and allocate trucks seamlessly."
402
+ # )