Rammohan0504 commited on
Commit
cbcec2e
·
verified ·
1 Parent(s): 4c9ef03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -52
app.py CHANGED
@@ -1,66 +1,60 @@
1
  import gradio as gr
2
 
3
- # Sample in-memory database
4
  CUSTOMERS = {
5
- "john123": {"password": "password123", "name": "John Doe"}
6
  }
7
 
8
- # Function for handling login
9
- def login(username, password):
10
- if username in CUSTOMERS:
11
- if CUSTOMERS[username]["password"] == password:
12
- return f"Welcome back, {CUSTOMERS[username]['name']}!"
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  else:
14
  return "Incorrect password. Please try again."
15
- return "Username not found. Please register."
16
-
17
- # Function for handling registration
18
- def register(username, name, password):
19
- if username in CUSTOMERS:
20
- return "Username already exists. Please log in."
21
- if not (username and name and password):
22
- return "All fields are required for registration."
23
- CUSTOMERS[username] = {"password": password, "name": name}
24
- return f"Account created successfully for {name}!"
25
 
26
- # Gradio Blocks
27
  def main():
28
  with gr.Blocks() as demo:
29
- gr.HTML("""
30
- <div style='display: flex; height: 100vh; font-family: Arial, sans-serif;'>
31
- <div style='flex: 1; background: url("https://via.placeholder.com/600x800") no-repeat center center; background-size: cover; color: white; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;'>
32
- <h1 style='font-size: 3em;'>Biryani Hub</h1>
33
- <p>Sign in with</p>
34
- <div style='display: flex; gap: 10px;'>
35
- <a href='#' style='color: white;'>Facebook</a> |
36
- <a href='#' style='color: white;'>Twitter</a> |
37
- <a href='#' style='color: white;'>Instagram</a>
38
- </div>
39
- </div>
40
- <div style='flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; background: linear-gradient(to bottom, #ff7e5f, #feb47b); border-radius: 10px; color: white;'>
41
- <div style='width: 80%;'>
42
- <h2 style='text-align: center;'>Log In</h2>
43
- </div>
44
- </div>
45
- </div>
46
- """)
47
 
48
- with gr.Row():
49
- with gr.Column():
50
- gr.Markdown("### Log In")
51
- login_username = gr.Textbox(label="Username", placeholder="Enter your username")
52
- login_password = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
53
- login_button = gr.Button("Log In")
54
- login_output = gr.Text(label="Login Status")
55
- login_button.click(login, inputs=[login_username, login_password], outputs=login_output)
56
- with gr.Column():
57
- gr.Markdown("### Register")
58
- register_username = gr.Textbox(label="Username", placeholder="Choose a username")
59
- register_name = gr.Textbox(label="Name", placeholder="Enter your name")
60
- register_password = gr.Textbox(label="Password", placeholder="Set your password", type="password")
61
- register_button = gr.Button("Register")
62
- register_output = gr.Text(label="Registration Status")
63
- register_button.click(register, inputs=[register_username, register_name, register_password], outputs=register_output)
64
 
65
  demo.launch()
66
 
 
1
  import gradio as gr
2
 
3
+ # Sample in-memory database for demonstration
4
  CUSTOMERS = {
5
+ "9876543210": {"name": "John Doe", "email": "john@example.com", "password": "password123"}
6
  }
7
 
8
+ def login_or_signup(phone_number, name=None, email=None, password=None):
9
+ """
10
+ Handles login or sign-up for customers.
11
+
12
+ Args:
13
+ phone_number (str): Customer's phone number.
14
+ name (str, optional): Customer's name (required for sign-up).
15
+ email (str, optional): Customer's email (required for sign-up).
16
+ password (str, optional): Customer's password (required for both login and sign-up).
17
+
18
+ Returns:
19
+ str: Status message about login or sign-up.
20
+ """
21
+ # Check if phone number exists in the database
22
+ if phone_number in CUSTOMERS:
23
+ # Customer exists, check for login
24
+ if CUSTOMERS[phone_number]["password"] == password:
25
+ return f"Welcome back, {CUSTOMERS[phone_number]['name']}!"
26
  else:
27
  return "Incorrect password. Please try again."
28
+ else:
29
+ # New customer, proceed with sign-up
30
+ if not all([name, email, password]):
31
+ return "Missing details for sign-up. Please provide Name, Email, and Password."
32
+ CUSTOMERS[phone_number] = {"name": name, "email": email, "password": password}
33
+ return f"Account created successfully for {name}!"
 
 
 
 
34
 
35
+ # Gradio Interface
36
  def main():
37
  with gr.Blocks() as demo:
38
+ gr.Markdown("### Login or Sign-Up")
39
+
40
+ # Input fields for phone number
41
+ phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
42
+
43
+ # New customer details
44
+ name_input = gr.Textbox(label="Name (For New Customers)", placeholder="Enter your name")
45
+ email_input = gr.Textbox(label="Email (For New Customers)", placeholder="Enter your email")
46
+ password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
47
+
48
+ # Action button
49
+ action_button = gr.Button("Submit")
50
+ result_output = gr.Text(label="Status")
 
 
 
 
 
51
 
52
+ # Function binding
53
+ action_button.click(
54
+ login_or_signup,
55
+ inputs=[phone_input, name_input, email_input, password_input],
56
+ outputs=result_output
57
+ )
 
 
 
 
 
 
 
 
 
 
58
 
59
  demo.launch()
60