Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ 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"]},
|
|
@@ -25,11 +25,12 @@ def generate_qr(table_id):
|
|
| 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 |
-
|
|
|
|
| 33 |
|
| 34 |
# Save Preferences
|
| 35 |
|
|
@@ -41,9 +42,8 @@ def save_preferences(phone_number, preferences):
|
|
| 41 |
|
| 42 |
# Filter Menu
|
| 43 |
|
| 44 |
-
def filter_menu(
|
| 45 |
-
|
| 46 |
-
return filtered_menu
|
| 47 |
|
| 48 |
# Dish Details
|
| 49 |
|
|
@@ -57,6 +57,16 @@ def dish_details(dish_name):
|
|
| 57 |
"Spice Levels": dish["spice_levels"],
|
| 58 |
"Portion Sizes": dish["portion_sizes"]
|
| 59 |
}, dish["image"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
# Gradio Interfaces
|
| 62 |
|
|
@@ -65,41 +75,52 @@ def main():
|
|
| 65 |
gr.Markdown("# Restaurant QR Code Ordering System")
|
| 66 |
|
| 67 |
# QR Code Generator
|
| 68 |
-
with gr.
|
| 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.
|
|
|
|
| 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 |
-
|
|
|
|
| 80 |
|
| 81 |
# Preferences
|
| 82 |
-
with gr.
|
| 83 |
-
|
|
|
|
| 84 |
pref_button = gr.Button("Save Preferences")
|
| 85 |
pref_output = gr.Text(label="Preference Status")
|
| 86 |
-
pref_button.click(save_preferences, inputs=[
|
| 87 |
|
| 88 |
# Menu Display
|
| 89 |
-
with gr.
|
| 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.
|
| 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 |
|
| 105 |
if __name__ == "__main__":
|
|
|
|
| 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"]},
|
|
|
|
| 25 |
|
| 26 |
# Login / Signup
|
| 27 |
|
| 28 |
+
def login_or_signup(name, phone_number, email):
|
| 29 |
if phone_number in CUSTOMERS:
|
| 30 |
return f"Welcome back, {CUSTOMERS[phone_number]['name']}!", True
|
| 31 |
else:
|
| 32 |
+
CUSTOMERS[phone_number] = {"name": name, "email": email, "preferences": []}
|
| 33 |
+
return f"Account created for {name}. Please set your preferences.", False
|
| 34 |
|
| 35 |
# Save Preferences
|
| 36 |
|
|
|
|
| 42 |
|
| 43 |
# Filter Menu
|
| 44 |
|
| 45 |
+
def filter_menu(preference):
|
| 46 |
+
return MENU.get(preference.upper(), MENU["ALL"])
|
|
|
|
| 47 |
|
| 48 |
# Dish Details
|
| 49 |
|
|
|
|
| 57 |
"Spice Levels": dish["spice_levels"],
|
| 58 |
"Portion Sizes": dish["portion_sizes"]
|
| 59 |
}, dish["image"]
|
| 60 |
+
return "Dish not found.", None
|
| 61 |
+
|
| 62 |
+
# Recommendations
|
| 63 |
+
|
| 64 |
+
def recommend_dishes(selected_dish):
|
| 65 |
+
recommendations = {
|
| 66 |
+
"Chicken Curry": ["Rotis", "Rice"],
|
| 67 |
+
"Paneer Butter Masala": ["Naan", "Rice"],
|
| 68 |
+
}
|
| 69 |
+
return recommendations.get(selected_dish, [])
|
| 70 |
|
| 71 |
# Gradio Interfaces
|
| 72 |
|
|
|
|
| 75 |
gr.Markdown("# Restaurant QR Code Ordering System")
|
| 76 |
|
| 77 |
# QR Code Generator
|
| 78 |
+
with gr.Tab("QR Code Generator"):
|
| 79 |
table_id = gr.Textbox(label="Table ID", placeholder="Enter table ID")
|
| 80 |
qr_button = gr.Button("Generate QR Code")
|
| 81 |
qr_output = gr.Image(label="QR Code")
|
| 82 |
qr_button.click(lambda table_id: generate_qr(table_id), inputs=table_id, outputs=qr_output)
|
| 83 |
|
| 84 |
# Login or Signup
|
| 85 |
+
with gr.Tab("Login / Signup"):
|
| 86 |
+
name_input = gr.Textbox(label="Name", placeholder="Enter your name")
|
| 87 |
phone_input = gr.Textbox(label="Phone Number", placeholder="Enter phone number")
|
| 88 |
+
email_input = gr.Textbox(label="Email", placeholder="Enter email")
|
| 89 |
login_button = gr.Button("Login / Signup")
|
| 90 |
login_output = gr.Text(label="Login Status")
|
| 91 |
+
existing_customer = gr.Text(label="Is Existing Customer?")
|
| 92 |
+
login_button.click(login_or_signup, inputs=[name_input, phone_input, email_input], outputs=[login_output, existing_customer])
|
| 93 |
|
| 94 |
# Preferences
|
| 95 |
+
with gr.Tab("Preferences"):
|
| 96 |
+
phone_input_pref = gr.Textbox(label="Phone Number", placeholder="Enter phone number")
|
| 97 |
+
preferences = gr.CheckboxGroup(["Vegan", "Halal", "Indian", "Chinese"], label="Select Preferences")
|
| 98 |
pref_button = gr.Button("Save Preferences")
|
| 99 |
pref_output = gr.Text(label="Preference Status")
|
| 100 |
+
pref_button.click(save_preferences, inputs=[phone_input_pref, preferences], outputs=pref_output)
|
| 101 |
|
| 102 |
# Menu Display
|
| 103 |
+
with gr.Tab("Menu Display"):
|
| 104 |
menu_pref = gr.Dropdown(["ALL", "VEGAN", "HALAL"], label="Menu Type")
|
| 105 |
menu_button = gr.Button("Show Menu")
|
| 106 |
+
menu_output = gr.JSON(label="Filtered Menu")
|
| 107 |
menu_button.click(filter_menu, inputs=menu_pref, outputs=menu_output)
|
| 108 |
|
| 109 |
# Dish Details
|
| 110 |
+
with gr.Tab("Dish Details"):
|
| 111 |
dish_name = gr.Textbox(label="Dish Name", placeholder="Enter dish name")
|
| 112 |
dish_button = gr.Button("Get Dish Details")
|
| 113 |
dish_output = gr.JSON(label="Dish Details")
|
| 114 |
dish_image = gr.Image(label="Dish Image")
|
| 115 |
dish_button.click(dish_details, inputs=dish_name, outputs=[dish_output, dish_image])
|
| 116 |
|
| 117 |
+
# Recommendations
|
| 118 |
+
with gr.Tab("Recommendations"):
|
| 119 |
+
selected_dish = gr.Textbox(label="Selected Dish", placeholder="Enter dish name")
|
| 120 |
+
rec_button = gr.Button("Get Recommendations")
|
| 121 |
+
rec_output = gr.List(label="Recommendations")
|
| 122 |
+
rec_button.click(recommend_dishes, inputs=selected_dish, outputs=rec_output)
|
| 123 |
+
|
| 124 |
demo.launch()
|
| 125 |
|
| 126 |
if __name__ == "__main__":
|