Rammohan0504 commited on
Commit
b9d952b
Β·
verified Β·
1 Parent(s): 1e5fb02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -55
app.py CHANGED
@@ -21,8 +21,6 @@ menu_data = [
21
  ]
22
 
23
 
24
- cart = []
25
-
26
  extras = [
27
  {"name": "Extra Raitha 4oz", "price": "$1.00"},
28
  {"name": "Extra Raitha 8oz", "price": "$2.00"},
@@ -65,83 +63,74 @@ def display_dishes(category):
65
  html_content += "</div>"
66
  return html_content
67
 
68
-
69
- # Add to cart
70
- def add_to_cart(item_name, quantity, custom_preference):
71
- cart.append({"name": item_name, "quantity": quantity, "custom_preference": custom_preference})
72
- return display_cart()
73
-
74
- # Display cart items
75
- def display_cart():
76
- if not cart:
77
- return "<p>Your cart is empty.</p>"
78
- html_content = "<div style='text-align: left;'>"
79
- for item in cart:
80
- html_content += f"<p>- {item['name']} (x{item['quantity']}) - Custom: {item['custom_preference']}</p>"
81
- html_content += "</div>"
82
- return html_content
83
-
84
  # Main Gradio App
85
  with gr.Blocks() as demo:
86
  gr.HTML("<h1 style='text-align: center; color: #333;'>πŸ› Biryani Hub Menu πŸ›</h1>")
87
 
88
- with gr.Row():
89
- gr.HTML("<span style='font-size: 24px; cursor: pointer;'>πŸ›’</span>")
90
- btn_cart = gr.Button("View Cart")
91
-
92
- cart_display = gr.HTML(value=display_cart())
93
-
94
  with gr.Row():
95
  btn_all = gr.Button("ALL")
96
  btn_vegan = gr.Button("VEGAN")
97
  btn_halal = gr.Button("HALAL")
98
 
99
- dish_display = gr.HTML(value=display_dishes("ALL"))
 
100
 
101
- gr.HTML("""
102
- <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 400px;">
103
- <span onclick="closePopup()" style="position: absolute; top: 10px; right: 15px; cursor: pointer; font-size: 18px;">&times;</span>
 
 
 
 
 
104
  <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
105
  <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
106
  <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
107
- <p id="popup-image-url" style="margin-top: 10px; font-size: 14px; color: #666;"></p>
108
-
109
- <label for="popup-quantity" style="margin-top: 20px; display: block; text-align: left;">Quantity:</label>
110
- <input id="popup-quantity" type="number" min="1" value="1" style="width: 100%; margin-top: 10px; padding: 5px; border: 1px solid #ddd; border-radius: 5px;">
111
-
112
- <label for="popup-custom" style="margin-top: 20px; display: block; text-align: left;">Custom Preferences:</label>
113
- <textarea id="popup-custom" placeholder="Add your custom preferences here..." style="width: 100%; margin-top: 10px; padding: 5px; border: 1px solid #ddd; border-radius: 5px;"></textarea>
114
 
115
- <button onclick="submitPopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button>
 
 
 
116
  </div>
117
  <script>
118
- function showPopup(name, description, price, imageUrl) {
119
- document.getElementById('popup-title').textContent = name;
 
120
  document.getElementById('popup-description').textContent = description;
121
- document.getElementById('popup-price').textContent = price;
122
- document.getElementById('popup-image-url').textContent = imageUrl;
 
123
  document.getElementById('popup').style.display = 'block';
124
  }
125
-
126
  function closePopup() {
127
  document.getElementById('popup').style.display = 'none';
128
  }
129
-
130
- function submitPopup() {
131
- const name = document.getElementById('popup-title').textContent;
132
- const quantity = document.getElementById('popup-quantity').value;
133
- const customPreference = document.getElementById('popup-custom').value;
134
- gr.Interface.postMessage('add_to_cart', [name, quantity, customPreference]);
135
- closePopup();
136
  }
137
  </script>
138
  """)
139
 
140
-
141
  # Button click events
142
- btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
143
- btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
144
- btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
145
- btn_cart.click(lambda: gr.update(value=display_cart()), outputs=cart_display)
146
-
147
- demo.launch()
 
 
 
 
 
 
 
 
 
21
  ]
22
 
23
 
 
 
24
  extras = [
25
  {"name": "Extra Raitha 4oz", "price": "$1.00"},
26
  {"name": "Extra Raitha 8oz", "price": "$2.00"},
 
63
  html_content += "</div>"
64
  return html_content
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  # Main Gradio App
67
  with gr.Blocks() as demo:
68
  gr.HTML("<h1 style='text-align: center; color: #333;'>πŸ› Biryani Hub Menu πŸ›</h1>")
69
 
70
+ # Buttons for category selection
 
 
 
 
 
71
  with gr.Row():
72
  btn_all = gr.Button("ALL")
73
  btn_vegan = gr.Button("VEGAN")
74
  btn_halal = gr.Button("HALAL")
75
 
76
+ # Dish display
77
+ dish_display = gr.HTML(value=display_dishes("ALL"))
78
 
79
+ # JavaScript for managing the pop-up
80
+ gr.HTML(f"""
81
+ <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
82
+ background-color: white; padding: 20px; border-radius: 10px;
83
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
84
+ <span onclick="closePopup()" style="position: absolute; top: 10px; right: 10px; cursor: pointer; font-size: 20px;">&times;</span>
85
+
86
+ <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
87
  <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
88
  <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
89
  <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
90
+
91
+
92
+ <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
93
+ <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
94
+ """ + "".join([f'<label style="margin-right: 10px; display: block;"><input type="checkbox" name="extras" value="{extra["name"]}" style="margin-right: 5px;">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
95
+ </div>
 
96
 
97
+ <button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
98
+ style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
99
+ border-radius: 5px; cursor: pointer;">Add to Cart</button>
100
+
101
  </div>
102
  <script>
103
+ function showPopup(image, title, description, price) {
104
+ document.getElementById('popup-image').src = image;
105
+ document.getElementById('popup-title').textContent = title;
106
  document.getElementById('popup-description').textContent = description;
107
+ document.getElementById('popup-price').textContent = "Price: " + price;
108
+
109
+ // Display the popup
110
  document.getElementById('popup').style.display = 'block';
111
  }
 
112
  function closePopup() {
113
  document.getElementById('popup').style.display = 'none';
114
  }
115
+ function addToCart(dishName, spiceLevel) {
116
+ const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
117
+ alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
 
 
 
 
118
  }
119
  </script>
120
  """)
121
 
 
122
  # Button click events
123
+ btn_all.click(
124
+ lambda: gr.update(value=display_dishes("ALL")),
125
+ outputs=dish_display
126
+ )
127
+ btn_vegan.click(
128
+ lambda: gr.update(value=display_dishes("VEGAN")),
129
+ outputs=dish_display
130
+ )
131
+ btn_halal.click(
132
+ lambda: gr.update(value=display_dishes("HALAL")),
133
+ outputs=dish_display
134
+ )
135
+
136
+ demo.launch()