DSatishchandra commited on
Commit
cddc1b8
·
verified ·
1 Parent(s): 3f9dbcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -19
app.py CHANGED
@@ -35,7 +35,7 @@ def filter_menu(preference):
35
  </div>
36
  <div style="flex-shrink: 0; text-align: center;">
37
  <img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
38
- <button class="add-btn" style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="openModal(event, '{item['Dish Name']}', '{item['Image URL']}', '{item['Description']}', '{item['Price ($)']}')">Add</button>
39
  </div>
40
  </div>
41
  """
@@ -76,16 +76,20 @@ def app():
76
  modal_window = gr.HTML("""
77
  <div id="modal" style="
78
  display: none;
79
- position: absolute;
 
 
 
 
 
 
80
  background: white;
81
- padding: 20px;
82
  border-radius: 15px;
83
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
84
- font-family: Arial, sans-serif;
85
  z-index: 1000;
86
- max-width: 500px; /* Limit modal width */
87
- max-height: 80%; /* Limit modal height to prevent overflow */
88
- overflow-y: auto; /* Allow scrolling inside the modal if content is too tall */
89
  ">
90
  <div style="text-align: right;">
91
  <button onclick="closeModal()" style="
@@ -126,21 +130,16 @@ def app():
126
  </div>
127
  <script>
128
  let cart = [];
129
- function openModal(event, name, image, description, price) {
130
  const modal = document.getElementById('modal');
131
  modal.style.display = 'block';
132
-
133
- // Get the clicked button's position
134
- const rect = event.target.getBoundingClientRect();
135
-
136
- // Set the popup position based on the clicked element
137
- modal.style.top = `${rect.top + window.scrollY + rect.height + 10}px`; // 10px below the button
138
- modal.style.left = `${rect.left + window.scrollX}px`;
139
-
140
  document.getElementById('modal-image').src = image;
141
  document.getElementById('modal-name').innerText = name;
142
  document.getElementById('modal-description').innerText = description;
143
- document.getElementById('modal-price').innerText = `$${price}`;
144
  }
145
  function closeModal() {
146
  const modal = document.getElementById('modal');
@@ -158,7 +157,7 @@ def app():
158
  headers: { "Content-Type": "application/json" },
159
  body: JSON.stringify(cart)
160
  });
161
- alert(`${name} added to cart!`);
162
  closeModal();
163
  }
164
  </script>
@@ -177,4 +176,4 @@ def app():
177
 
178
  if __name__ == "__main__":
179
  demo = app()
180
- demo.launch()
 
35
  </div>
36
  <div style="flex-shrink: 0; text-align: center;">
37
  <img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
38
+ <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 ($)']}')">Add</button>
39
  </div>
40
  </div>
41
  """
 
76
  modal_window = gr.HTML("""
77
  <div id="modal" style="
78
  display: none;
79
+ position: fixed;
80
+ top: 50%;
81
+ left: 50%;
82
+ transform: translate(-50%, -50%);
83
+ width: 90%;
84
+ max-width: 500px;
85
+ max-height: 90%;
86
  background: white;
 
87
  border-radius: 15px;
88
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
89
+ padding: 20px;
90
  z-index: 1000;
91
+ overflow-y: auto;
92
+ font-family: Arial, sans-serif;
 
93
  ">
94
  <div style="text-align: right;">
95
  <button onclick="closeModal()" style="
 
130
  </div>
131
  <script>
132
  let cart = [];
133
+ function openModal(name, image, description, price) {
134
  const modal = document.getElementById('modal');
135
  modal.style.display = 'block';
136
+ modal.style.top = '50%';
137
+ modal.style.left = '50%';
138
+ modal.style.transform = 'translate(-50%, -50%)';
 
 
 
 
 
139
  document.getElementById('modal-image').src = image;
140
  document.getElementById('modal-name').innerText = name;
141
  document.getElementById('modal-description').innerText = description;
142
+ document.getElementById('modal-price').innerText = $${price};
143
  }
144
  function closeModal() {
145
  const modal = document.getElementById('modal');
 
157
  headers: { "Content-Type": "application/json" },
158
  body: JSON.stringify(cart)
159
  });
160
+ alert(${name} added to cart!);
161
  closeModal();
162
  }
163
  </script>
 
176
 
177
  if __name__ == "__main__":
178
  demo = app()
179
+ demo.launch()