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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
922e41c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
import streamlit as st
import firebase_admin
from firebase_admin import credentials, db
from datetime import datetime
import base64
from io import BytesIO
from PIL import Image
import requests

# Initialize Firebase Realtime Database
if not firebase_admin._apps:
    cred = credentials.Certificate("firebase_credentials.json")  
    firebase_admin.initialize_app(cred, {
        'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
    })

# Firebase Authentication REST API
FIREBASE_AUTH_URL = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyAj-0voQamIhPvnWZPd_SwkhlOR1pXynvg"

st.title("Binsight Driver Dashboard")

# Session state for authentication
if "authenticated" not in st.session_state:
    st.session_state.authenticated = False
if "driver_email" not in st.session_state:
    st.session_state.driver_email = None

# Authentication UI
st.sidebar.header("Driver Login")

def login():
    email = st.sidebar.text_input("Enter your email")
    password = st.sidebar.text_input("Enter your password", type="password")
    if st.sidebar.button("Login"):
        payload = {"email": email, "password": password, "returnSecureToken": True}
        response = requests.post(FIREBASE_AUTH_URL, json=payload)
        if response.status_code == 200:
            st.session_state.authenticated = True
            st.session_state.driver_email = email
            st.sidebar.success(f"Logged in as {email}")
            st.rerun()
        else:
            st.sidebar.error("Invalid credentials or user does not exist.")

# Logout functionality
def logout():
    st.session_state.authenticated = False
    st.session_state.driver_email = None
    st.rerun()

if st.session_state.authenticated:
    st.sidebar.button("Logout", on_click=logout)
else:
    login()
    st.stop()

# Fetch allocated tasks
dustbins_ref = db.reference("dustbins")
dustbins = dustbins_ref.get() or {}

allocated_tasks = {
    key: value for key, value in dustbins.items()
    if value.get("allocated_truck") == st.session_state["driver_email"] and value.get("status") == "Allocated"
}

st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")

for key, value in allocated_tasks.items():
    with st.expander(f"πŸ“ Task at {value['address']}"):
        st.write(f"**Latitude**: {value['latitude']}")
        st.write(f"**Longitude**: {value['longitude']}")

        if "image" in value:
            image_data = base64.b64decode(value["image"])
            st.image(Image.open(BytesIO(image_data)), caption="Dustbin Image", use_column_width=True)

        if st.button(f"Mark as Done", key=f"done_{key}"):
            dustbins_ref.child(key).update({
                "status": "Completed",
                "completed_at": str(datetime.now()),
                "completed_by": st.session_state["driver_email"]
            })
            st.success(f"Task at {value['address']} marked as completed!")

# Back button to redirect to dashboard
st.markdown("<br>", unsafe_allow_html=True)
st.markdown("<a href='https://binsight.onrender.com/dashboard.html' target='_self' style='text-decoration:none;'><button style='padding: 10px 20px; font-size: 16px;'>β¬… Back to Dashboard</button></a>", unsafe_allow_html=True)








# Best version without back button

# import streamlit as st
# import firebase_admin
# from firebase_admin import credentials, db
# from datetime import datetime
# import base64
# from io import BytesIO
# from PIL import Image
# import requests

# # Initialize Firebase Realtime Database
# if not firebase_admin._apps:
#     cred = credentials.Certificate("firebase_credentials.json")  
#     firebase_admin.initialize_app(cred, {
#         'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
#     })

# # Firebase Authentication REST API
# FIREBASE_AUTH_URL = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyAj-0voQamIhPvnWZPd_SwkhlOR1pXynvg"

# st.title("Binsight Driver Dashboard")

# # Session state for authentication
# if "authenticated" not in st.session_state:
#     st.session_state.authenticated = False
# if "driver_email" not in st.session_state:
#     st.session_state.driver_email = None

# # Authentication UI
# st.sidebar.header("Driver Login")

# def login():
#     email = st.sidebar.text_input("Enter your email")
#     password = st.sidebar.text_input("Enter your password", type="password")
#     if st.sidebar.button("Login"):
#         payload = {"email": email, "password": password, "returnSecureToken": True}
#         response = requests.post(FIREBASE_AUTH_URL, json=payload)
#         if response.status_code == 200:
#             st.session_state.authenticated = True
#             st.session_state.driver_email = email
#             st.sidebar.success(f"Logged in as {email}")
#             st.rerun()
#         else:
#             st.sidebar.error("Invalid credentials or user does not exist.")

# # Logout functionality
# def logout():
#     st.session_state.authenticated = False
#     st.session_state.driver_email = None
#     st.rerun()

# if st.session_state.authenticated:
#     st.sidebar.button("Logout", on_click=logout)
# else:
#     login()
#     st.stop()

