Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,111 +1,54 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import qrcode
|
| 3 |
-
from PIL import Image
|
| 4 |
|
| 5 |
-
# Sample
|
| 6 |
CUSTOMERS = {
|
| 7 |
-
"
|
| 8 |
}
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 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 "
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
def
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|