Rammohan0504 commited on
Commit
3cfb0b9
·
verified ·
1 Parent(s): 2cb9d97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +131 -117
app.py CHANGED
@@ -1,119 +1,133 @@
1
  import gradio as gr
2
- import pandas as pd
3
- import qrcode
4
- import os
5
 
6
- # Data storage (for prototyping; switch to Salesforce or database for production)
7
- customer_data_path = "customer_data.xlsx"
8
- order_data_path = "order_data.xlsx"
9
-
10
- # Ensure data files exist
11
- if not os.path.exists(customer_data_path):
12
- pd.DataFrame(columns=["Name", "Email", "Phone", "Preferences", "Allergies"]).to_excel(customer_data_path, index=False)
13
-
14
- if not os.path.exists(order_data_path):
15
- pd.DataFrame(columns=["Table", "Customer", "Order", "Status"]).to_excel(order_data_path, index=False)
16
-
17
- # Sample menu (can be dynamically loaded from an external file)
18
- menu = {
19
- "Bread": ["Roti", "Naan", "Paratha"],
20
- "Veg Curries": ["Paneer Butter Masala", "Mix Veg", "Dal Tadka"],
21
- "Non-Veg Curries": ["Chicken Curry", "Mutton Korma", "Fish Curry"],
22
- "Biryanis": ["Veg Biryani", "Chicken Biryani", "Mutton Biryani"]
23
- }
24
-
25
- # Generate QR Code for each table
26
- def generate_qr(table_number):
27
- qr = qrcode.make(f"https://your-huggingface-space/{table_number}")
28
- qr_path = f"table_{table_number}_qr.png"
29
- qr.save(qr_path)
30
- return qr_path
31
-
32
- # Sign-Up functionality
33
- def sign_up(name, email, phone, preferences, allergies):
34
- customer_data = pd.read_excel(customer_data_path)
35
- if email in customer_data["Email"].values:
36
- return "Email already exists! Please log in."
37
- new_entry = {"Name": name, "Email": email, "Phone": phone, "Preferences": preferences, "Allergies": allergies}
38
- customer_data = customer_data.append(new_entry, ignore_index=True)
39
- customer_data.to_excel(customer_data_path, index=False)
40
- return "Sign-Up successful! Please log in."
41
-
42
- # Login functionality
43
- def login(email):
44
- customer_data = pd.read_excel(customer_data_path)
45
- if email in customer_data["Email"].values:
46
- customer = customer_data[customer_data["Email"] == email].iloc[0]
47
- return f"Welcome back, {customer['Name']}!", customer.to_dict()
48
- return "Email not found! Please sign up.", None
49
-
50
- # Display menu based on preferences
51
- def display_menu(preferences, allergies):
52
- filtered_menu = {}
53
- for category, items in menu.items():
54
- filtered_menu[category] = [item for item in items if item not in allergies]
55
- return filtered_menu
56
-
57
- # Add item to order
58
- def add_to_order(table, customer, item):
59
- order_data = pd.read_excel(order_data_path)
60
- new_order = {"Table": table, "Customer": customer, "Order": item, "Status": "Pending"}
61
- order_data = order_data.append(new_order, ignore_index=True)
62
- order_data.to_excel(order_data_path, index=False)
63
- return "Item added to order."
64
-
65
- # Gradio Interface
66
- with gr.Blocks() as app:
67
- gr.Markdown("# QR-Based Restaurant Ordering System")
68
-
69
- # QR Code Section
70
- with gr.Tab("Generate QR Code"):
71
- table_input = gr.Number(label="Table Number", value=1)
72
- qr_output = gr.Image(label="QR Code")
73
- generate_button = gr.Button("Generate QR Code")
74
-
75
- generate_button.click(generate_qr, inputs=table_input, outputs=qr_output)
76
-
77
- # Sign-Up and Login Section
78
- with gr.Tab("Sign Up / Login"):
79
- with gr.Row():
80
- with gr.Column():
81
- gr.Markdown("### Sign Up")
82
- name_input = gr.Textbox(label="Name")
83
- email_input = gr.Textbox(label="Email")
84
- phone_input = gr.Textbox(label="Phone")
85
- preferences_input = gr.Textbox(label="Preferences (e.g., Vegetarian)")
86
- allergies_input = gr.Textbox(label="Allergies (e.g., Peanuts)")
87
- sign_up_button = gr.Button("Sign Up")
88
- sign_up_output = gr.Textbox(label="Sign-Up Status")
89
-
90
- sign_up_button.click(sign_up,
91
- inputs=[name_input, email_input, phone_input, preferences_input, allergies_input],
92
- outputs=sign_up_output)
93
-
94
- with gr.Column():
95
- gr.Markdown("### Login")
96
- login_email_input = gr.Textbox(label="Email")
97
- login_button = gr.Button("Login")
98
- login_output = gr.Textbox(label="Login Status")
99
-
100
- login_button.click(login, inputs=login_email_input, outputs=login_output)
101
-
102
- # Menu and Ordering Section
103
- with gr.Tab("Menu & Order"):
104
- preferences_input = gr.Textbox(label="Preferences (from Login)", interactive=False)
105
- allergies_input = gr.Textbox(label="Allergies (from Login)", interactive=False)
106
- menu_display = gr.JSON(label="Filtered Menu")
107
- display_menu_button = gr.Button("Show Menu")
108
-
109
- display_menu_button.click(display_menu, inputs=[preferences_input, allergies_input], outputs=menu_display)
110
-
111
- item_input = gr.Textbox(label="Item to Add")
112
- table_input = gr.Number(label="Table Number", value=1)
113
- customer_input = gr.Textbox(label="Customer Name")
114
- add_order_button = gr.Button("Add to Order")
115
- add_order_output = gr.Textbox(label="Order Status")
116
-
117
- add_order_button.click(add_to_order, inputs=[table_input, customer_input, item_input], outputs=add_order_output)
118
-
119
- app.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
 
 
 