# # Fetch allocated tasks
# dustbins_ref = db.reference("dustbins")
# dustbins = dustbins_ref.get() or {}

# allocated_tasks = {
#     key: value for key, value in dustbins.items()
#     if value.get("allocated_truck") == st.session_state["driver_email"] and value.get("status") == "Allocated"
# }

# st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")

# for key, value in allocated_tasks.items():
#     with st.expander(f"πŸ“ Task at {value['address']}"):
#         st.write(f"**Latitude**: {value['latitude']}")
#         st.write(f"**Longitude**: {value['longitude']}")

#         if "image" in value:
#             image_data = base64.b64decode(value["image"])
#             st.image(Image.open(BytesIO(image_data)), caption="Dustbin Image", use_column_width=True)

#         if st.button(f"Mark as Done", key=f"done_{key}"):
#             dustbins_ref.child(key).update({
#                 "status": "Completed",
#                 "completed_at": str(datetime.now()),
#                 "completed_by": st.session_state["driver_email"]
#             })
#             st.success(f"Task at {value['address']} marked as completed!")












## Below code is working but it is doesn't having login proper for user. anyone can login


# import streamlit as st
# import firebase_admin
# from firebase_admin import credentials, db
# from datetime import datetime
# import base64
# from io import BytesIO
# from PIL import Image

# # Initialize Firebase (Check if already initialized)
# if not firebase_admin._apps:
#     cred = credentials.Certificate("firebase_credentials.json")  
#     firebase_admin.initialize_app(cred, {
#         'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
#     })


# st.title("Binsight Driver Dashboard")
# st.sidebar.header("Driver Login")

# driver_email = st.sidebar.text_input("Enter your email")
# login_button = st.sidebar.button("Login")

# if login_button and driver_email:
#     st.session_state["driver_email"] = driver_email
#     st.sidebar.success(f"Logged in as {driver_email}")

# if "driver_email" not in st.session_state:
#     st.warning("Please log in first.")
#     st.stop()

# dustbins_ref = db.reference("dustbins")
# dustbins = dustbins_ref.get() or {}

# allocated_tasks = {
#     key: value for key, value in dustbins.items()
#     if value.get("allocated_truck") == st.session_state["driver_email"] and value.get("status") == "Allocated"
# }

# st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")

# for key, value in allocated_tasks.items():
#     with st.expander(f"πŸ“ Task at {value['address']}"):
#         st.write(f"**Latitude**: {value['latitude']}")
#         st.write(f"**Longitude**: {value['longitude']}")

#         if "image" in value:
#             image_data = base64.b64decode(value["image"])
#             st.image(Image.open(BytesIO(image_data)), caption="Dustbin Image", use_column_width=True)

#         if st.button(f"Mark as Done", key=f"done_{key}"):
#             dustbins_ref.child(key).update({
#                 "status": "Completed",
#                 "completed_at": str(datetime.now()),
#                 "completed_by": st.session_state["driver_email"]
#             })
#             st.success(f"Task at {value['address']} marked as completed!")









# # Best without image

# # import streamlit as st
# # import firebase_admin
# # from firebase_admin import credentials, db
# # from datetime import datetime

# # # Initialize Firebase
# # if not firebase_admin._apps:
# #     cred = credentials.Certificate("firebase_credentials.json")
# #     firebase_admin.initialize_app(cred, {
# #         'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
# #     })

# # st.title("Binsight Driver Dashboard")
# # st.sidebar.header("Driver Login")

# # driver_email = st.sidebar.text_input("Enter your email")
# # login_button = st.sidebar.button("Login")

# # if login_button and driver_email:
# #     st.session_state["driver_email"] = driver_email
# #     st.sidebar.success(f"Logged in as {driver_email}")

# # if "driver_email" not in st.session_state:
# #     st.warning("Please log in first.")
# #     st.stop()

# # dustbins_ref = db.reference("dustbins")
# # dustbins = dustbins_ref.get() or {}

# # allocated_tasks = {
# #     key: value for key, value in dustbins.items()
# #     if value.get("allocated_truck") == st.session_state["driver_email"] and value.get("status") == "Allocated"
# # }

# # st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")

# # for key, value in allocated_tasks.items():
# #     with st.expander(f"πŸ“ Task at {value['address']}"):
# #         st.write(f"**Latitude**: {value['latitude']}")
# #         st.write(f"**Longitude**: {value['longitude']}")
# #         st.write(f"**Classification**: {', '.join([f'{k} ({v:.2f})' for k, v in value['classification'].items()])}")

