Rammohan0504 commited on
Commit
78b574e
·
verified ·
1 Parent(s): cbcec2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -34
app.py CHANGED
@@ -1,15 +1,36 @@
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).
@@ -18,43 +39,71 @@ def login_or_signup(phone_number, name=None, email=None, password=None):
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
 
 
1
  import gradio as gr
2
+ import qrcode
3
+ from PIL import Image
4
 
5
+ # Sample Data
6
  CUSTOMERS = {
7
  "9876543210": {"name": "John Doe", "email": "john@example.com", "password": "password123"}
8
  }
9
 
10
+ MENU = {
11
+ "ALL": [
12
+ {"name": "Chicken Curry", "description": "Spicy chicken curry", "image": "chicken_curry.jpg", "spice_levels": ["Mild", "Medium", "Hot"], "portion_sizes": ["Small", "Medium", "Large"]},
13
+ {"name": "Paneer Butter Masala", "description": "Creamy paneer dish", "image": "paneer_butter.jpg", "spice_levels": ["Mild", "Medium", "Hot"], "portion_sizes": ["Small", "Medium", "Large"]}
14
+ ]
15
+ }
16
+
17
+ # Generate QR Code
18
+
19
+ def generate_qr(table_id):
20
+ qr = qrcode.QRCode(box_size=10, border=5)
21
+ qr.add_data(f"http://restaurant.com/table/{table_id}")
22
+ qr.make(fit=True)
23
+ img = qr.make_image(fill="black", back_color="white")
24
+ return img
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
 
 
60
  def main():
61
  with gr.Blocks() as demo:
62
+ gr.Markdown("# Welcome to Biryani Hub")
63
+
64
+ # QR Code Generator
65
+ with gr.Tab("QR Code Generator"):
66
+ table_id = gr.Textbox(label="Table ID", placeholder="Enter table ID")
67
+ qr_button = gr.Button("Generate QR Code")
68
+ qr_output = gr.Image(label="QR Code")
69
+ qr_button.click(lambda table_id: generate_qr(table_id), inputs=table_id, outputs=qr_output)
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.Checkbox(label="New Customer", value=True)
75
+ phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
76
+ name_input = gr.Textbox(label="Name", placeholder="Enter your name", visible=True)
77
+ email_input = gr.Textbox(label="Email", placeholder="Enter your email", visible=True)
78
+ password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
79
+ username_input = gr.Textbox(label="Username", placeholder="Enter your username", visible=False)
80
+
81
+ def toggle_fields(is_new):
82
+ return (
83
+ is_new, # Show name input
84
+ is_new, # Show email input
85
+ not is_new # Show username input for existing customers
86
+ )
87
+
88
+ is_new_customer.change(
89
+ toggle_fields,
90
+ inputs=[is_new_customer],
91
+ outputs=[name_input, email_input, username_input]
92
+ )
93
+
94
+ action_button = gr.Button("Submit")
95
+ result_output = gr.Text(label="Status")
96
+
97
+ def handle_input(is_new, phone, name, email, password, username):
98
+ if not is_new:
99
+ name, email = None, None # Ignore name and email for existing customers
100
+ return login_or_signup(is_new, phone, name, email, password)
101
+
102
+ action_button.click(
103
+ handle_input,
104
+ inputs=[is_new_customer, phone_input, name_input, email_input, password_input, username_input],
105
+ outputs=result_output
106
+ )
107
 
108
  demo.launch()
109