Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,6 +85,10 @@ if st.session_state.authenticated:
|
|
| 85 |
st.success("Truck allocated successfully!")
|
| 86 |
else:
|
| 87 |
st.error("Please enter a valid truck email.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
else:
|
| 89 |
login()
|
| 90 |
|
|
@@ -100,6 +104,110 @@ else:
|
|
| 100 |
|
| 101 |
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
|
| 105 |
## Below code is working but it is not having login of admin. that is accessible to anyone..
|
|
|
|
| 85 |
st.success("Truck allocated successfully!")
|
| 86 |
else:
|
| 87 |
st.error("Please enter a valid truck email.")
|
| 88 |
+
|
| 89 |
+
# Back button to redirect to dashboard
|
| 90 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 91 |
+
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)
|
| 92 |
else:
|
| 93 |
login()
|
| 94 |
|
|
|
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
+
# Best version without back button
|
| 108 |
+
|
| 109 |
+
# import streamlit as st
|
| 110 |
+
# import firebase_admin
|
| 111 |
+
# from firebase_admin import credentials, db
|
| 112 |
+
# import base64
|
| 113 |
+
# from io import BytesIO
|
| 114 |
+
# from PIL import Image
|
| 115 |
+
# import requests
|
| 116 |
+
|
| 117 |
+
# # Initialize Firebase Realtime Database
|
| 118 |
+
# if not firebase_admin._apps:
|
| 119 |
+
# cred = credentials.Certificate("firebase_credentials.json")
|
| 120 |
+
# firebase_admin.initialize_app(cred, {
|
| 121 |
+
# 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
|
| 122 |
+
# })
|
| 123 |
+
|
| 124 |
+
# # Firebase Authentication REST API
|
| 125 |
+
# FIREBASE_AUTH_URL = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCwYZcPI5pltxxHiMUxjmQUNIaObNXWydw"
|
| 126 |
+
|
| 127 |
+
# # Streamlit UI
|
| 128 |
+
# st.title("Binsight Admin Dashboard")
|
| 129 |
+
|
| 130 |
+
# # Session state for authentication
|
| 131 |
+
# if "authenticated" not in st.session_state:
|
| 132 |
+
# st.session_state.authenticated = False
|
| 133 |
+
# if "user" not in st.session_state:
|
| 134 |
+
# st.session_state.user = None
|
| 135 |
+
|
| 136 |
+
# # Authentication UI
|
| 137 |
+
# def login():
|
| 138 |
+
# st.subheader("Login")
|
| 139 |
+
# email = st.text_input("Email")
|
| 140 |
+
# password = st.text_input("Password", type="password")
|
| 141 |
+
# if st.button("Login"):
|
| 142 |
+
# payload = {"email": email, "password": password, "returnSecureToken": True}
|
| 143 |
+
# response = requests.post(FIREBASE_AUTH_URL, json=payload)
|
| 144 |
+
# if response.status_code == 200:
|
| 145 |
+
# st.session_state.authenticated = True
|
| 146 |
+
# st.session_state.user = email
|
| 147 |
+
# st.rerun()
|
| 148 |
+
# else:
|
| 149 |
+
# st.error("Invalid credentials or user does not exist.")
|
| 150 |
+
|
| 151 |
+
# # Logout functionality
|
| 152 |
+
# def logout():
|
| 153 |
+
# st.session_state.authenticated = False
|
| 154 |
+
# st.session_state.user = None
|
| 155 |
+
# st.rerun()
|
| 156 |
+
|
| 157 |
+
# # Main Dashboard
|
| 158 |
+
# if st.session_state.authenticated:
|
| 159 |
+
# st.sidebar.button("Logout", on_click=logout)
|
| 160 |
+
# st.sidebar.header("Filters")
|
| 161 |
+
# filter_status = st.sidebar.selectbox("Filter by Status", ["All", "Pending", "Allocated", "Completed"], index=0)
|
| 162 |
+
|
| 163 |
+
# dustbins_ref = db.reference("dustbins")
|
| 164 |
+
# dustbins = dustbins_ref.get() or {}
|
| 165 |
+
|
| 166 |
+
# filtered_dustbins = {
|
| 167 |
+
# key: value for key, value in dustbins.items()
|
| 168 |
+
# if filter_status == "All" or value["status"] == filter_status
|
| 169 |
+
# }
|
| 170 |
+
|
| 171 |
+
# st.subheader(f"Showing {filter_status.lower()} dustbins ({len(filtered_dustbins)})")
|
| 172 |
+
|
| 173 |
+
# for key, value in filtered_dustbins.items():
|
| 174 |
+
# with st.expander(f"📍 {value['address']}"):
|
| 175 |
+
# st.write(f"**Latitude**: {value['latitude']}")
|
| 176 |
+
# st.write(f"**Longitude**: {value['longitude']}")
|
| 177 |
+
# st.write(f"**Status**: {value['status']}")
|
| 178 |
+
# # st.write(f"**User**: {value['user_email']}")
|
| 179 |
+
|
| 180 |
+
# # Display Image
|
| 181 |
+
# if "image" in value:
|
| 182 |
+
# image_data = base64.b64decode(value["image"])
|
| 183 |
+
# st.image(Image.open(BytesIO(image_data)), caption="Dustbin Image", use_column_width=True)
|
| 184 |
+
|
| 185 |
+
# if value["status"] == "Pending":
|
| 186 |
+
# truck_email = st.text_input(f"Allocate Truck Email for {key}", key=f"truck_{key}")
|
| 187 |
+
# if st.button(f"Allocate Truck", key=f"allocate_{key}"):
|
| 188 |
+
# if truck_email:
|
| 189 |
+
# dustbins_ref.child(key).update({
|
| 190 |
+
# "allocated_truck": truck_email,
|
| 191 |
+
# "status": "Allocated"
|
| 192 |
+
# })
|
| 193 |
+
# st.success("Truck allocated successfully!")
|
| 194 |
+
# else:
|
| 195 |
+
# st.error("Please enter a valid truck email.")
|
| 196 |
+
# else:
|
| 197 |
+
# login()
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
|
| 211 |
|
| 212 |
|
| 213 |
## Below code is working but it is not having login of admin. that is accessible to anyone..
|