Rammohan0504 commited on
Commit
c9d38f1
·
verified ·
1 Parent(s): 892368a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -18
app.py CHANGED
@@ -17,20 +17,6 @@ def add_item_to_cart(item_name, price, extras="None"):
17
  cart.append({"name": item_name, "price": price, "extras": extras, "count": 1})
18
  return update_cart()
19
 
20
- def remove_item_from_cart(item_name):
21
- for item in cart:
22
- if item['name'] == item_name:
23
- item['count'] -= 1
24
- if item['count'] == 0:
25
- cart.remove(item)
26
- break
27
- return update_cart()
28
-
29
- def clear_cart():
30
- global cart
31
- cart = []
32
- return update_cart()
33
-
34
  def update_cart():
35
  if not cart:
36
  return "<p>Your cart is empty.</p>"
@@ -60,7 +46,7 @@ def display_dishes(category="ALL"):
60
  <h4>{dish['name']}</h4>
61
  <p>{dish['description']}</p>
62
  <p><strong>Price:</strong> ${dish['price']}</p>
63
- <button onclick="addToCart('{dish['name']}', {dish['price']})" style='padding: 5px 10px; background-color: #28a745; color: white; border: none; border-radius: 3px;'>Add to Cart</button>
64
  </div>
65
  """
66
  html_content += "</div>"
@@ -96,20 +82,48 @@ with gr.Blocks() as demo:
96
  <button onclick='placeOrder()' style='margin-top: 10px; padding: 10px; background-color: #007bff; color: white; border: none; border-radius: 5px; display: block; width: 100%;'>Place Order</button>
97
  </div>
98
 
 
 
 
 
 
 
 
 
 
99
  <script>
 
 
 
 
100
  window.toggleCartPopup = function() {
101
  const popup = document.getElementById('cart-popup');
102
  popup.style.display = popup.style.display === 'block' ? 'none' : 'block';
103
  }
104
 
105
- window.addToCart = function(name, price) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  fetch('/run/predict', {
107
  method: 'POST',
108
  headers: { 'Content-Type': 'application/json' },
109
- body: JSON.stringify({ data: [name, price] })
110
  }).then(response => response.json()).then(data => {
111
  document.getElementById('cart-content').innerHTML = data.data;
112
- alert(`${name} has been added to your cart.`);
 
113
  });
114
  }
115
 
 
17
  cart.append({"name": item_name, "price": price, "extras": extras, "count": 1})
18
  return update_cart()
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  def update_cart():
21
  if not cart:
22
  return "<p>Your cart is empty.</p>"
 
46
  <h4>{dish['name']}</h4>
47
  <p>{dish['description']}</p>
48
  <p><strong>Price:</strong> ${dish['price']}</p>
49
+ <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>
50
  </div>
51
  """
52
  html_content += "</div>"
 
82
  <button onclick='placeOrder()' style='margin-top: 10px; padding: 10px; background-color: #007bff; color: white; border: none; border-radius: 5px; display: block; width: 100%;'>Place Order</button>
83
  </div>
84
 
85
+ <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); width: 300px;'>
86
+ <span onclick='closeMenuPopup()' style='position: absolute; top: 10px; right: 15px; font-size: 20px; font-weight: bold; cursor: pointer;'>&times;</span>
87
+ <img id='popup-image' src='' style='width: 100%; border-radius: 5px; margin-bottom: 10px;'>
88
+ <h4 id='popup-title'></h4>
89
+ <p id='popup-description'></p>
90
+ <p id='popup-price'></p>
91
+ <button onclick='addItemToCartFromPopup()' style='padding: 5px 10px; background-color: #28a745; color: white; border: none; border-radius: 5px; width: 100%;'>Add to Cart</button>
92
+ </div>
93
+
94
  <script>
95
+ let selectedItem = '';
96
+ let selectedPrice = 0;
97
+ let selectedExtras = 'None';
98
+
99
  window.toggleCartPopup = function() {
100
  const popup = document.getElementById('cart-popup');
101
  popup.style.display = popup.style.display === 'block' ? 'none' : 'block';
102
  }
103
 
104
+ window.showMenuPopup = function(name, description, price, image) {
105
+ selectedItem = name;
106
+ selectedPrice = price;
107
+ document.getElementById('popup-title').textContent = name;
108
+ document.getElementById('popup-description').textContent = description;
109
+ document.getElementById('popup-price').textContent = `Price: $${price}`;
110
+ document.getElementById('popup-image').src = image;
111
+ document.getElementById('menu-popup').style.display = 'block';
112
+ }
113
+
114
+ window.closeMenuPopup = function() {
115
+ document.getElementById('menu-popup').style.display = 'none';
116
+ }
117
+
118
+ window.addItemToCartFromPopup = function() {
119
  fetch('/run/predict', {
120
  method: 'POST',
121
  headers: { 'Content-Type': 'application/json' },
122
+ body: JSON.stringify({ data: [selectedItem, selectedPrice, selectedExtras] })
123
  }).then(response => response.json()).then(data => {
124
  document.getElementById('cart-content').innerHTML = data.data;
125
+ alert(`${selectedItem} has been added to your cart.`);
126
+ closeMenuPopup();
127
  });
128
  }
129