# #         if st.button(f"Mark as Done", key=f"done_{key}"):
# #             dustbins_ref.child(key).update({
# #                 "status": "Completed",
# #                 "completed_at": str(datetime.now()),
# #                 "completed_by": st.session_state["driver_email"]
# #             })
# #             st.success(f"Task at {value['address']} marked as completed!")






# # import streamlit as st
# # import firebase_admin
# # from firebase_admin import credentials, db
# # from datetime import datetime

# # # Initialize Firebase
# # if not firebase_admin._apps:
# #     cred = credentials.Certificate("firebase_credentials.json")  # Path to your Firebase JSON
# #     firebase_admin.initialize_app(cred, {
# #         'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'  # Replace with your Firebase Realtime Database URL
# #     })

# # # Streamlit App
# # st.title("Binsight Driver Dashboard")
# # st.sidebar.header("Driver Login")

# # # Driver Login
# # driver_email = st.sidebar.text_input("Enter your email")
# # login_button = st.sidebar.button("Login")

# # if login_button:
# #     if driver_email:
# #         # Fetch allocated tasks from Firebase
# #         dustbins_ref = db.reference("dustbins")
# #         dustbins = dustbins_ref.get()

# #         # Filter tasks for the logged-in driver
# #         allocated_tasks = {
# #             key: value
# #             for key, value in dustbins.items()
# #             if value.get("allocated_truck") == driver_email and value.get("status") == "Allocated"
# #         }

# #         if allocated_tasks:
# #             st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")
# #             for key, value in allocated_tasks.items():
# #                 with st.expander(f"πŸ“ Task at {value['address']}"):
# #                     st.write(f"**Latitude**: {value['latitude']}")
# #                     st.write(f"**Longitude**: {value['longitude']}")
# #                     st.write(f"**Classification**: {', '.join([f'{k} ({v:.2f})' for k, v in value['classification'].items()])}")
# #                     st.write(f"**Allocated At**: {value.get('allocated_at', 'N/A')}")

# #                     # Submit Work Done
# #                     if st.button(f"Mark as Done", key=f"done_{key}"):
# #                         dustbins_ref.child(key).update({
# #                             "status": "Completed",
# #                             "completed_at": str(datetime.now()),
# #                             "completed_by": driver_email
# #                         })
# #                         st.success(f"Task at {value['address']} marked as completed!")
# #         else:
# #             st.info("No allocated tasks found.")
# #     else:
# #         st.error("Please enter your email to login.")












# # import streamlit as st
# # import firebase_admin
# # from firebase_admin import credentials, db
# # from datetime import datetime

# # # Initialize Firebase
# # if not firebase_admin._apps:
# #     cred = credentials.Certificate("firebase_credentials.json")  # Path to your Firebase JSON
# #     firebase_admin.initialize_app(cred, {
# #         'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'  # Replace with your Firebase Realtime Database URL
# #     })

# # # Streamlit App
# # st.title("Binsight Driver Dashboard")
# # st.sidebar.header("Driver Login")

# # # Driver Login
# # driver_email = st.sidebar.text_input("Enter your email", help="Provide your registered email.")
# # login_button = st.sidebar.button("Login")

# # if login_button:
# #     if driver_email:
# #         # Fetch allocated tasks from Firebase
# #         dustbins_ref = db.reference("dustbins")
# #         dustbins = dustbins_ref.get()

# #         if not dustbins:
# #             st.info("No tasks available.")
# #         else:
# #             # Filter tasks for the logged-in driver
# #             allocated_tasks = {
# #                 key: value
# #                 for key, value in dustbins.items()
# #                 if value.get("allocated_truck") == driver_email and value.get("status") == "Allocated"
# #             }

# #             if allocated_tasks:
# #                 st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")
# #                 for key, value in allocated_tasks.items():
# #                     with st.expander(f"πŸ“ Task at {value['address']}"):
# #                         st.write(f"**Latitude**: {value['latitude']}")
# #                         st.write(f"**Longitude**: {value['longitude']}")
# #                         st.write(f"**Classification**: {', '.join([f'{k} ({v:.2f})' for k, v in value['classification'].items()])}")
# #                         st.write(f"**Allocated At**: {value.get('allocated_at', 'N/A')}")

# #                         # Submit Work Done
# #                         if st.button(f"Mark as Done", key=f"done_{key}"):
# #                             dustbins_ref.child(key).update({
# #                                 "status": "Completed",
# #                                 "completed_at": str(datetime.now()),
# #                                 "completed_by": driver_email,
# #                             })
# #                             st.success(f"Task at {value['address']} marked as completed!")
# #             else:
# #                 st.info("No allocated tasks found for your account.")
# #     else:
# #         st.error("Please enter your email to login.")