nagasurendra commited on
Commit
a80b70a
·
verified ·
1 Parent(s): 251b182

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -35
app.py CHANGED
@@ -7,24 +7,11 @@ def load_menu():
7
  try:
8
  return pd.read_excel(menu_file)
9
  except Exception as e:
10
- print(f"Error loading menu file: {e}")
11
- # Fallback: create a sample menu
12
- sample_menu = pd.DataFrame({
13
- "Dish Name": ["Sample Dish 1", "Sample Dish 2"],
14
- "Ingredients": ["Chicken, Spices", "Paneer, Spices"],
15
- "Description": ["Delicious chicken curry", "Tasty paneer curry"],
16
- "Price ($)": [10, 12],
17
- "Image URL": ["https://via.placeholder.com/100", "https://via.placeholder.com/100"]
18
- })
19
- return sample_menu
20
 
21
  # Function to filter menu items based on preference
22
  def filter_menu(preference):
23
  menu_data = load_menu()
24
- required_columns = ["Ingredients", "Description", "Dish Name", "Price ($)", "Image URL"]
25
- if not all(col in menu_data.columns for col in required_columns):
26
- raise ValueError("Menu file is missing required columns.")
27
-
28
  if preference == "Halal/Non-Veg":
29
  filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
30
  elif preference == "Vegetarian":
@@ -45,10 +32,7 @@ def filter_menu(preference):
45
  </div>
46
  <div style="flex-shrink: 0; text-align: center;">
47
  <img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
48
- <button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;"
49
- onclick="openModal('{item['Dish Name']}', '{item['Image URL']}', '{item['Description']}', '{item['Price ($)']}', event)">
50
- Add
51
- </button>
52
  </div>
53
  </div>
54
  """
@@ -114,34 +98,32 @@ modal_and_cart_js = """
114
  modal.style.display = 'block';
115
  modal.style.position = 'absolute';
116
 
117
- // Get the button position and calculate modal position
118
- const buttonRect = event.target.getBoundingClientRect();
119
- const isSmallScreen = window.innerWidth <= 768;
120
-
121
- modal.style.top = `${window.scrollY + buttonRect.top + (isSmallScreen ? 20 : 0)}px`;
122
- modal.style.left = isSmallScreen
123
- ? "50%"
124
- : `${window.scrollX + buttonRect.left}px`;
125
- modal.style.transform = isSmallScreen ? "translateX(-50%)" : "none";
126
- modal.style.width = isSmallScreen ? "90%" : "30%";
 
 
127
 
128
- // Update modal content
129
  document.getElementById('modal-image').src = image;
130
  document.getElementById('modal-name').innerText = name;
131
  document.getElementById('modal-description').innerText = description;
132
  document.getElementById('modal-price').innerText = price;
133
-
134
- // Reset extras and quantity
135
  const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
136
  extrasInputs.forEach(input => input.checked = false);
137
  document.getElementById('quantity').value = 1;
138
  document.getElementById('special-instructions').value = '';
139
  }
140
-
141
  function closeModal() {
142
  document.getElementById('modal').style.display = 'none';
143
  }
144
- // Other cart functions remain unchanged
145
  </script>
146
  """
147
 
@@ -167,8 +149,8 @@ def app():
167
  final_order_output = gr.HTML(value="", elem_id="final-order")
168
 
169
  # Modal window
170
- modal_window = gr.HTML("""
171
- <div id="modal" style="display: none; position: absolute; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
172
  <div style="text-align: right;">
173
  <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
174
  </div>
@@ -176,11 +158,24 @@ def app():
176
  <h2 id="modal-name"></h2>
177
  <p id="modal-description"></p>
178
  <p id="modal-price"></p>
 
 
 
 
 
 
 
 
 
 
 
 
179
  <label for="quantity">Quantity:</label>
180
  <input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
181
  <br><br>
182
  <textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
183
  <br><br>
 
184
  <button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
185
  </div>
186
  """)
 
7
  try:
8
  return pd.read_excel(menu_file)
9
  except Exception as e:
10
+ raise ValueError(f"Error loading menu file: {e}")
 
 
 
 
 
 
 
 
 
11
 
12
  # Function to filter menu items based on preference
13
  def filter_menu(preference):
14
  menu_data = load_menu()
 
 
 
 
15
  if preference == "Halal/Non-Veg":
16
  filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
17
  elif preference == "Vegetarian":
 
32
  </div>
33
  <div style="flex-shrink: 0; text-align: center;">
34
  <img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
35
+ <button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="openModal('{item['Dish Name']}', '{item['Image URL']}', '{item['Description']}', '{item['Price ($)']}', event)">Add</button>
 
 
 
36
  </div>
37
  </div>
38
  """
 
98
  modal.style.display = 'block';
99
  modal.style.position = 'absolute';
100
 
101
+ try {
102
+ // Get button position and adjust modal location
103
+ const buttonRect = event.target.getBoundingClientRect();
104
+ modal.style.top = `${window.scrollY + buttonRect.top}px`;
105
+ modal.style.left = `${window.scrollX + buttonRect.left}px`;
106
+ } catch (e) {
107
+ console.error("Dynamic positioning failed, centering modal:", e);
108
+ modal.style.position = 'fixed';
109
+ modal.style.top = '15%';
110
+ modal.style.left = '50%';
111
+ modal.style.transform = 'translate(-50%, -50%)';
112
+ }
113
 
114
+ modal.style.width = window.innerWidth <= 768 ? "90%" : "30%";
115
  document.getElementById('modal-image').src = image;
116
  document.getElementById('modal-name').innerText = name;
117
  document.getElementById('modal-description').innerText = description;
118
  document.getElementById('modal-price').innerText = price;
 
 
119
  const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
120
  extrasInputs.forEach(input => input.checked = false);
121
  document.getElementById('quantity').value = 1;
122
  document.getElementById('special-instructions').value = '';
123
  }
 
124
  function closeModal() {
125
  document.getElementById('modal').style.display = 'none';
126
  }
 
127
  </script>
128
  """
129
 
 
149
  final_order_output = gr.HTML(value="", elem_id="final-order")
150
 
151
  # Modal window
152
+ modal_window = gr.HTML("""
153
+ <div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
154
  <div style="text-align: right;">
155
  <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
156
  </div>
 
158
  <h2 id="modal-name"></h2>
159
  <p id="modal-description"></p>
160
  <p id="modal-price"></p>
161
+ <!-- Biryani Extras -->
162
+ <label for="biryani-extras">Biryani Extras :</label>
163
+ <div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
164
+ <label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label>
165
+ <label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label>
166
+ <label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label>
167
+ <label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label>
168
+ <label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
169
+ <label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label>
170
+ <label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label>
171
+ </div>
172
+ <!-- Quantity and Special Instructions -->
173
  <label for="quantity">Quantity:</label>
174
  <input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
175
  <br><br>
176
  <textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
177
  <br><br>
178
+ <!-- Add to Cart Button -->
179
  <button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
180
  </div>
181
  """)