2
 
3
+ # Menu data
4
+ menu_data = [
5
+ {"name": "Veg Burger", "category": "VEGAN",
6
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg",
7
+ "description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.",
8
+ "price": "$8.99"},
9
+ {"name": "Chicken Biryani", "category": "HALAL",
10
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_biryani.jpg",
11
+ "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
12
+ "price": "$12.99"},
13
+ {"name": "Paneer Butter Masala", "category": "VEGAN",
14
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/paneer_butter_masala.jpg",
15
+ "description": "Paneer cooked in a rich and creamy tomato-based gravy.",
16
+ "price": "$10.99"}
17
+ ]
18
+
19
+ # Spice levels and extras
20
+ spice_levels = ["American Mild", "American Medium", "American Spicy",
21
+ "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
22
+ extras = [
23
+ {"name": "Extra Raitha 4oz", "price": "$1.00"},
24
+ {"name": "Extra Onion", "price": "$1.00"},
25
+ {"name": "Extra Fried Onion 4oz", "price": "$2.00"}
26
+ ]
27
+
28
+ # Filter dishes by category
29
+ def filter_dishes(category):
30
+ if category == "ALL":
31
+ return menu_data
32
+ return [dish for dish in menu_data if dish["category"] == category]
33
+
34
+ # Generate dish cards with "Add" button
35
+ def display_dishes(category):
36
+ filtered_dishes = filter_dishes(category)
37
+ html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%'>"
38
+ for dish in filtered_dishes:
39
+ html_content += f"""
40
+ <div style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
41
+ width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
42
+ background-color: #f9f9f9;'>
43
+ <div style='flex: 1; margin-right: 20px; text-align: left;'>
44
+ <h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
45
+ <p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
46
+ <p style='font-size: 16px; color: #444; margin: 0;'>Price: {dish['price']}</p>
47
+ </div>
48
+ <div style='text-align: center;'>
49
+ <img src='{dish['image']}' alt='{dish['name']}'
50
+ style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
51
+ <button onclick=\"showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')\"
52
+ style=\"margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
53
+ border-radius: 5px; cursor: pointer;\">Add</button>
54
+ </div>
55
+ </div>
56
+ """
57
+ html_content += "</div>"
58
+ return html_content
59
+
60
+ # Main Gradio App
61
+ with gr.Blocks() as demo:
62
+ gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Dynamic Menu with Pop-up 🍛</h1>")
63
+
64
+ # Buttons for category selection
65
+ with gr.Row():
66
+ btn_all = gr.Button("ALL")
67
+ btn_vegan = gr.Button("VEGAN")
68
+ btn_halal = gr.Button("HALAL")
69
+
70
+ # Dish display
71
+ dish_display = gr.HTML(value=display_dishes("ALL"))
72
+
73
+ # JavaScript for managing the pop-up
74
+ gr.HTML(f"""
75
+ <div id=\"popup\" style=\"display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
76
+ background-color: white; padding: 20px; border-radius: 10px;
77
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;\">
78
+ <img id=\"popup-image\" src=\"\" alt=\"\" style=\"width: 100%; height: auto; border-radius: 10px;\">
79
+ <h2 id=\"popup-title\" style=\"margin-top: 20px; color: #444;\"></h2>
80
+ <p id=\"popup-description\" style=\"margin-top: 10px; font-size: 16px; color: #666;\"></p>
81
+ <p id=\"popup-price\" style=\"margin-top: 10px; font-size: 16px; color: #444;\"></p>
82
+
83
+ <h4 style=\"text-align: left; margin-top: 20px;\">Choose a spice level</h4>
84
+ <div style=\"display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;\">
85
+ """ + """".join([f'<label style=\"margin-right: 10px; display: block;\"><input type=\"radio\" name=\"spice\" value=\"{spice}\" style=\"margin-right: 5px;\">{spice}</label>' for spice in spice_levels]) + """
86
+ </div>
87
+
88
+ <h4 style=\"text-align: left; margin-top: 20px;\">Choose Extras</h4>
89
+ <div style=\"display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;\">
90
+ """ + """".join([f'<label style=\"margin-right: 10px; display: block;\"><input type=\"checkbox\" name=\"extras\" value=\"{extra["name"]}\" style=\"margin-right: 5px;\">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
91
+ </div>
92
+
93
+ <button onclick=\"addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)\"
94
+ style=\"margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
95
+ border-radius: 5px; cursor: pointer;\">Add to Cart</button>
96
+ <button onclick=\"closePopup()\" style=\"margin-top: 20px; padding: 10px 20px; background-color: #28a745;
97
+ color: white; border: none; border-radius: 5px; cursor: pointer;\">Close</button>
98
+ </div>
99
+ <script>
100
+ function showPopup(image, title, description, price) {
101
+ document.getElementById('popup-image').src = image;
102
+ document.getElementById('popup-title').textContent = title;
103
+ document.getElementById('popup-description').textContent = description;
104
+ document.getElementById('popup-price').textContent = "Price: " + price;
105
+
106
+ // Display the popup
107
+ document.getElementById('popup').style.display = 'block';
108
+ }
109
+ function closePopup() {
110
+ document.getElementById('popup').style.display = 'none';
111
+ }
112
+ function addToCart(dishName, spiceLevel) {
113
+ const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
114
+ alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
115
+ }
116
+ </script>
117
+ """)
118
+
119
+ # Button click events
120
+ btn_all.click(
121
+ lambda: gr.update(value=display_dishes("ALL")),
122
+ outputs=dish_display
123
+ )
124
+ btn_vegan.click(
125
+ lambda: gr.update(value=display_dishes("VEGAN")),
126
+ outputs=dish_display
127
+ )
128
+ btn_halal.click(
129
+ lambda: gr.update(value=display_dishes("HALAL")),
130
+ outputs=dish_display
131
+ )
132
+
133
+ demo.launch()