Rammohan0504 commited on
Commit
dcecc82
·
verified ·
1 Parent(s): 291a1b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -21
app.py CHANGED
@@ -16,13 +16,12 @@ menu_data = [
16
  # Cart data (persistent across sessions)
17
  cart_items = []
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 Salan 8oz", "price": "$2.00"},
25
- # Add more extras here
26
  ]
27
 
28
  # Filter dishes by category
@@ -34,7 +33,7 @@ def filter_dishes(category):
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;
@@ -58,10 +57,9 @@ def display_dishes(category):
58
  return html_content
59
 
60
  # Function to handle adding items to the cart
61
- def add_to_cart(dish_name, spice_level, selected_extras, quantity, custom_description):
62
  cart_items.append({
63
  "name": dish_name,
64
- "spice_level": spice_level,
65
  "extras": selected_extras,
66
  "quantity": quantity,
67
  "custom_description": custom_description
@@ -76,7 +74,7 @@ def update_cart():
76
  for item in cart_items:
77
  extras = ", ".join(item["extras"])
78
  html_content += f"<li style='margin-bottom: 10px;'><strong>{item['name']}</strong> (x{item['quantity']})<br>"
79
- html_content += f"Spice Level: {item['spice_level']}<br>Extras: {extras if extras else 'None'}<br>"
80
  html_content += f"Note: {item['custom_description']}</li>"
81
  html_content += "</ul>"
82
  return html_content
@@ -104,7 +102,6 @@ with gr.Blocks() as demo:
104
  # Add to cart button with input fields
105
  add_to_cart_inputs = [
106
  gr.Textbox(label="Dish Name", visible=False),
107
- gr.Textbox(label="Spice Level", visible=False),
108
  gr.Textbox(label="Selected Extras", visible=False),
109
  gr.Number(label="Quantity", value=1, visible=False),
110
  gr.Textbox(label="Custom Description", visible=False)
@@ -125,10 +122,6 @@ with gr.Blocks() as demo:
125
  <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
126
  <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
127
  <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
128
- <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
129
- <div style="display: flex; flex-wrap: wrap; justify-content: space-between;">
130
- """ + "".join([f'<label><input type="radio" name="spice" value="{spice}">{spice}</label>' for spice in spice_levels]) + """
131
- </div>
132
  <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
133
  <div style="display: flex; flex-wrap: wrap;">
134
  """ + "".join([f'<label><input type="checkbox" name="extras" value="{extra["name"]}">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
@@ -146,7 +139,6 @@ with gr.Blocks() as demo:
146
  <script>
147
  let selectedDish = "";
148
  let selectedExtras = [];
149
- let spiceLevel = "";
150
 
151
  function showPopup(title, description, price) {
152
  selectedDish = title;
@@ -169,8 +161,6 @@ with gr.Blocks() as demo:
169
  }
170
  }
171
  function addItemToCart() {
172
- const spiceInput = document.querySelector('input[name="spice"]:checked');
173
- spiceLevel = spiceInput ? spiceInput.value : "No Spice Selected";
174
  const extrasInputs = document.querySelectorAll('input[name="extras"]:checked');
175
  selectedExtras = Array.from(extrasInputs).map(input => input.value);
176
  const quantity = document.getElementById('quantity').value || 1;
@@ -178,11 +168,10 @@ with gr.Blocks() as demo:
178
 
179
  // Pass to Gradio backend
180
  gradioApp().querySelector("#component-0 input").value = selectedDish;
181
- gradioApp().querySelector("#component-1 input").value = spiceLevel;
182
- gradioApp().querySelector("#component-2 input").value = JSON.stringify(selectedExtras);
183
- gradioApp().querySelector("#component-3 input").value = quantity;
184
- gradioApp().querySelector("#component-4 input").value = customDescription;
185
- gradioApp().querySelector("#component-5 button").click();
186
  closePopup();
187
  }
188
  </script>
 
16
  # Cart data (persistent across sessions)
17
  cart_items = []
18
 
19
+ # Extras
 
 
20
  extras = [
21
+ {"name": "Coke 500ml", "price": "$2.00"},
22
+ {"name": "Sprite 500ml", "price": "$2.00"},
23
  {"name": "Extra Raitha 4oz", "price": "$1.00"},
24
  {"name": "Extra Salan 8oz", "price": "$2.00"},
 
25
  ]
26
 
27
  # Filter dishes by category
 
33
  # Generate dish cards with "Add" button
34
  def display_dishes(category):
35
  filtered_dishes = filter_dishes(category)
36
+ html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%; overflow-y: auto;'>"
37
  for dish in filtered_dishes:
38
  html_content += f"""
39
  <div style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
 
57
  return html_content
58
 
59
  # Function to handle adding items to the cart
60
+ def add_to_cart(dish_name, selected_extras, quantity, custom_description):
61
  cart_items.append({
62
  "name": dish_name,
 
63
  "extras": selected_extras,
64
  "quantity": quantity,
65
  "custom_description": custom_description
 
74
  for item in cart_items:
75
  extras = ", ".join(item["extras"])
76
  html_content += f"<li style='margin-bottom: 10px;'><strong>{item['name']}</strong> (x{item['quantity']})<br>"
77
+ html_content += f"Extras: {extras if extras else 'None'}<br>"
78
  html_content += f"Note: {item['custom_description']}</li>"
79
  html_content += "</ul>"
80
  return html_content
 
102
  # Add to cart button with input fields
103
  add_to_cart_inputs = [
104
  gr.Textbox(label="Dish Name", visible=False),
 
105
  gr.Textbox(label="Selected Extras", visible=False),
106
  gr.Number(label="Quantity", value=1, visible=False),
107
  gr.Textbox(label="Custom Description", visible=False)
 
122
  <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
123
  <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
124
  <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
 
 
 
 
125
  <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
126
  <div style="display: flex; flex-wrap: wrap;">
127
  """ + "".join([f'<label><input type="checkbox" name="extras" value="{extra["name"]}">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
 
139
  <script>
140
  let selectedDish = "";
141
  let selectedExtras = [];
 
142
 
143
  function showPopup(title, description, price) {
144
  selectedDish = title;
 
161
  }
162
  }
163
  function addItemToCart() {
 
 
164
  const extrasInputs = document.querySelectorAll('input[name="extras"]:checked');
165
  selectedExtras = Array.from(extrasInputs).map(input => input.value);
166
  const quantity = document.getElementById('quantity').value || 1;
 
168
 
169
  // Pass to Gradio backend
170
  gradioApp().querySelector("#component-0 input").value = selectedDish;
171
+ gradioApp().querySelector("#component-1 input").value = JSON.stringify(selectedExtras);
172
+ gradioApp().querySelector("#component-2 input").value = quantity;
173
+ gradioApp().querySelector("#component-3 input").value = customDescription;
174
+ gradioApp().querySelector("#component-4 button").click();
 
175
  closePopup();
176
  }
177
  </script>