Krish-Upgrix commited on
Commit
922e41c
Β·
verified Β·
1 Parent(s): ed86ea9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +246 -179
app.py CHANGED
@@ -1,179 +1,246 @@
1
- import streamlit as st
2
- import firebase_admin
3
- from firebase_admin import credentials, db
4
- from datetime import datetime
5
-
6
- # Initialize Firebase
7
- if not firebase_admin._apps:
8
- cred = credentials.Certificate("firebase_credentials.json")
9
- firebase_admin.initialize_app(cred, {
10
- 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
11
- })
12
-
13
- st.title("Binsight Driver Dashboard")
14
- st.sidebar.header("Driver Login")
15
-
16
- driver_email = st.sidebar.text_input("Enter your email")
17
- login_button = st.sidebar.button("Login")
18
-
19
- if login_button and driver_email:
20
- st.session_state["driver_email"] = driver_email
21
- st.sidebar.success(f"Logged in as {driver_email}")
22
-
23
- if "driver_email" not in st.session_state:
24
- st.warning("Please log in first.")
25
- st.stop()
26
-
27
- dustbins_ref = db.reference("dustbins")
28
- dustbins = dustbins_ref.get() or {}
29
-
30
- allocated_tasks = {
31
- key: value for key, value in dustbins.items()
32
- if value.get("allocated_truck") == st.session_state["driver_email"] and value.get("status") == "Allocated"
33
- }
34
-
35
- st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")
36
-
37
- for key, value in allocated_tasks.items():
38
- with st.expander(f"πŸ“ Task at {value['address']}"):
39
- st.write(f"**Latitude**: {value['latitude']}")
40
- st.write(f"**Longitude**: {value['longitude']}")
41
- st.write(f"**Classification**: {', '.join([f'{k} ({v:.2f})' for k, v in value['classification'].items()])}")
42
-
43
- if st.button(f"Mark as Done", key=f"done_{key}"):
44
- dustbins_ref.child(key).update({
45
- "status": "Completed",
46
- "completed_at": str(datetime.now()),
47
- "completed_by": st.session_state["driver_email"]
48
- })
49
- st.success(f"Task at {value['address']} marked as completed!")
50
-
51
-
52
-
53
-
54
-
55
-
56
- # import streamlit as st
57
- # import firebase_admin
58
- # from firebase_admin import credentials, db
59
- # from datetime import datetime
60
-
61
- # # Initialize Firebase
62
- # if not firebase_admin._apps:
63
- # cred = credentials.Certificate("firebase_credentials.json") # Path to your Firebase JSON
64
- # firebase_admin.initialize_app(cred, {
65
- # 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/' # Replace with your Firebase Realtime Database URL
66
- # })
67
-
68
- # # Streamlit App
69
- # st.title("Binsight Driver Dashboard")
70
- # st.sidebar.header("Driver Login")
71
-
72
- # # Driver Login
73
- # driver_email = st.sidebar.text_input("Enter your email")
74
- # login_button = st.sidebar.button("Login")
75
-
76
- # if login_button:
77
- # if driver_email:
78
- # # Fetch allocated tasks from Firebase
79
- # dustbins_ref = db.reference("dustbins")
80
- # dustbins = dustbins_ref.get()
81
-
82
- # # Filter tasks for the logged-in driver
83
- # allocated_tasks = {
84
- # key: value
85
- # for key, value in dustbins.items()
86
- # if value.get("allocated_truck") == driver_email and value.get("status") == "Allocated"
87
- # }
88
-
89
- # if allocated_tasks:
90
- # st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")
91
- # for key, value in allocated_tasks.items():
92
- # with st.expander(f"πŸ“ Task at {value['address']}"):
93
- # st.write(f"**Latitude**: {value['latitude']}")
94
- # st.write(f"**Longitude**: {value['longitude']}")
95
- # st.write(f"**Classification**: {', '.join([f'{k} ({v:.2f})' for k, v in value['classification'].items()])}")
96
- # st.write(f"**Allocated At**: {value.get('allocated_at', 'N/A')}")
97
-
98
- # # Submit Work Done
99
- # if st.button(f"Mark as Done", key=f"done_{key}"):
100
- # dustbins_ref.child(key).update({
101
- # "status": "Completed",
102
- # "completed_at": str(datetime.now()),
103
- # "completed_by": driver_email
104
- # })
105
- # st.success(f"Task at {value['address']} marked as completed!")
106
- # else:
107
- # st.info("No allocated tasks found.")
108
- # else:
109
- # st.error("Please enter your email to login.")
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
- # import streamlit as st
123
- # import firebase_admin
124
- # from firebase_admin import credentials, db
125
- # from datetime import datetime
126
-
127
- # # Initialize Firebase
128
- # if not firebase_admin._apps:
129
- # cred = credentials.Certificate("firebase_credentials.json") # Path to your Firebase JSON
130
- # firebase_admin.initialize_app(cred, {
131
- # 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/' # Replace with your Firebase Realtime Database URL
132
- # })
133
-
134
- # # Streamlit App
135
- # st.title("Binsight Driver Dashboard")
136
- # st.sidebar.header("Driver Login")
137
-
138
- # # Driver Login
139
- # driver_email = st.sidebar.text_input("Enter your email", help="Provide your registered email.")
140
- # login_button = st.sidebar.button("Login")
141
-
142
- # if login_button:
143
- # if driver_email:
144
- # # Fetch allocated tasks from Firebase
145
- # dustbins_ref = db.reference("dustbins")
146
- # dustbins = dustbins_ref.get()
147
-
148
- # if not dustbins:
149
- # st.info("No tasks available.")
150
- # else:
151
- # # Filter tasks for the logged-in driver
152
- # allocated_tasks = {
153
- # key: value
154
- # for key, value in dustbins.items()
155
- # if value.get("allocated_truck") == driver_email and value.get("status") == "Allocated"
156
- # }
157
-
158
- # if allocated_tasks:
159
- # st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")
160
- # for key, value in allocated_tasks.items():
161
- # with st.expander(f"πŸ“ Task at {value['address']}"):
162
- # st.write(f"**Latitude**: {value['latitude']}")
163
- # st.write(f"**Longitude**: {value['longitude']}")
164
- # st.write(f"**Classification**: {', '.join([f'{k} ({v:.2f})' for k, v in value['classification'].items()])}")
165
- # st.write(f"**Allocated At**: {value.get('allocated_at', 'N/A')}")
166
-
167
- # # Submit Work Done
168
- # if st.button(f"Mark as Done", key=f"done_{key}"):
169
- # dustbins_ref.child(key).update({
170
- # "status": "Completed",
171
- # "completed_at": str(datetime.now()),
172
- # "completed_by": driver_email,
173
- # })
174
- # st.success(f"Task at {value['address']} marked as completed!")
175
- # else:
176
- # st.info("No allocated tasks found for your account.")
177
- # else:
178
- # st.error("Please enter your email to login.")
179
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import firebase_admin
3
+ from firebase_admin import credentials, db
4
+ from datetime import datetime
5
+ import base64
6
+ from io import BytesIO
7
+ from PIL import Image
8
+
9
+ # Initialize Firebase (Check if already initialized)
10
+ if not firebase_admin._apps:
11
+ cred = credentials.Certificate("firebase_credentials.json")
12
+ firebase_admin.initialize_app(cred, {
13
+ 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
14
+ })
15
+
16
+
17
+ st.title("Binsight Driver Dashboard")
18
+ st.sidebar.header("Driver Login")
19
+
20
+ driver_email = st.sidebar.text_input("Enter your email")
21
+ login_button = st.sidebar.button("Login")
22
+
23
+ if login_button and driver_email:
24
+ st.session_state["driver_email"] = driver_email
25
+ st.sidebar.success(f"Logged in as {driver_email}")
26
+
27
+ if "driver_email" not in st.session_state:
28
+ st.warning("Please log in first.")
29
+ st.stop()
30
+
31
+ dustbins_ref = db.reference("dustbins")
32
+ dustbins = dustbins_ref.get() or {}
33
+
34
+ allocated_tasks = {
35
+ key: value for key, value in dustbins.items()
36
+ if value.get("allocated_truck") == st.session_state["driver_email"] and value.get("status") == "Allocated"
37
+ }
38
+
39
+ st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")
40
+
41
+ for key, value in allocated_tasks.items():
42
+ with st.expander(f"πŸ“ Task at {value['address']}"):
43
+ st.write(f"**Latitude**: {value['latitude']}")
44
+ st.write(f"**Longitude**: {value['longitude']}")
45
+
46
+ if "image" in value:
47
+ image_data = base64.b64decode(value["image"])
48
+ st.image(Image.open(BytesIO(image_data)), caption="Dustbin Image", use_column_width=True)
49
+
50
+ if st.button(f"Mark as Done", key=f"done_{key}"):
51
+ dustbins_ref.child(key).update({
52
+ "status": "Completed",
53
+ "completed_at": str(datetime.now()),
54
+ "completed_by": st.session_state["driver_email"]
55
+ })
56
+ st.success(f"Task at {value['address']} marked as completed!")
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+ # Best without image
67
+
68
+ # import streamlit as st
69
+ # import firebase_admin
70
+ # from firebase_admin import credentials, db
71
+ # from datetime import datetime
72
+
73
+ # # Initialize Firebase
74
+ # if not firebase_admin._apps:
75
+ # cred = credentials.Certificate("firebase_credentials.json")
76
+ # firebase_admin.initialize_app(cred, {
77
+ # 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
78
+ # })
79
+
80
+ # st.title("Binsight Driver Dashboard")
81
+ # st.sidebar.header("Driver Login")
82
+
83
+ # driver_email = st.sidebar.text_input("Enter your email")
84
+ # login_button = st.sidebar.button("Login")
85
+
86
+ # if login_button and driver_email:
87
+ # st.session_state["driver_email"] = driver_email
88
+ # st.sidebar.success(f"Logged in as {driver_email}")
89
+
90
+ # if "driver_email" not in st.session_state:
91
+ # st.warning("Please log in first.")
92
+ # st.stop()
93
+
94
+ # dustbins_ref = db.reference("dustbins")
95
+ # dustbins = dustbins_ref.get() or {}
96
+
97
+ # allocated_tasks = {
98
+ # key: value for key, value in dustbins.items()
99
+ # if value.get("allocated_truck") == st.session_state["driver_email"] and value.get("status") == "Allocated"
100
+ # }
101
+
102
+ # st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")
103
+
104
+ # for key, value in allocated_tasks.items():
105
+ # with st.expander(f"πŸ“ Task at {value['address']}"):
106
+ # st.write(f"**Latitude**: {value['latitude']}")
107
+ # st.write(f"**Longitude**: {value['longitude']}")
108
+ # st.write(f"**Classification**: {', '.join([f'{k} ({v:.2f})' for k, v in value['classification'].items()])}")
109
+
110
+ # if st.button(f"Mark as Done", key=f"done_{key}"):
111
+ # dustbins_ref.child(key).update({
112
+ # "status": "Completed",
113
+ # "completed_at": str(datetime.now()),
114
+ # "completed_by": st.session_state["driver_email"]
115
+ # })
116
+ # st.success(f"Task at {value['address']} marked as completed!")
117
+
118
+
119
+
120
+
121
+
122
+
123
+ # import streamlit as st
124
+ # import firebase_admin
125
+ # from firebase_admin import credentials, db
126
+ # from datetime import datetime
127
+
128
+ # # Initialize Firebase
129
+ # if not firebase_admin._apps:
130
+ # cred = credentials.Certificate("firebase_credentials.json") # Path to your Firebase JSON
131
+ # firebase_admin.initialize_app(cred, {
132
+ # 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/' # Replace with your Firebase Realtime Database URL
133
+ # })
134
+
135
+ # # Streamlit App
136
+ # st.title("Binsight Driver Dashboard")
137
+ # st.sidebar.header("Driver Login")
138
+
139
+ # # Driver Login
140
+ # driver_email = st.sidebar.text_input("Enter your email")
141
+ # login_button = st.sidebar.button("Login")
142
+
143
+ # if login_button:
144
+ # if driver_email:
145
+ # # Fetch allocated tasks from Firebase
146
+ # dustbins_ref = db.reference("dustbins")
147
+ # dustbins = dustbins_ref.get()
148
+
149
+ # # Filter tasks for the logged-in driver
150
+ # allocated_tasks = {
151
+ # key: value
152
+ # for key, value in dustbins.items()
153
+ # if value.get("allocated_truck") == driver_email and value.get("status") == "Allocated"
154
+ # }
155
+
156
+ # if allocated_tasks:
157
+ # st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")
158
+ # for key, value in allocated_tasks.items():
159
+ # with st.expander(f"πŸ“ Task at {value['address']}"):
160
+ # st.write(f"**Latitude**: {value['latitude']}")
161
+ # st.write(f"**Longitude**: {value['longitude']}")
162
+ # st.write(f"**Classification**: {', '.join([f'{k} ({v:.2f})' for k, v in value['classification'].items()])}")
163
+ # st.write(f"**Allocated At**: {value.get('allocated_at', 'N/A')}")
164
+
165
+ # # Submit Work Done
166
+ # if st.button(f"Mark as Done", key=f"done_{key}"):
167
+ # dustbins_ref.child(key).update({
168
+ # "status": "Completed",
169
+ # "completed_at": str(datetime.now()),
170
+ # "completed_by": driver_email
171
+ # })
172
+ # st.success(f"Task at {value['address']} marked as completed!")
173
+ # else:
174
+ # st.info("No allocated tasks found.")
175
+ # else:
176
+ # st.error("Please enter your email to login.")
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+ # import streamlit as st
190
+ # import firebase_admin
191
+ # from firebase_admin import credentials, db
192
+ # from datetime import datetime
193
+
194
+ # # Initialize Firebase
195
+ # if not firebase_admin._apps:
196
+ # cred = credentials.Certificate("firebase_credentials.json") # Path to your Firebase JSON
197
+ # firebase_admin.initialize_app(cred, {
198
+ # 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/' # Replace with your Firebase Realtime Database URL
199
+ # })
200
+
201
+ # # Streamlit App
202
+ # st.title("Binsight Driver Dashboard")
203
+ # st.sidebar.header("Driver Login")
204
+
205
+ # # Driver Login
206
+ # driver_email = st.sidebar.text_input("Enter your email", help="Provide your registered email.")
207
+ # login_button = st.sidebar.button("Login")
208
+
209
+ # if login_button:
210
+ # if driver_email:
211
+ # # Fetch allocated tasks from Firebase
212
+ # dustbins_ref = db.reference("dustbins")
213
+ # dustbins = dustbins_ref.get()
214
+
215
+ # if not dustbins:
216
+ # st.info("No tasks available.")
217
+ # else:
218
+ # # Filter tasks for the logged-in driver
219
+ # allocated_tasks = {
220
+ # key: value
221
+ # for key, value in dustbins.items()
222
+ # if value.get("allocated_truck") == driver_email and value.get("status") == "Allocated"
223
+ # }
224
+
225
+ # if allocated_tasks:
226
+ # st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")
227
+ # for key, value in allocated_tasks.items():
228
+ # with st.expander(f"πŸ“ Task at {value['address']}"):
229
+ # st.write(f"**Latitude**: {value['latitude']}")
230
+ # st.write(f"**Longitude**: {value['longitude']}")
231
+ # st.write(f"**Classification**: {', '.join([f'{k} ({v:.2f})' for k, v in value['classification'].items()])}")
232
+ # st.write(f"**Allocated At**: {value.get('allocated_at', 'N/A')}")
233
+
234
+ # # Submit Work Done
235
+ # if st.button(f"Mark as Done", key=f"done_{key}"):
236
+ # dustbins_ref.child(key).update({
237
+ # "status": "Completed",
238
+ # "completed_at": str(datetime.now()),
239
+ # "completed_by": driver_email,
240
+ # })
241
+ # st.success(f"Task at {value['address']} marked as completed!")
242
+ # else:
243
+ # st.info("No allocated tasks found for your account.")
244
+ # else:
245
+ # st.error("Please enter your email to login.")
246
+