Rammohan0504 commited on
Commit
0290f5a
·
verified ·
1 Parent(s): 66f7c8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -75
app.py CHANGED
@@ -102,10 +102,48 @@ 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
  # Generate dish cards with "Add" button
107
  def display_dishes(category):
108
- filtered_dishes = filter_dishes(category)
109
  html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%;'>"
110
  for dish in filtered_dishes:
111
  html_content += f"""
@@ -120,92 +158,42 @@ def display_dishes(category):
120
  <div style='text-align: center;'>
121
  <img src='{dish['image']}' alt='{dish['name']}'
122
  style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
123
- <button onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')"
124
- style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
125
- border-radius: 5px; cursor: pointer;">Add</button>
126
  </div>
127
  </div>
128
  """
129
  html_content += "</div>"
130
  return html_content
131
 
132
- # Main Gradio App
133
  with gr.Blocks() as demo:
134
- gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
135
-
136
- # Buttons for category selection
137
- with gr.Row():
138
- btn_all = gr.Button("ALL")
139
- btn_vegan = gr.Button("VEGAN")
140
- btn_halal = gr.Button("HALAL")
141
-
142
  # Dish display
143
  dish_display = gr.HTML(value=display_dishes("ALL"))
144
 
145
- # JavaScript for managing the pop-up
146
- gr.HTML(f"""
147
- <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
148
- background-color: white; padding: 20px; border-radius: 10px;
149
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
150
- <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
151
- <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
152
- <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
153
- <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
154
-
155
- <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
156
- <div id="spice-levels-container" style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
157
- """ + "".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]) + """
158
- </div>
159
 
160
- <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
161
- <div id="extras-container" style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
162
- """ + "".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]) + """
163
- </div>
164
 
165
- <button onclick="addToCart()"
166
- style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
167
- border-radius: 5px; cursor: pointer;">Add to Cart</button>
168
- <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
169
- color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
170
- </div>
171
- <script>
172
- let selectedSpice = null;
173
- let selectedExtras = [];
174
-
175
- function showPopup(image, title, description, price) {
176
- document.getElementById('popup-image').src = image;
177
- document.getElementById('popup-title').textContent = title;
178
- document.getElementById('popup-description').textContent = description;
179
- document.getElementById('popup-price').textContent = "Price: " + price;
180
-
181
- document.getElementById('popup').style.display = 'block';
182
- }
183
-
184
- function closePopup() {
185
- document.getElementById('popup').style.display = 'none';
186
- }
187
-
188
- function addToCart() {
189
- const spice = document.querySelector('input[name=spice]:checked')?.value || "No spice selected";
190
- const extras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(input => input.value);
191
- alert(`Added with spice level: ${spice}, and extras: ${extras.join(", ")}`);
192
- closePopup();
193
- }
194
- </script>
195
- """)
196
-
197
- # Button click events
198
- btn_all.click(
199
- lambda: gr.update(value=display_dishes("ALL")),
200
- outputs=dish_display
201
- )
202
- btn_vegan.click(
203
- lambda: gr.update(value=display_dishes("VEGAN")),
204
- outputs=dish_display
205
- )
206
- btn_halal.click(
207
- lambda: gr.update(value=display_dishes("HALAL")),
208
- outputs=dish_display
209
  )
210
 
 
 
 
 
 
211
  demo.launch()
 
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
  <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()