Rammohan0504 commited on
Commit
20b9bf1
·
verified ·
1 Parent(s): 9c58e19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -8
app.py CHANGED
@@ -39,7 +39,7 @@ def display_dishes(category="ALL"):
39
  <h4>{dish['name']}</h4>
40
  <p>{dish['description']}</p>
41
  <p><strong>Price:</strong> {dish['price']}</p>
42
- <button onclick=\"addItemToCart('{dish['name']}')\" style='padding: 5px 10px; background-color: #28a745; color: white; border: none; border-radius: 3px;'>Add to Cart</button>
43
  </div>
44
  """
45
  html_content += "</div>"
@@ -63,10 +63,6 @@ with gr.Blocks() as demo:
63
  btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
64
  btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
65
 
66
- def handle_add_to_cart(cart, dish_name):
67
- cart.append(dish_name)
68
- return cart, update_cart(cart)
69
-
70
  with gr.Row():
71
  gr.HTML("""
72
  <div id='cart-icon' style='position: fixed; top: 10px; right: 10px; cursor: pointer;'>
@@ -76,20 +72,46 @@ with gr.Blocks() as demo:
76
  <div id='cart-content'></div>
77
  <button onclick='toggleCartPopup()' style='margin-top: 10px; padding: 5px 10px; background-color: #007bff; color: white; border: none; border-radius: 3px;'>Close</button>
78
  </div>
 
 
 
 
 
 
 
 
 
 
79
  <script>
 
 
80
  function toggleCartPopup() {
81
  const popup = document.getElementById('cart-popup');
82
  popup.style.display = popup.style.display === 'block' ? 'none' : 'block';
83
  }
84
 
85
- function addItemToCart(name) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  fetch('/run/predict', {
87
  method: 'POST',
88
  headers: { 'Content-Type': 'application/json' },
89
- body: JSON.stringify({ data: [name] })
90
  }).then(response => response.json()).then(data => {
91
  document.getElementById('cart-content').innerHTML = data.data[1];
92
- alert(name + ' has been added to the cart!');
93
  });
94
  }
95
  </script>
 
39
  <h4>{dish['name']}</h4>
40
  <p>{dish['description']}</p>
41
  <p><strong>Price:</strong> {dish['price']}</p>
42
+ <button onclick=\"showMenuPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')\" style='padding: 5px 10px; background-color: #28a745; color: white; border: none; border-radius: 3px;'>Add to Cart</button>
43
  </div>
44
  """
45
  html_content += "</div>"
 
63
  btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
64
  btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
65
 
 
 
 
 
66
  with gr.Row():
67
  gr.HTML("""
68
  <div id='cart-icon' style='position: fixed; top: 10px; right: 10px; cursor: pointer;'>
 
72
  <div id='cart-content'></div>
73
  <button onclick='toggleCartPopup()' style='margin-top: 10px; padding: 5px 10px; background-color: #007bff; color: white; border: none; border-radius: 3px;'>Close</button>
74
  </div>
75
+
76
+ <div id='menu-popup' style='display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);'>
77
+ <span onclick='closeMenuPopup()' style='position: absolute; top: 5px; right: 10px; cursor: pointer;'>&times;</span>
78
+ <img id='popup-image' src='' style='width: 100%; border-radius: 5px; margin-bottom: 10px;'>
79
+ <h4 id='popup-title'></h4>
80
+ <p id='popup-description'></p>
81
+ <p id='popup-price'></p>
82
+ <button onclick='addItemToCart()' style='padding: 5px 10px; background-color: #28a745; color: white; border: none; border-radius: 3px;'>Add to Cart</button>
83
+ </div>
84
+
85
  <script>
86
+ let selectedItem = '';
87
+
88
  function toggleCartPopup() {
89
  const popup = document.getElementById('cart-popup');
90
  popup.style.display = popup.style.display === 'block' ? 'none' : 'block';
91
  }
92
 
93
+ function showMenuPopup(name, description, price, image) {
94
+ selectedItem = name;
95
+ document.getElementById('popup-title').textContent = name;
96
+ document.getElementById('popup-description').textContent = description;
97
+ document.getElementById('popup-price').textContent = `Price: ${price}`;
98
+ document.getElementById('popup-image').src = image;
99
+ document.getElementById('menu-popup').style.display = 'block';
100
+ }
101
+
102
+ function closeMenuPopup() {
103
+ document.getElementById('menu-popup').style.display = 'none';
104
+ }
105
+
106
+ function addItemToCart() {
107
+ closeMenuPopup();
108
  fetch('/run/predict', {
109
  method: 'POST',
110
  headers: { 'Content-Type': 'application/json' },
111
+ body: JSON.stringify({ data: [selectedItem] })
112
  }).then(response => response.json()).then(data => {
113
  document.getElementById('cart-content').innerHTML = data.data[1];
114
+ alert(selectedItem + ' has been added to the cart!');
115
  });
116
  }
117
  </script>