Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ def load_users():
|
|
11 |
df = pd.read_excel(USER_FILE)
|
12 |
return {row['Email']: row for _, row in df.iterrows()}
|
13 |
except FileNotFoundError:
|
|
|
14 |
df = pd.DataFrame(columns=["Name", "Phone", "Email", "Password"])
|
15 |
df.to_excel(USER_FILE, index=False)
|
16 |
return {}
|
@@ -24,37 +25,19 @@ def save_users(users):
|
|
24 |
def signup_user(name, phone, email, password):
|
25 |
users = load_users()
|
26 |
if email in users:
|
27 |
-
return "Email already exists. Please use a different email."
|
28 |
hashed_password = hashpw(password.encode(), gensalt()).decode()
|
29 |
users[email] = {"Name": name, "Phone": phone, "Email": email, "Password": hashed_password}
|
30 |
save_users(users)
|
31 |
-
return "Signup successful!
|
32 |
|
33 |
# Validate login
|
34 |
def validate_login(email, password):
|
35 |
users = load_users()
|
36 |
if email in users and checkpw(password.encode(), users[email]["Password"].encode()):
|
37 |
-
return
|
38 |
-
return
|
39 |
|
40 |
-
# Session management
|
41 |
-
active_sessions = {}
|
42 |
-
|
43 |
-
def login_user(email, password):
|
44 |
-
success, message = validate_login(email, password)
|
45 |
-
if success:
|
46 |
-
active_sessions[email] = True
|
47 |
-
return message
|
48 |
-
return message
|
49 |
-
|
50 |
-
def is_logged_in(email):
|
51 |
-
return active_sessions.get(email, False)
|
52 |
-
|
53 |
-
def logout_user(email):
|
54 |
-
if email in active_sessions:
|
55 |
-
del active_sessions[email]
|
56 |
-
return "Logged out successfully!"
|
57 |
-
return "No active session found for this email."
|
58 |
# Function to load the menu data
|
59 |
def load_menu():
|
60 |
menu_file = "menu.xlsx" # Ensure this file exists in the same directory
|
@@ -273,125 +256,113 @@ modal_and_cart_js = """
|
|
273 |
}
|
274 |
</script>
|
275 |
"""
|
276 |
-
|
277 |
-
|
278 |
-
# Gradio app
|
279 |
def app():
|
280 |
with gr.Blocks() as demo:
|
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 |
-
# Final order display
|
349 |
-
final_order_output = gr.HTML(value="", elem_id="final-order")
|
350 |
-
|
351 |
-
# Modal window
|
352 |
-
modal_window = gr.HTML("""
|
353 |
-
<div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
|
354 |
-
<div style="text-align: right;">
|
355 |
-
<button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button>
|
356 |
-
</div>
|
357 |
-
<img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" />
|
358 |
-
<h2 id="modal-name"></h2>
|
359 |
-
<p id="modal-description"></p>
|
360 |
-
<p id="modal-price"></p>
|
361 |
-
<!-- Biryani Extras -->
|
362 |
-
<label for="biryani-extras">Biryani Extras :</label>
|
363 |
-
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
364 |
-
<label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label>
|
365 |
-
<label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label>
|
366 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label>
|
367 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label>
|
368 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
|
369 |
-
<label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label>
|
370 |
-
<label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label>
|
371 |
-
</div>
|
372 |
-
<!-- Quantity and Special Instructions -->
|
373 |
-
<label for="quantity">Quantity:</label>
|
374 |
-
<input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
|
375 |
-
<br><br>
|
376 |
-
<textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
|
377 |
-
<br><br>
|
378 |
-
<!-- Add to Cart Button -->
|
379 |
-
<button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
|
380 |
</div>
|
381 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
|
383 |
-
|
384 |
-
|
385 |
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
|
394 |
-
|
395 |
|
396 |
|
397 |
if __name__ == "__main__":
|
|
|
11 |
df = pd.read_excel(USER_FILE)
|
12 |
return {row['Email']: row for _, row in df.iterrows()}
|
13 |
except FileNotFoundError:
|
14 |
+
# Create the file if it doesn't exist
|
15 |
df = pd.DataFrame(columns=["Name", "Phone", "Email", "Password"])
|
16 |
df.to_excel(USER_FILE, index=False)
|
17 |
return {}
|
|
|
25 |
def signup_user(name, phone, email, password):
|
26 |
users = load_users()
|
27 |
if email in users:
|
28 |
+
return "Email already exists. Please use a different email.", "signup" # Redirect to signup
|
29 |
hashed_password = hashpw(password.encode(), gensalt()).decode()
|
30 |
users[email] = {"Name": name, "Phone": phone, "Email": email, "Password": hashed_password}
|
31 |
save_users(users)
|
32 |
+
return "Signup successful! Redirecting to login page...", "login" # Redirect to login
|
33 |
|
34 |
# Validate login
|
35 |
def validate_login(email, password):
|
36 |
users = load_users()
|
37 |
if email in users and checkpw(password.encode(), users[email]["Password"].encode()):
|
38 |
+
return "Login successful! Redirecting to menu page...", "menu" # Redirect to menu
|
39 |
+
return "Invalid email or password. Please try again.", "login" # Redirect to login
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
# Function to load the menu data
|
42 |
def load_menu():
|
43 |
menu_file = "menu.xlsx" # Ensure this file exists in the same directory
|
|
|
256 |
}
|
257 |
</script>
|
258 |
"""
|
|
|
|
|
|
|
259 |
def app():
|
260 |
with gr.Blocks() as demo:
|
261 |
+
# State to track the current page
|
262 |
+
current_page = gr.State("login") # Default page is the login page
|
263 |
+
|
264 |
+
# === LOGIN PAGE ===
|
265 |
+
with gr.Row(visible_if=lambda x: x == "login", inputs=[current_page]):
|
266 |
+
gr.Markdown("### Login Page")
|
267 |
+
login_email = gr.Textbox(label="Email")
|
268 |
+
login_password = gr.Textbox(label="Password", type="password")
|
269 |
+
login_btn = gr.Button("Login")
|
270 |
+
login_message = gr.Label()
|
271 |
+
|
272 |
+
def login(email, password):
|
273 |
+
message, page = validate_login(email, password)
|
274 |
+
return message, page # Redirect based on login status
|
275 |
+
|
276 |
+
login_btn.click(
|
277 |
+
login,
|
278 |
+
inputs=[login_email, login_password],
|
279 |
+
outputs=[login_message, current_page], # Update message and page
|
280 |
+
)
|
281 |
+
|
282 |
+
# === SIGNUP PAGE ===
|
283 |
+
with gr.Row(visible_if=lambda x: x == "signup", inputs=[current_page]):
|
284 |
+
gr.Markdown("### Signup Page")
|
285 |
+
name = gr.Textbox(label="Name")
|
286 |
+
phone = gr.Textbox(label="Phone Number")
|
287 |
+
email = gr.Textbox(label="Email")
|
288 |
+
password = gr.Textbox(label="Password", type="password")
|
289 |
+
signup_btn = gr.Button("Signup")
|
290 |
+
signup_message = gr.Label()
|
291 |
+
|
292 |
+
def signup(name, phone, email, password):
|
293 |
+
message, page = signup_user(name, phone, email, password)
|
294 |
+
return message, page # Redirect to login after signup
|
295 |
+
|
296 |
+
signup_btn.click(
|
297 |
+
signup,
|
298 |
+
inputs=[name, phone, email, password],
|
299 |
+
outputs=[signup_message, current_page], # Update message and page
|
300 |
+
)
|
301 |
+
|
302 |
+
# === MENU PAGE ===
|
303 |
+
with gr.Row(visible_if=lambda x: x == "menu", inputs=[current_page]):
|
304 |
+
gr.Markdown("### Menu Page")
|
305 |
+
|
306 |
+
# Radio button for selecting preference
|
307 |
+
selected_preference = gr.Radio(
|
308 |
+
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
309 |
+
value="All",
|
310 |
+
label="Choose a Preference",
|
311 |
+
)
|
312 |
+
|
313 |
+
# Output area for menu items
|
314 |
+
menu_output = gr.HTML(value=filter_menu("All"))
|
315 |
+
|
316 |
+
# Floating cart display
|
317 |
+
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
318 |
+
|
319 |
+
# Final order display
|
320 |
+
final_order_output = gr.HTML(value="", elem_id="final-order")
|
321 |
+
|
322 |
+
# Modal window
|
323 |
+
modal_window = gr.HTML("""
|
324 |
+
<div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
|
325 |
+
<div style="text-align: right;">
|
326 |
+
<button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
327 |
</div>
|
328 |
+
<img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" />
|
329 |
+
<h2 id="modal-name"></h2>
|
330 |
+
<p id="modal-description"></p>
|
331 |
+
<p id="modal-price"></p>
|
332 |
+
<!-- Biryani Extras -->
|
333 |
+
<label for="biryani-extras">Biryani Extras :</label>
|
334 |
+
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
335 |
+
<label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label>
|
336 |
+
<label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label>
|
337 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label>
|
338 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label>
|
339 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
|
340 |
+
<label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label>
|
341 |
+
<label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label>
|
342 |
+
</div>
|
343 |
+
<!-- Quantity and Special Instructions -->
|
344 |
+
<label for="quantity">Quantity:</label>
|
345 |
+
<input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
|
346 |
+
<br><br>
|
347 |
+
<textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
|
348 |
+
<br><br>
|
349 |
+
<!-- Add to Cart Button -->
|
350 |
+
<button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
|
351 |
+
</div>
|
352 |
+
""")
|
353 |
|
354 |
+
# Update menu dynamically based on preference
|
355 |
+
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
356 |
|
357 |
+
# Layout
|
358 |
+
gr.Row([selected_preference])
|
359 |
+
gr.Row(menu_output)
|
360 |
+
gr.Row(cart_output)
|
361 |
+
gr.Row(modal_window)
|
362 |
+
gr.Row(final_order_output)
|
363 |
+
gr.HTML(modal_and_cart_js)
|
364 |
|
365 |
+
return demo
|
366 |
|
367 |
|
368 |
if __name__ == "__main__":
|