Rammohan0504 commited on
Commit
1f6fe47
·
verified ·
1 Parent(s): 964b187

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -25,11 +25,12 @@ def generate_qr(table_id):
25
 
26
  # Login or Signup
27
 
28
- def login_or_signup(phone_number, name=None, email=None, password=None):
29
  """
30
  Handles login or sign-up for customers.
31
 
32
  Args:
 
33
  phone_number (str): Customer's phone number.
34
  name (str, optional): Customer's name (required for sign-up).
35
  email (str, optional): Customer's email (required for sign-up).
@@ -38,19 +39,21 @@ def login_or_signup(phone_number, name=None, email=None, password=None):
38
  Returns:
39
  str: Status message about login or sign-up.
40
  """
41
- # Check if phone number exists in the database
42
- if phone_number in CUSTOMERS:
43
- # Customer exists, check for login
44
- if CUSTOMERS[phone_number]["password"] == password:
45
- return f"Welcome back, {CUSTOMERS[phone_number]['name']}!"
46
- else:
47
- return "Incorrect password. Please try again."
48
- else:
49
  # New customer, proceed with sign-up
50
- if not all([name, email, password]):
51
- return "Missing details for sign-up. Please provide Name, Email, and Password."
52
  CUSTOMERS[phone_number] = {"name": name, "email": email, "password": password}
53
  return f"Account created successfully for {name}!"
 
 
 
 
 
 
 
 
 
54
 
55
  # Gradio Interfaces
56
 
@@ -67,6 +70,8 @@ def main():
67
 
68
  # Login or Signup
69
  with gr.Tab("Login / Signup"):
 
 
70
  phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
71
  name_input = gr.Textbox(label="Name (For New Customers)", placeholder="Enter your name")
72
  email_input = gr.Textbox(label="Email (For New Customers)", placeholder="Enter your email")
@@ -75,9 +80,13 @@ def main():
75
  action_button = gr.Button("Submit")
76
  result_output = gr.Text(label="Status")
77
 
 
 
 
 
78
  action_button.click(
79
- login_or_signup,
80
- inputs=[phone_input, name_input, email_input, password_input],
81
  outputs=result_output
82
  )
83
 
 
25
 
26
  # Login or Signup
27
 
28
+ def login_or_signup(is_new_customer, phone_number, name=None, email=None, password=None):
29
  """
30
  Handles login or sign-up for customers.
31
 
32
  Args:
33
+ is_new_customer (bool): Whether the user is a new customer.
34
  phone_number (str): Customer's phone number.
35
  name (str, optional): Customer's name (required for sign-up).
36
  email (str, optional): Customer's email (required for sign-up).
 
39
  Returns:
40
  str: Status message about login or sign-up.
41
  """
42
+ if is_new_customer:
 
 
 
 
 
 
 
43
  # New customer, proceed with sign-up
44
+ if not all([phone_number, name, email, password]):
45
+ return "Missing details for sign-up. Please provide Name, Email, Phone Number, and Password."
46
  CUSTOMERS[phone_number] = {"name": name, "email": email, "password": password}
47
  return f"Account created successfully for {name}!"
48
+ else:
49
+ # Existing customer, proceed with login
50
+ if phone_number in CUSTOMERS:
51
+ if CUSTOMERS[phone_number]["password"] == password:
52
+ return f"Welcome back, {CUSTOMERS[phone_number]['name']}!"
53
+ else:
54
+ return "Incorrect password. Please try again."
55
+ else:
56
+ return "Phone number not found. Please sign up."
57
 
58
  # Gradio Interfaces
59
 
 
70
 
71
  # Login or Signup
72
  with gr.Tab("Login / Signup"):
73
+ gr.Markdown("## Are you a new or existing customer?")
74
+ is_new_customer = gr.Radio(["New Customer", "Existing Customer"], label="Select Customer Type")
75
  phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
76
  name_input = gr.Textbox(label="Name (For New Customers)", placeholder="Enter your name")
77
  email_input = gr.Textbox(label="Email (For New Customers)", placeholder="Enter your email")
 
80
  action_button = gr.Button("Submit")
81
  result_output = gr.Text(label="Status")
82
 
83
+ def handle_input(customer_type, phone, name, email, password):
84
+ is_new = customer_type == "New Customer"
85
+ return login_or_signup(is_new, phone, name, email, password)
86
+
87
  action_button.click(
88
+ handle_input,
89
+ inputs=[is_new_customer, phone_input, name_input, email_input, password_input],
90
  outputs=result_output
91
  )
92