Rammohan0504 commited on
Commit
ff72661
·
verified ·
1 Parent(s): 09ac4f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -105
app.py CHANGED
@@ -1,111 +1,54 @@
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).
37
- password (str, optional): Customer's password (required for both login and sign-up).
38
-
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
-
110
- if __name__ == "__main__":
111
- main()
 
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
+ # Custom HTML and CSS for the UI
27
+ HTML = """
28
+ <div class="container">
29
+ <div class="left">
30
+ <h1>Biryani Hub</h1>
31
+ <img src="https://via.placeholder.com/300" alt="Food Image">
32
+ <p>Sign in with</p>
33
+ <div class="social-icons">
34
+ <i>Facebook</i> | <i>Twitter</i> | <i>Instagram</i>
35
+ </div>
36
+ </div>
37
+ <div class="right">
38
+ <div class="tab">
39
+ <button onclick="document.getElementById('login').style.display='block'; document.getElementById('register').style.display='none';">Log In</button>
40
+ <button onclick="document.getElementById('register').style.display='block'; document.getElementById('login').style.display='none';">Register</button>
41
+ </div>
42
+ <div id="login" style="display:block;">
43
+ <h2>Log In</h2>
44
+ {login}
45
+ </div>
46
+ <div id="register" style="display:none;">
47
+ <h2>Register</h2>
48
+ {register}
49
+ </div>
50
+ </div>
51
+ </div>
52
+ <style>
53
+ .container {{ display: flex; height: 100vh; }}
54
+ .left {{ flex: 1; background: url('https://via.placeholder.com/300') no-repeat center center;