Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,28 +3,14 @@ import qrcode
|
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
# Sample Data
|
| 6 |
-
CUSTOMERS = {
|
|
|
|
|
|
|
|
|
|
| 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 |
-
{"name": "Veg Biryani", "description": "Flavourful veg biryani", "image": "veg_biryani.jpg", "spice_levels": ["Mild", "Medium"], "portion_sizes": ["Small", "Medium", "Large"]},
|
| 12 |
-
{"name": "Butter Naan", "description": "Soft buttery naan", "image": "butter_naan.jpg", "spice_levels": [], "portion_sizes": ["Single", "Double"]},
|
| 13 |
-
{"name": "Tandoori Chicken", "description": "Chargrilled chicken", "image": "tandoori_chicken.jpg", "spice_levels": ["Mild", "Medium", "Hot"], "portion_sizes": ["Quarter", "Half", "Full"]},
|
| 14 |
-
{"name": "Dal Makhani", "description": "Rich lentil curry", "image": "dal_makhani.jpg", "spice_levels": ["Mild", "Medium"], "portion_sizes": ["Small", "Large"]},
|
| 15 |
-
{"name": "Chole Bhature", "description": "Spicy chickpeas with fried bread", "image": "chole_bhature.jpg", "spice_levels": ["Mild", "Medium", "Spicy"], "portion_sizes": ["Single", "Double"]},
|
| 16 |
-
{"name": "Egg Curry", "description": "Eggs in spicy gravy", "image": "egg_curry.jpg", "spice_levels": ["Mild", "Medium", "Hot"], "portion_sizes": ["Small", "Medium", "Large"]},
|
| 17 |
-
{"name": "Gulab Jamun", "description": "Sweet milk dumplings", "image": "gulab_jamun.jpg", "spice_levels": [], "portion_sizes": ["Single", "Double"]},
|
| 18 |
-
{"name": "Mutton Biryani", "description": "Fragrant rice with mutton", "image": "mutton_biryani.jpg", "spice_levels": ["Mild", "Medium", "Hot"], "portion_sizes": ["Small", "Medium", "Large"]},
|
| 19 |
-
{"name": "Fish Fry", "description": "Crispy fried fish", "image": "fish_fry.jpg", "spice_levels": ["Mild", "Medium"], "portion_sizes": ["Single", "Double"]},
|
| 20 |
-
{"name": "Prawns Curry", "description": "Spicy prawn curry", "image": "prawns_curry.jpg", "spice_levels": ["Mild", "Medium", "Hot"], "portion_sizes": ["Small", "Medium", "Large"]},
|
| 21 |
-
{"name": "Malai Kofta", "description": "Rich and creamy kofta curry", "image": "malai_kofta.jpg", "spice_levels": ["Mild", "Medium"], "portion_sizes": ["Small", "Medium", "Large"]},
|
| 22 |
-
{"name": "Vegetable Soup", "description": "Healthy mixed vegetable soup", "image": "vegetable_soup.jpg", "spice_levels": [], "portion_sizes": ["Small", "Medium"]},
|
| 23 |
-
{"name": "Paneer Tikka", "description": "Grilled paneer skewers", "image": "paneer_tikka.jpg", "spice_levels": ["Mild", "Medium"], "portion_sizes": ["Single", "Double"]}
|
| 24 |
-
],
|
| 25 |
-
"VEGAN": [
|
| 26 |
-
{"name": "Veg Biryani", "description": "Flavourful veg biryani", "image": "veg_biryani.jpg", "spice_levels": ["Mild", "Medium"], "portion_sizes": ["Small", "Medium", "Large"]},
|
| 27 |
-
{"name": "Dal Makhani", "description": "Rich lentil curry", "image": "dal_makhani.jpg", "spice_levels": ["Mild", "Medium"], "portion_sizes": ["Small", "Large"]}
|
| 28 |
]
|
| 29 |
}
|
| 30 |
|
|
@@ -37,59 +23,34 @@ def generate_qr(table_id):
|
|
| 37 |
img = qr.make_image(fill="black", back_color="white")
|
| 38 |
return img
|
| 39 |
|
| 40 |
-
# Login
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
if phone_number in CUSTOMERS:
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
else:
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
def save_preferences(phone_number, preferences):
|
| 52 |
-
if phone_number not in CUSTOMERS:
|
| 53 |
-
return "Customer not found. Sign up first."
|
| 54 |
-
CUSTOMERS[phone_number]["preferences"] = preferences
|
| 55 |
-
return f"Preferences saved: {preferences}"
|
| 56 |
-
|
| 57 |
-
# Filter Menu
|
| 58 |
-
|
| 59 |
-
def filter_menu(preference):
|
| 60 |
-
return MENU.get(preference.upper(), MENU["ALL"])
|
| 61 |
-
|
| 62 |
-
# Menu Display as Images and Names
|
| 63 |
-
|
| 64 |
-
def display_menu(preference):
|
| 65 |
-
dishes = filter_menu(preference)
|
| 66 |
-
display_items = []
|
| 67 |
-
for dish in dishes:
|
| 68 |
-
display_items.append({"label": dish["name"], "value": dish["image"]})
|
| 69 |
-
return display_items
|
| 70 |
-
|
| 71 |
-
# Dish Details
|
| 72 |
-
|
| 73 |
-
def dish_details(dish_name):
|
| 74 |
-
for category in MENU.values():
|
| 75 |
-
for dish in category:
|
| 76 |
-
if dish["name"] == dish_name:
|
| 77 |
-
return {
|
| 78 |
-
"Name": dish["name"],
|
| 79 |
-
"Description": dish["description"],
|
| 80 |
-
"Spice Levels": dish["spice_levels"],
|
| 81 |
-
"Portion Sizes": dish["portion_sizes"]
|
| 82 |
-
}, dish["image"]
|
| 83 |
-
return "Dish not found.", None
|
| 84 |
-
|
| 85 |
-
# Recommendations
|
| 86 |
-
|
| 87 |
-
def recommend_dishes(selected_dish):
|
| 88 |
-
recommendations = {
|
| 89 |
-
"Chicken Curry": ["Rotis", "Rice"],
|
| 90 |
-
"Paneer Butter Masala": ["Naan", "Rice"],
|
| 91 |
-
}
|
| 92 |
-
return recommendations.get(selected_dish, [])
|
| 93 |
|
| 94 |
# Gradio Interfaces
|
| 95 |
|
|
@@ -106,42 +67,19 @@ def main():
|
|
| 106 |
|
| 107 |
# Login or Signup
|
| 108 |
with gr.Tab("Login / Signup"):
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
email_input = gr.Textbox(label="Email", placeholder="Enter email")
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
pref_button.click(save_preferences, inputs=[phone_input_pref, preferences], outputs=pref_output)
|
| 123 |
-
|
| 124 |
-
# Menu Display
|
| 125 |
-
with gr.Tab("Menu Display"):
|
| 126 |
-
menu_pref = gr.Dropdown(["ALL", "VEGAN", "HALAL"], label="Menu Type")
|
| 127 |
-
menu_button = gr.Button("Show Menu")
|
| 128 |
-
menu_output = gr.Gallery(label="Filtered Menu")
|
| 129 |
-
menu_button.click(display_menu, inputs=menu_pref, outputs=menu_output)
|
| 130 |
-
|
| 131 |
-
# Dish Details
|
| 132 |
-
with gr.Tab("Dish Details"):
|
| 133 |
-
dish_name = gr.Textbox(label="Dish Name", placeholder="Enter dish name")
|
| 134 |
-
dish_button = gr.Button("Get Dish Details")
|
| 135 |
-
dish_output = gr.JSON(label="Dish Details")
|
| 136 |
-
dish_image = gr.Image(label="Dish Image")
|
| 137 |
-
dish_button.click(dish_details, inputs=dish_name, outputs=[dish_output, dish_image])
|
| 138 |
-
|
| 139 |
-
# Recommendations
|
| 140 |
-
with gr.Tab("Recommendations"):
|
| 141 |
-
selected_dish = gr.Textbox(label="Selected Dish", placeholder="Enter dish name")
|
| 142 |
-
rec_button = gr.Button("Get Recommendations")
|
| 143 |
-
rec_output = gr.List(label="Recommendations")
|
| 144 |
-
rec_button.click(recommend_dishes, inputs=selected_dish, outputs=rec_output)
|
| 145 |
|
| 146 |
demo.launch()
|
| 147 |
|
|
|
|
| 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 |
img = qr.make_image(fill="black", back_color="white")
|
| 24 |
return img
|
| 25 |
|
| 26 |
+
# Login or Signup
|
| 27 |
+
|
| 28 |
+
def login_or_signup(phone_number, name=None, email=None, password=None):
|
| 29 |
+
"""
|
| 30 |
+
Handles login or sign-up for customers.
|
| 31 |
+
|
| 32 |
+
Args:
|
| 33 |
+
phone_number (str): Customer's phone number.
|
| 34 |
+
name (str, optional): Customer's name (required for sign-up).
|
| 35 |
+
email (str, optional): Customer's email (required for sign-up).
|
| 36 |
+
password (str, optional): Customer's password (required for both login and sign-up).
|
| 37 |
|
| 38 |
+
Returns:
|
| 39 |
+
str: Status message about login or sign-up.
|
| 40 |
+
"""
|
| 41 |
+
# Check if phone number exists in the database
|
| 42 |
if phone_number in CUSTOMERS:
|
| 43 |
+
# Customer exists, check for login
|
| 44 |
+
if CUSTOMERS[phone_number]["password"] == password:
|
| 45 |
+
return f"Welcome back, {CUSTOMERS[phone_number]['name']}!"
|
| 46 |
+
else:
|
| 47 |
+
return "Incorrect password. Please try again."
|
| 48 |
else:
|
| 49 |
+
# New customer, proceed with sign-up
|
| 50 |
+
if not all([name, email, password]):
|
| 51 |
+
return "Missing details for sign-up. Please provide Name, Email, and Password."
|
| 52 |
+
CUSTOMERS[phone_number] = {"name": name, "email": email, "password": password}
|
| 53 |
+
return f"Account created successfully for {name}!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
# Gradio Interfaces
|
| 56 |
|
|
|
|
| 67 |
|
| 68 |
# Login or Signup
|
| 69 |
with gr.Tab("Login / Signup"):
|
| 70 |
+
phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
|
| 71 |
+
name_input = gr.Textbox(label="Name (For New Customers)", placeholder="Enter your name")
|
| 72 |
+
email_input = gr.Textbox(label="Email (For New Customers)", placeholder="Enter your email")
|
| 73 |
+
password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
|
| 74 |
+
|
| 75 |
+
action_button = gr.Button("Submit")
|
| 76 |
+
result_output = gr.Text(label="Status")
|
| 77 |
+
|
| 78 |
+
action_button.click(
|
| 79 |
+
login_or_signup,
|
| 80 |
+
inputs=[phone_input, name_input, email_input, password_input],
|
| 81 |
+
outputs=result_output
|
| 82 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
demo.launch()
|
| 85 |
|