Rammohan0504 commited on
Commit
da4b12f
·
verified ·
1 Parent(s): 5d07555

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -80,7 +80,7 @@ def display_dishes(category):
80
  <div id="item-{index}" style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
81
  width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
82
  background-color: #f9f9f9; cursor: pointer;'
83
- onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', 'item-{index}')">
84
  <div style='flex: 1; margin-right: 20px;'>
85
  <h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
86
  <p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
@@ -118,10 +118,9 @@ with gr.Blocks() as demo:
118
  border-radius: 5px; cursor: pointer;">Close</button>
119
  </div>
120
  <script>
121
- function showPopup(image, title, description, itemId) {
122
  // Get the item's position
123
- const item = document.getElementById(itemId);
124
- const rect = item.getBoundingClientRect();
125
 
126
  // Set pop-up content
127
  const popup = document.getElementById('popup');
@@ -130,7 +129,7 @@ with gr.Blocks() as demo:
130
  document.getElementById('popup-description').textContent = description;
131
 
132
  // Position the pop-up near the item
133
- popup.style.top = window.scrollY + rect.top + 'px';
134
  popup.style.left = rect.left + 'px';
135
  popup.style.display = 'block';
136
  }
@@ -146,4 +145,4 @@ with gr.Blocks() as demo:
146
  btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
147
  btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
148
 
149
- demo.launch()
 
80
  <div id="item-{index}" style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
81
  width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
82
  background-color: #f9f9f9; cursor: pointer;'
83
+ onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', this)">
84
  <div style='flex: 1; margin-right: 20px;'>
85
  <h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
86
  <p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
 
118
  border-radius: 5px; cursor: pointer;">Close</button>
119
  </div>
120
  <script>
121
+ function showPopup(image, title, description, element) {
122
  // Get the item's position
123
+ const rect = element.getBoundingClientRect();
 
124
 
125
  // Set pop-up content
126
  const popup = document.getElementById('popup');
 
129
  document.getElementById('popup-description').textContent = description;
130
 
131
  // Position the pop-up near the item
132
+ popup.style.top = window.scrollY + rect.top + rect.height + 'px';
133
  popup.style.left = rect.left + 'px';
134
  popup.style.display = 'block';
135
  }
 
145
  btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
146
  btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
147
 
148
+ demo.launch()