geethareddy commited on
Commit
566fb77
·
verified ·
1 Parent(s): 81b77b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -0
app.py CHANGED
@@ -1,5 +1,93 @@
1
  import gradio as gr
2
  import pandas as pd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  # Initialize global cart
5
  cart_items = []
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import gradio as gr
4
+ from utils.database_handler import check_credentials, save_user
5
+
6
+
7
+ def app_interface():
8
+ # Login Button Actions
9
+ def authenticate_user(email, password):
10
+ if check_credentials(email, password):
11
+ return (
12
+ gr.update(visible=False), # Hide login page
13
+ gr.update(visible=True), # Show preferences page
14
+ "", # Clear any error message
15
+ )
16
+ else:
17
+ return (
18
+ gr.update(visible=True), # Show error box
19
+ gr.update(visible=False), # Keep preferences page hidden
20
+ "Invalid email or password. Try again.", # Error message
21
+ )
22
+
23
+ def navigate_to_signup():
24
+ return gr.update(visible=False), gr.update(visible=True)
25
+
26
+ def create_account(name, phone, email, password):
27
+ if save_user(name, phone, email, password):
28
+ return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
29
+ else:
30
+ return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True)
31
+
32
+ def navigate_to_login():
33
+ return gr.update(visible=True), gr.update(visible=False)
34
+
35
+ with gr.Blocks() as app:
36
+ # Login Page
37
+ with gr.Column(visible=True) as login_section:
38
+ gr.Markdown("# Login Page")
39
+ email = gr.Textbox(label="Email", placeholder="Enter your email")
40
+ password = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
41
+ error_box = gr.Markdown("", visible=False)
42
+ login_btn = gr.Button("Login")
43
+ create_account_btn = gr.Button("Create an Account")
44
+
45
+ # Sign-Up Page
46
+ with gr.Column(visible=False) as signup_section:
47
+ gr.Markdown("# Sign Up Page")
48
+ name = gr.Textbox(label="Name", placeholder="Enter your full name")
49
+ phone = gr.Textbox(label="Phone", placeholder="Enter your phone number")
50
+ signup_email = gr.Textbox(label="Email", placeholder="Enter your email")
51
+ signup_password = gr.Textbox(label="Password", placeholder="Enter a password", type="password")
52
+ success_message = gr.Markdown("", visible=False)
53
+ error_message = gr.Markdown("", visible=False)
54
+ submit_btn = gr.Button("Sign Up")
55
+ back_to_login_btn = gr.Button("Back to Login")
56
+
57
+ # Preferences Page
58
+ with gr.Column(visible=False) as preference_section:
59
+ gr.Markdown("# Preferences Page")
60
+
61
+ # Button Actions for Login
62
+ login_btn.click(
63
+ authenticate_user,
64
+ inputs=[email, password],
65
+ outputs=[login_section, preference_section, error_box],
66
+ )
67
+ create_account_btn.click(
68
+ navigate_to_signup,
69
+ inputs=[],
70
+ outputs=[login_section, signup_section],
71
+ )
72
+
73
+ # Button Actions for Sign-Up
74
+ submit_btn.click(
75
+ create_account,
76
+ inputs=[name, phone, signup_email, signup_password],
77
+ outputs=[success_message, signup_section, login_section],
78
+ )
79
+ back_to_login_btn.click(
80
+ navigate_to_login,
81
+ inputs=[],
82
+ outputs=[login_section, signup_section],
83
+ )
84
+
85
+ return app
86
+
87
+
88
+ if __name__ == "__main__":
89
+ app = app_interface()
90
+ app.launch()
91
 
92
  # Initialize global cart
93
  cart_items = []