Rammohan0504 commited on
Commit
0fd1b8b
·
verified ·
1 Parent(s): 0290f5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -64
app.py CHANGED
@@ -84,7 +84,6 @@ menu_data = [
84
 
85
 
86
 
87
- # Spice levels and extras
88
  spice_levels = ["American Mild", "American Medium", "American Spicy",
89
  "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
90
  extras = [
@@ -102,48 +101,10 @@ def filter_dishes(category):
102
  if category == "ALL":
103
  return menu_data
104
  return [dish for dish in menu_data if dish["category"] == category]
105
-
106
-
107
- # Generate dish cards with "Add" button
108
- # Spice levels and extras
109
- spice_levels = ["American Mild", "American Medium", "American Spicy",
110
- "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
111
- extras = [
112
- {"name": "Extra Raitha 4oz", "price": "$1.00"},
113
- {"name": "Extra Raitha 8oz", "price": "$2.00"},
114
- {"name": "Extra Salan 4oz", "price": "$1.00"},
115
- {"name": "Extra Salan 8oz", "price": "$2.00"},
116
- {"name": "Extra Onion", "price": "$1.00"},
117
- {"name": "Extra Onion & Lemon", "price": "$2.00"},
118
- {"name": "Extra Fried Onion 4oz", "price": "$2.00"},
119
- ]
120
-
121
- # Initialize cart as a global state
122
- cart = []
123
-
124
- # Add dish to cart
125
- def add_to_cart(dish_name, spice_level, extras):
126
- global cart
127
- cart.append({
128
- "Dish": dish_name,
129
- "Spice Level": spice_level,
130
- "Extras": extras,
131
- })
132
- return cart
133
-
134
- # Display cart
135
- def display_cart():
136
- if not cart:
137
- return "Cart is empty."
138
- cart_html = "<h3>Cart Contents:</h3><ul>"
139
- for item in cart:
140
- cart_html += f"<li>{item['Dish']} - Spice Level: {item['Spice Level']}, Extras: {', '.join(item['Extras'])}</li>"
141
- cart_html += "</ul>"
142
- return cart_html
143
 
144
  # Generate dish cards with "Add" button
145
  def display_dishes(category):
146
- filtered_dishes = menu_data # Only one item for simplicity
147
  html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%;'>"
148
  for dish in filtered_dishes:
149
  html_content += f"""
@@ -158,42 +119,92 @@ def display_dishes(category):
158
  <div style='text-align: center;'>
159
  <img src='{dish['image']}' alt='{dish['name']}'
160
  style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
 
 
 
161
  </div>
162
  </div>
163
  """
164
  html_content += "</div>"
165
  return html_content
166
 
167
- # Gradio interface
168
  with gr.Blocks() as demo:
169
- # Header
170
- gr.HTML("<h1 style='text-align: center;'>🍛 Biryani Hub Menu 🍛</h1>")
171
-
 
 
 
 
 
172
  # Dish display
173
  dish_display = gr.HTML(value=display_dishes("ALL"))
174
 
175
- # User inputs for spice level and extras
176
- spice_level = gr.Radio(spice_levels, label="Choose Spice Level")
177
- extra_options = gr.CheckboxGroup(
178
- [f"{extra['name']} ({extra['price']})" for extra in extras], label="Choose Extras"
179
- )
180
-
181
- # Add to Cart button
182
- add_button = gr.Button("Add to Cart")
 
 
 
 
 
 
183
 
184
- # Cart display
185
- cart_display = gr.HTML(value="Cart is empty.")
 
 
186
 
187
- # Add to cart functionality
188
- add_button.click(
189
- fn=lambda spice, extras: add_to_cart("Vegetable Biryani", spice, extras),
190
- inputs=[spice_level, extra_options],
191
- outputs=cart_display,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  )
193
 
194
- # Layout
195
- gr.Row([spice_level, extra_options])
196
- gr.Row([add_button, cart_display])
197
-
198
- # Launch app
199
  demo.launch()
 
84
 
85
 
86
 
 
87
  spice_levels = ["American Mild", "American Medium", "American Spicy",
88
  "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
89
  extras = [
 
101
  if category == "ALL":
102
  return menu_data
103
  return [dish for dish in menu_data if dish["category"] == category]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
  # Generate dish cards with "Add" button
106
  def display_dishes(category):
107
+ filtered_dishes = filter_dishes(category)
108
  html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%;'>"
109
  for dish in filtered_dishes:
110
  html_content += f"""
 
119
  <div style='text-align: center;'>
120
  <img src='{dish['image']}' alt='{dish['name']}'
121
  style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
122
+ <button onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')"
123
+ style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
124
+ border-radius: 5px; cursor: pointer;">Add</button>
125
  </div>
126
  </div>
127
  """
128
  html_content += "</div>"
129
  return html_content
130
 
131
+ # Main Gradio App
132
  with gr.Blocks() as demo:
133
+ gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
134
+
135
+ # Buttons for category selection
136
+ with gr.Row():
137
+ btn_all = gr.Button("ALL")
138
+ btn_vegan = gr.Button("VEGAN")
139
+ btn_halal = gr.Button("HALAL")
140
+
141
  # Dish display
142
  dish_display = gr.HTML(value=display_dishes("ALL"))
143
 
144
+ # JavaScript for managing the pop-up
145
+ gr.HTML(f"""
146
+ <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
147
+ background-color: white; padding: 20px; border-radius: 10px;
148
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
149
+ <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
150
+ <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
151
+ <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
152
+ <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
153
+
154
+ <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
155
+ <div id="spice-levels-container" style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
156
+ """ + "".join([f'<label style="margin-right: 10px; display: block;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>' for spice in spice_levels]) + """
157
+ </div>
158
 
159
+ <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
160
+ <div id="extras-container" style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
161
+ """ + "".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]) + """
162
+ </div>
163
 
164
+ <button onclick="addToCart()"
165
+ style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
166
+ border-radius: 5px; cursor: pointer;">Add to Cart</button>
167
+ <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
168
+ color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
169
+ </div>
170
+ <script>
171
+ let selectedSpice = null;
172
+ let selectedExtras = [];
173
+
174
+ function showPopup(image, title, description, price) {
175
+ document.getElementById('popup-image').src = image;
176
+ document.getElementById('popup-title').textContent = title;
177
+ document.getElementById('popup-description').textContent = description;
178
+ document.getElementById('popup-price').textContent = "Price: " + price;
179
+
180
+ document.getElementById('popup').style.display = 'block';
181
+ }
182
+
183
+ function closePopup() {
184
+ document.getElementById('popup').style.display = 'none';
185
+ }
186
+
187
+ function addToCart() {
188
+ const spice = document.querySelector('input[name=spice]:checked')?.value || "No spice selected";
189
+ const extras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(input => input.value);
190
+ alert(`Added with spice level: ${spice}, and extras: ${extras.join(", ")}`);
191
+ closePopup();
192
+ }
193
+ </script>
194
+ """)
195
+
196
+ # Button click events
197
+ btn_all.click(
198
+ lambda: gr.update(value=display_dishes("ALL")),
199
+ outputs=dish_display
200
+ )
201
+ btn_vegan.click(
202
+ lambda: gr.update(value=display_dishes("VEGAN")),
203
+ outputs=dish_display
204
+ )
205
+ btn_halal.click(
206
+ lambda: gr.update(value=display_dishes("HALAL")),
207
+ outputs=dish_display
208
  )
209
 
 
 
 
 
 
210
  demo.launch()