Rammohan0504 commited on
Commit
c1fbff5
·
verified ·
1 Parent(s): 28fdec6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -9
app.py CHANGED
@@ -60,7 +60,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>"
@@ -86,12 +86,6 @@ with gr.Blocks() as demo:
86
  def add_to_cart_handler(item_name, price):
87
  return add_item_to_cart(item_name, price)
88
 
89
- add_to_cart_interface = gr.Interface(
90
- fn=add_to_cart_handler,
91
- inputs=[gr.Textbox(visible=False, label="Item Name"), gr.Textbox(visible=False, label="Price")],
92
- outputs=cart_display,
93
- )
94
-
95
  gr.HTML("""
96
  <div id='cart-icon' style='position: fixed; top: 10px; right: 10px; cursor: pointer;'>
97
  <img src='https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Shopping_cart_icon.svg/512px-Shopping_cart_icon.svg.png' alt='Cart' style='width: 40px;' onclick='toggleCartPopup()'>
@@ -99,7 +93,7 @@ with gr.Blocks() as demo:
99
  <div id='cart-popup' style='display: none; position: fixed; top: 50px; right: 10px; background: white; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); width: 300px; height: auto; max-height: 80vh; overflow-y: auto;'>
100
  <span onclick='toggleCartPopup()' style='position: absolute; top: 10px; right: 15px; font-size: 20px; font-weight: bold; cursor: pointer;'>&times;</span>
101
  <div id='cart-content' style='margin-bottom: 10px;'>Your cart is empty.</div>
102
- <button onclick='placeOrder()' style='margin-top: 10px; padding: 10px; background-color: #007bff; color: white; border: none; border-radius: 5px; display: block; width: auto;'>Place Order</button>
103
  </div>
104
 
105
  <script>
@@ -114,7 +108,7 @@ with gr.Blocks() as demo:
114
  headers: { 'Content-Type': 'application/json' },
115
  body: JSON.stringify({ data: [name, price] })
116
  }).then(response => response.json()).then(data => {
117
- document.getElementById('cart-content').innerHTML = data.data[0];
118
  alert(`${name} has been added to your cart.`);
119
  });
120
  }
 
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>"
 
86
  def add_to_cart_handler(item_name, price):
87
  return add_item_to_cart(item_name, price)
88
 
 
 
 
 
 
 
89
  gr.HTML("""
90
  <div id='cart-icon' style='position: fixed; top: 10px; right: 10px; cursor: pointer;'>
91
  <img src='https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Shopping_cart_icon.svg/512px-Shopping_cart_icon.svg.png' alt='Cart' style='width: 40px;' onclick='toggleCartPopup()'>
 
93
  <div id='cart-popup' style='display: none; position: fixed; top: 50px; right: 10px; background: white; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); width: 300px; height: auto; max-height: 80vh; overflow-y: auto;'>
94
  <span onclick='toggleCartPopup()' style='position: absolute; top: 10px; right: 15px; font-size: 20px; font-weight: bold; cursor: pointer;'>&times;</span>
95
  <div id='cart-content' style='margin-bottom: 10px;'>Your cart is empty.</div>
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>
 
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
  }