Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,90 +1,106 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
-
gr.
|
| 48 |
-
|
| 49 |
-
# Category Selection
|
| 50 |
-
gr.Markdown("### Select a Category")
|
| 51 |
-
category_dropdown = gr.Radio(choices=["ALL", "VEGAN", "HALAL"], label="Categories", value="ALL")
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
gr.Markdown("### Select a Dish")
|
| 55 |
-
dish_selector = gr.Radio(label="Available Dishes", choices=get_dish_list("ALL"))
|
| 56 |
-
|
| 57 |
-
# Dish Details Section
|
| 58 |
-
gr.Markdown("### Dish Details")
|
| 59 |
with gr.Row():
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="๐ถ Medium")
|
| 65 |
-
portion_dropdown = gr.Radio(label="Select Portion Size", choices=portion_options, value="๐ฝ Medium")
|
| 66 |
-
place_order_btn = gr.Button("Place Order")
|
| 67 |
-
order_status = gr.Textbox(label="Order Status", interactive=False)
|
| 68 |
-
|
| 69 |
-
# Update dish list dynamically
|
| 70 |
-
def update_dish_list(category):
|
| 71 |
-
return gr.update(choices=get_dish_list(category))
|
| 72 |
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
#
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import qrcode
|
| 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 |
+
|
| 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 / 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 |
+
|
| 63 |
+
def main():
|
| 64 |
with gr.Blocks() as demo:
|
| 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 |
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
main()
|