Krish-Upgrix commited on
Commit
060d88d
·
verified ·
1 Parent(s): 0ed4c7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -0
app.py CHANGED
@@ -82,6 +82,103 @@ for key, value in allocated_tasks.items():
82
  })
83
  st.success(f"Task at {value['address']} marked as completed!")
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
 
87
 
 
82
  })
83
  st.success(f"Task at {value['address']} marked as completed!")
84
 
85
+ # Back button to redirect to dashboard
86
+ st.markdown("<br>", unsafe_allow_html=True)
87
+ 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)
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+ # Best version without back button
97
+
98
+ # import streamlit as st
99
+ # import firebase_admin
100
+ # from firebase_admin import credentials, db
101
+ # from datetime import datetime
102
+ # import base64
103
+ # from io import BytesIO
104
+ # from PIL import Image
105
+ # import requests
106
+
107
+ # # Initialize Firebase Realtime Database
108
+ # if not firebase_admin._apps:
109
+ # cred = credentials.Certificate("firebase_credentials.json")
110
+ # firebase_admin.initialize_app(cred, {
111
+ # 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
112
+ # })
113
+
114
+ # # Firebase Authentication REST API
115
+ # FIREBASE_AUTH_URL = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyAj-0voQamIhPvnWZPd_SwkhlOR1pXynvg"
116
+
117
+ # st.title("Binsight Driver Dashboard")
118
+
119
+ # # Session state for authentication
120
+ # if "authenticated" not in st.session_state:
121
+ # st.session_state.authenticated = False
122
+ # if "driver_email" not in st.session_state:
123
+ # st.session_state.driver_email = None
124
+
125
+ # # Authentication UI
126
+ # st.sidebar.header("Driver Login")
127
+
128
+ # def login():
129
+ # email = st.sidebar.text_input("Enter your email")
130
+ # password = st.sidebar.text_input("Enter your password", type="password")
131
+ # if st.sidebar.button("Login"):
132
+ # payload = {"email": email, "password": password, "returnSecureToken": True}
133
+ # response = requests.post(FIREBASE_AUTH_URL, json=payload)
134
+ # if response.status_code == 200:
135
+ # st.session_state.authenticated = True
136
+ # st.session_state.driver_email = email
137
+ # st.sidebar.success(f"Logged in as {email}")
138
+ # st.rerun()
139
+ # else:
140
+ # st.sidebar.error("Invalid credentials or user does not exist.")
141
+
142
+ # # Logout functionality
143
+ # def logout():
144
+ # st.session_state.authenticated = False
145
+ # st.session_state.driver_email = None
146
+ # st.rerun()
147
+
148
+ # if st.session_state.authenticated:
149
+ # st.sidebar.button("Logout", on_click=logout)
150
+ # else:
151
+ # login()
152
+ # st.stop()
153
+
154
+ # # Fetch allocated tasks
155
+ # dustbins_ref = db.reference("dustbins")
156
+ # dustbins = dustbins_ref.get() or {}
157
+
158
+ # allocated_tasks = {
159
+ # key: value for key, value in dustbins.items()
160
+ # if value.get("allocated_truck") == st.session_state["driver_email"] and value.get("status") == "Allocated"
161
+ # }
162
+
163
+ # st.subheader(f"Allocated Tasks ({len(allocated_tasks)})")
164
+
165
+ # for key, value in allocated_tasks.items():
166
+ # with st.expander(f"📍 Task at {value['address']}"):
167
+ # st.write(f"**Latitude**: {value['latitude']}")
168
+ # st.write(f"**Longitude**: {value['longitude']}")
169
+
170
+ # if "image" in value:
171
+ # image_data = base64.b64decode(value["image"])
172
+ # st.image(Image.open(BytesIO(image_data)), caption="Dustbin Image", use_column_width=True)
173
+
174
+ # if st.button(f"Mark as Done", key=f"done_{key}"):
175
+ # dustbins_ref.child(key).update({
176
+ # "status": "Completed",
177
+ # "completed_at": str(datetime.now()),
178
+ # "completed_by": st.session_state["driver_email"]
179
+ # })
180
+ # st.success(f"Task at {value['address']} marked as completed!")
181
+
182
 
183
 
184