Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,14 +3,14 @@ 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 |
|
|
@@ -23,37 +23,40 @@ def generate_qr(table_id):
|
|
| 23 |
img = qr.make_image(fill="black", back_color="white")
|
| 24 |
return img
|
| 25 |
|
| 26 |
-
# Login
|
| 27 |
-
|
| 28 |
-
def login_or_signup(
|
| 29 |
-
|
| 30 |
-
|
| 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 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# Gradio Interfaces
|
| 59 |
|
|
@@ -62,50 +65,40 @@ def main():
|
|
| 62 |
gr.Markdown("# Restaurant QR Code Ordering System")
|
| 63 |
|
| 64 |
# QR Code Generator
|
| 65 |
-
with gr.
|
| 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.
|
| 73 |
-
gr.
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
if is_new:
|
| 100 |
-
return login_or_signup(is_new, phone, name, email, password)
|
| 101 |
-
else:
|
| 102 |
-
return login_or_signup(is_new, phone, name=username, password=existing_password)
|
| 103 |
-
|
| 104 |
-
action_button.click(
|
| 105 |
-
handle_input,
|
| 106 |
-
inputs=[is_new_customer, phone_input, name_input, email_input, password_input_new, username_input, password_input_existing],
|
| 107 |
-
outputs=result_output
|
| 108 |
-
)
|
| 109 |
|
| 110 |
demo.launch()
|
| 111 |
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
# Sample Data
|
| 6 |
+
CUSTOMERS = {"9876543210": {"name": "John Doe", "preferences": ["Halal", "Indian"]}}
|
|
|
|
|
|
|
|
|
|
| 7 |
MENU = {
|
| 8 |
"ALL": [
|
| 9 |
{"name": "Chicken Curry", "description": "Spicy chicken curry", "image": "chicken_curry.jpg", "spice_levels": ["Mild", "Medium", "Hot"], "portion_sizes": ["Small", "Medium", "Large"]},
|
| 10 |
{"name": "Paneer Butter Masala", "description": "Creamy paneer dish", "image": "paneer_butter.jpg", "spice_levels": ["Mild", "Medium", "Hot"], "portion_sizes": ["Small", "Medium", "Large"]}
|
| 11 |
+
],
|
| 12 |
+
"VEGAN": [
|
| 13 |
+
{"name": "Veg Biryani", "description": "Flavourful veg biryani", "image": "veg_biryani.jpg", "spice_levels": ["Mild", "Medium"], "portion_sizes": ["Small", "Medium", "Large"]}
|
| 14 |
]
|
| 15 |
}
|
| 16 |
|
|
|
|
| 23 |
img = qr.make_image(fill="black", back_color="white")
|
| 24 |
return img
|
| 25 |
|
| 26 |
+
# Login / Signup
|
| 27 |
+
|
| 28 |
+
def login_or_signup(phone_number):
|
| 29 |
+
if phone_number in CUSTOMERS:
|
| 30 |
+
return f"Welcome back, {CUSTOMERS[phone_number]['name']}!", True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
else:
|
| 32 |
+
return "Please sign up to continue.", False
|
| 33 |
+
|
| 34 |
+
# Save Preferences
|
| 35 |
+
|
| 36 |
+
def save_preferences(phone_number, preferences):
|
| 37 |
+
if phone_number not in CUSTOMERS:
|
| 38 |
+
return "Customer not found. Sign up first."
|
| 39 |
+
CUSTOMERS[phone_number]["preferences"] = preferences
|
| 40 |
+
return f"Preferences saved: {preferences}"
|
| 41 |
+
|
| 42 |
+
# Filter Menu
|
| 43 |
+
|
| 44 |
+
def filter_menu(preferences):
|
| 45 |
+
filtered_menu = MENU.get(preferences[0].upper(), MENU["ALL"])
|
| 46 |
+
return filtered_menu
|
| 47 |
+
|
| 48 |
+
# Dish Details
|
| 49 |
+
|
| 50 |
+
def dish_details(dish_name):
|
| 51 |
+
for category in MENU.values():
|
| 52 |
+
for dish in category:
|
| 53 |
+
if dish["name"] == dish_name:
|
| 54 |
+
return {
|
| 55 |
+
"Name": dish["name"],
|
| 56 |
+
"Description": dish["description"],
|
| 57 |
+
"Spice Levels": dish["spice_levels"],
|
| 58 |
+
"Portion Sizes": dish["portion_sizes"]
|
| 59 |
+
}, dish["image"]
|
| 60 |
|
| 61 |
# Gradio Interfaces
|
| 62 |
|
|
|
|
| 65 |
gr.Markdown("# Restaurant QR Code Ordering System")
|
| 66 |
|
| 67 |
# QR Code Generator
|
| 68 |
+
with gr.Row():
|
| 69 |
table_id = gr.Textbox(label="Table ID", placeholder="Enter table ID")
|
| 70 |
qr_button = gr.Button("Generate QR Code")
|
| 71 |
qr_output = gr.Image(label="QR Code")
|
| 72 |
qr_button.click(lambda table_id: generate_qr(table_id), inputs=table_id, outputs=qr_output)
|
| 73 |
|
| 74 |
# Login or Signup
|
| 75 |
+
with gr.Row():
|
| 76 |
+
phone_input = gr.Textbox(label="Phone Number", placeholder="Enter phone number")
|
| 77 |
+
login_button = gr.Button("Login / Signup")
|
| 78 |
+
login_output = gr.Text(label="Login Status")
|
| 79 |
+
login_button.click(login_or_signup, inputs=phone_input, outputs=login_output)
|
| 80 |
+
|
| 81 |
+
# Preferences
|
| 82 |
+
with gr.Row():
|
| 83 |
+
preferences = gr.CheckboxGroup(["Vegan", "Halal", "Indian", "Chinese"], label="Preferences")
|
| 84 |
+
pref_button = gr.Button("Save Preferences")
|
| 85 |
+
pref_output = gr.Text(label="Preference Status")
|
| 86 |
+
pref_button.click(save_preferences, inputs=[phone_input, preferences], outputs=pref_output)
|
| 87 |
+
|
| 88 |
+
# Menu Display
|
| 89 |
+
with gr.Row():
|
| 90 |
+
menu_pref = gr.Dropdown(["ALL", "VEGAN", "HALAL"], label="Menu Type")
|
| 91 |
+
menu_button = gr.Button("Show Menu")
|
| 92 |
+
menu_output = gr.JSON(label="Menu")
|
| 93 |
+
menu_button.click(filter_menu, inputs=menu_pref, outputs=menu_output)
|
| 94 |
+
|
| 95 |
+
# Dish Details
|
| 96 |
+
with gr.Row():
|
| 97 |
+
dish_name = gr.Textbox(label="Dish Name", placeholder="Enter dish name")
|
| 98 |
+
dish_button = gr.Button("Get Dish Details")
|
| 99 |
+
dish_output = gr.JSON(label="Dish Details")
|
| 100 |
+
dish_image = gr.Image(label="Dish Image")
|
| 101 |
+
dish_button.click(dish_details, inputs=dish_name, outputs=[dish_output, dish_image])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
demo.launch()
|
| 104 |
|