Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -270,21 +270,18 @@ modal_and_cart_js = """
|
|
270 |
"""
|
271 |
|
272 |
|
|
|
273 |
# Gradio app
|
274 |
def app():
|
275 |
with gr.Blocks() as demo:
|
276 |
gr.Markdown("## Secure Food Ordering System")
|
277 |
|
278 |
-
# State
|
279 |
current_page = gr.State("signup") # Default page is Signup
|
|
|
280 |
|
281 |
-
#
|
282 |
-
|
283 |
-
login_page = gr.Column(visible=False)
|
284 |
-
menu_page = gr.Column(visible=False)
|
285 |
-
|
286 |
-
# Signup Page Logic
|
287 |
-
with signup_page:
|
288 |
gr.Markdown("### Signup Page")
|
289 |
name = gr.Textbox(label="Name")
|
290 |
phone = gr.Textbox(label="Phone Number")
|
@@ -296,7 +293,6 @@ def app():
|
|
296 |
# Signup callback
|
297 |
def handle_signup(name, phone, email, password):
|
298 |
message, next_page = signup_user(name, phone, email, password)
|
299 |
-
# Update visibility for redirection
|
300 |
if next_page == "login":
|
301 |
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), message
|
302 |
return gr.update(), gr.update(), gr.update(), message
|
@@ -307,8 +303,8 @@ def app():
|
|
307 |
outputs=[signup_page, login_page, menu_page, signup_message],
|
308 |
)
|
309 |
|
310 |
-
# Login Page
|
311 |
-
with login_page:
|
312 |
gr.Markdown("### Login Page")
|
313 |
login_email = gr.Textbox(label="Email")
|
314 |
login_password = gr.Textbox(label="Password", type="password")
|
@@ -317,20 +313,20 @@ def app():
|
|
317 |
|
318 |
# Login callback
|
319 |
def handle_login(email, password):
|
320 |
-
message, next_page =
|
321 |
-
# Update visibility for redirection
|
322 |
if next_page == "menu":
|
323 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), message
|
324 |
-
return gr.update(), gr.update(), gr.update(), message
|
325 |
|
326 |
login_btn.click(
|
327 |
handle_login,
|
328 |
inputs=[login_email, login_password],
|
329 |
-
outputs=[signup_page, login_page, menu_page, login_message],
|
330 |
)
|
331 |
|
332 |
-
# Menu Page
|
333 |
-
with menu_page:
|
|
|
334 |
gr.Markdown("### Menu Page (Accessible Only After Login)")
|
335 |
|
336 |
# Radio button for selecting preference
|
@@ -392,7 +388,34 @@ def app():
|
|
392 |
gr.Row(final_order_output)
|
393 |
gr.HTML(modal_and_cart_js)
|
394 |
|
395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
|
397 |
|
398 |
if __name__ == "__main__":
|
|
|
270 |
"""
|
271 |
|
272 |
|
273 |
+
# Gradio app
|
274 |
# Gradio app
|
275 |
def app():
|
276 |
with gr.Blocks() as demo:
|
277 |
gr.Markdown("## Secure Food Ordering System")
|
278 |
|
279 |
+
# State variables to track the current page and active user
|
280 |
current_page = gr.State("signup") # Default page is Signup
|
281 |
+
active_user = gr.State(None) # No user is active initially
|
282 |
|
283 |
+
# Signup Page
|
284 |
+
with gr.Row(visible=True) as signup_page:
|
|
|
|
|
|
|
|
|
|
|
285 |
gr.Markdown("### Signup Page")
|
286 |
name = gr.Textbox(label="Name")
|
287 |
phone = gr.Textbox(label="Phone Number")
|
|
|
293 |
# Signup callback
|
294 |
def handle_signup(name, phone, email, password):
|
295 |
message, next_page = signup_user(name, phone, email, password)
|
|
|
296 |
if next_page == "login":
|
297 |
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), message
|
298 |
return gr.update(), gr.update(), gr.update(), message
|
|
|
303 |
outputs=[signup_page, login_page, menu_page, signup_message],
|
304 |
)
|
305 |
|
306 |
+
# Login Page
|
307 |
+
with gr.Row(visible=False) as login_page:
|
308 |
gr.Markdown("### Login Page")
|
309 |
login_email = gr.Textbox(label="Email")
|
310 |
login_password = gr.Textbox(label="Password", type="password")
|
|
|
313 |
|
314 |
# Login callback
|
315 |
def handle_login(email, password):
|
316 |
+
message, next_page = validate_login(email, password)
|
|
|
317 |
if next_page == "menu":
|
318 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), email, message
|
319 |
+
return gr.update(), gr.update(), gr.update(), None, message
|
320 |
|
321 |
login_btn.click(
|
322 |
handle_login,
|
323 |
inputs=[login_email, login_password],
|
324 |
+
outputs=[signup_page, login_page, menu_page, active_user, login_message],
|
325 |
)
|
326 |
|
327 |
+
# Menu Page
|
328 |
+
with gr.Row(visible=False) as menu_page:
|
329 |
+
# Adding your original code here without any changes
|
330 |
gr.Markdown("### Menu Page (Accessible Only After Login)")
|
331 |
|
332 |
# Radio button for selecting preference
|
|
|
388 |
gr.Row(final_order_output)
|
389 |
gr.HTML(modal_and_cart_js)
|
390 |
|
391 |
+
logout_btn = gr.Button("Logout")
|
392 |
+
|
393 |
+
# Logout callback
|
394 |
+
def handle_logout():
|
395 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), None
|
396 |
+
|
397 |
+
logout_btn.click(
|
398 |
+
handle_logout,
|
399 |
+
outputs=[signup_page, login_page, menu_page, active_user],
|
400 |
+
)
|
401 |
+
|
402 |
+
# Show the appropriate page based on the current state
|
403 |
+
def show_page(page):
|
404 |
+
if page == "signup":
|
405 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
406 |
+
elif page == "login":
|
407 |
+
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
408 |
+
elif page == "menu":
|
409 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
410 |
+
|
411 |
+
# Initial visibility setup
|
412 |
+
demo.load(
|
413 |
+
show_page,
|
414 |
+
inputs=[current_page],
|
415 |
+
outputs=[signup_page, login_page, menu_page],
|
416 |
+
)
|
417 |
+
|
418 |
+
return demo
|
419 |
|
420 |
|
421 |
if __name__ == "__main__":
|