Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -284,24 +284,6 @@ button {
|
|
284 |
alert("Your final order has been submitted!");
|
285 |
}
|
286 |
</script>
|
287 |
-
def authenticate_user(email, password):
|
288 |
-
if check_credentials(email, password):
|
289 |
-
return gr.update(visible=False), gr.update(visible=True), ""
|
290 |
-
else:
|
291 |
-
return gr.update(visible=True), gr.update(visible=False), "Invalid email or password. Try again."
|
292 |
-
|
293 |
-
def navigate_to_signup():
|
294 |
-
return gr.update(visible=False), gr.update(visible=True)
|
295 |
-
|
296 |
-
def create_account(name, phone, email, password):
|
297 |
-
if save_user(name, phone, email, password):
|
298 |
-
return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
|
299 |
-
else:
|
300 |
-
return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True)
|
301 |
-
|
302 |
-
def navigate_to_login():
|
303 |
-
return gr.update(visible=True), gr.update(visible=False)
|
304 |
-
|
305 |
"""
|
306 |
# Authentication and Navigation Logic
|
307 |
def authenticate_user(email, password):
|
@@ -321,18 +303,10 @@ def create_account(name, phone, email, password):
|
|
321 |
|
322 |
def navigate_to_login():
|
323 |
return gr.update(visible=True), gr.update(visible=False)
|
324 |
-
SCROLL_TO_TOP_JS = """
|
325 |
-
<script>
|
326 |
-
function scrollToTop() {
|
327 |
-
window.scrollTo({ top: 0, behavior: 'smooth' });
|
328 |
-
}
|
329 |
-
</script>
|
330 |
-
"""
|
331 |
|
332 |
# Gradio App
|
333 |
def app():
|
334 |
with gr.Blocks() as demo:
|
335 |
-
gr.HTML(SCROLL_TO_TOP_JS)
|
336 |
# Login Page
|
337 |
with gr.Column(visible=True) as login_section:
|
338 |
gr.Markdown("# Login Page")
|
@@ -357,6 +331,9 @@ def app():
|
|
357 |
with gr.Column(visible=False) as menu_section:
|
358 |
gr.Markdown("### Menu Page (Accessible Only After Login)")
|
359 |
|
|
|
|
|
|
|
360 |
# Radio button for selecting preference
|
361 |
selected_preference = gr.Radio(
|
362 |
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt Free"],
|
@@ -368,11 +345,11 @@ def app():
|
|
368 |
# Output area for menu items
|
369 |
menu_output = gr.HTML(value=filter_menu("All"))
|
370 |
|
371 |
-
#
|
372 |
-
|
373 |
empty_div = gr.HTML('<div style="height: 300px;"></div>')
|
374 |
|
375 |
-
|
376 |
modal_window = gr.HTML("""
|
377 |
<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;">
|
378 |
<div style="text-align: right;">
|
@@ -403,16 +380,19 @@ def app():
|
|
403 |
<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>
|
404 |
</div>
|
405 |
""")
|
|
|
406 |
# Update menu dynamically based on preference
|
407 |
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
408 |
|
409 |
# Layout
|
|
|
410 |
gr.Row([selected_preference])
|
411 |
gr.Row(menu_output)
|
|
|
412 |
gr.Row(modal_window)
|
413 |
gr.HTML(modal_and_cart_js)
|
414 |
|
415 |
-
|
416 |
with gr.Column(visible=False) as cart_section:
|
417 |
gr.Markdown("### Cart & Final Order Page")
|
418 |
|
@@ -451,8 +431,12 @@ def app():
|
|
451 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
452 |
outputs=[login_section, signup_section],
|
453 |
)
|
454 |
-
# Navigate to Cart Page
|
455 |
-
|
|
|
|
|
|
|
|
|
456 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
457 |
outputs=[menu_section, cart_section],
|
458 |
)
|
|
|
284 |
alert("Your final order has been submitted!");
|
285 |
}
|
286 |
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
"""
|
288 |
# Authentication and Navigation Logic
|
289 |
def authenticate_user(email, password):
|
|
|
303 |
|
304 |
def navigate_to_login():
|
305 |
return gr.update(visible=True), gr.update(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
|
307 |
# Gradio App
|
308 |
def app():
|
309 |
with gr.Blocks() as demo:
|
|
|
310 |
# Login Page
|
311 |
with gr.Column(visible=True) as login_section:
|
312 |
gr.Markdown("# Login Page")
|
|
|
331 |
with gr.Column(visible=False) as menu_section:
|
332 |
gr.Markdown("### Menu Page (Accessible Only After Login)")
|
333 |
|
334 |
+
# View Cart Button (Top Position)
|
335 |
+
view_cart_button_top = gr.Button("View Cart")
|
336 |
+
|
337 |
# Radio button for selecting preference
|
338 |
selected_preference = gr.Radio(
|
339 |
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt Free"],
|
|
|
345 |
# Output area for menu items
|
346 |
menu_output = gr.HTML(value=filter_menu("All"))
|
347 |
|
348 |
+
# View Cart Button (Original Position)
|
349 |
+
view_cart_button_bottom = gr.Button("View Cart")
|
350 |
empty_div = gr.HTML('<div style="height: 300px;"></div>')
|
351 |
|
352 |
+
# Modal window
|
353 |
modal_window = gr.HTML("""
|
354 |
<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;">
|
355 |
<div style="text-align: right;">
|
|
|
380 |
<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>
|
381 |
</div>
|
382 |
""")
|
383 |
+
|
384 |
# Update menu dynamically based on preference
|
385 |
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
386 |
|
387 |
# Layout
|
388 |
+
gr.Row(view_cart_button_top) # View Cart button at the top
|
389 |
gr.Row([selected_preference])
|
390 |
gr.Row(menu_output)
|
391 |
+
gr.Row(view_cart_button_bottom) # View Cart button at the bottom
|
392 |
gr.Row(modal_window)
|
393 |
gr.HTML(modal_and_cart_js)
|
394 |
|
395 |
+
# Cart & Final Order Page
|
396 |
with gr.Column(visible=False) as cart_section:
|
397 |
gr.Markdown("### Cart & Final Order Page")
|
398 |
|
|
|
431 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
432 |
outputs=[login_section, signup_section],
|
433 |
)
|
434 |
+
# Navigate to Cart Page (Both Buttons Use the Same Logic)
|
435 |
+
view_cart_button_top.click(
|
436 |
+
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
437 |
+
outputs=[menu_section, cart_section],
|
438 |
+
)
|
439 |
+
view_cart_button_bottom.click(
|
440 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
441 |
outputs=[menu_section, cart_section],
|
442 |
)
|