Rammohan0504 commited on
Commit
a4cac9e
·
verified ·
1 Parent(s): 10ccfdf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -8
app.py CHANGED
@@ -147,6 +147,55 @@ popup_html = """
147
  """
148
 
149
  # Generate dish cards
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  # Generate dish cards
151
  def display_dishes(category):
152
  html_content = "<div style='display: flex; flex-direction: column; gap: 20px; width: 80%; margin: auto;'>"
@@ -154,23 +203,23 @@ def display_dishes(category):
154
  if category == "ALL" or dish["category"] == category:
155
  html_content += f"""
156
  <div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;'>
157
- <div style='flex: 1; display: flex; align-items: center;'>
158
- <img src='{dish['image']}' alt='{dish['name']}' style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px; margin-right: 20px;'>
159
- <button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')"
160
- style='padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>
161
- Add
162
- </button>
163
- </div>
164
  <div style='flex: 3; text-align: left;'>
165
  <h3 style='margin: 0; font-size: 20px;'>{dish['name']}</h3>
166
  <p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
167
  <p style='margin: 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
168
  </div>
 
 
 
 
 
 
 
169
  </div>
170
  """
171
  html_content += "</div>"
172
  return html_content
173
-
174
  # Main Gradio App
175
  with gr.Blocks() as demo:
176
  gr.HTML(popup_html) # Add the popup container and overlay
 
147
  """
148
 
149
  # Generate dish cards
150
+ import gradio as gr
151
+
152
+ menu_data = [
153
+ {"name": "Veg Burger", "category": "VEGAN",
154
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg",
155
+ "description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.",
156
+ "price": "$8.99"},
157
+ {"name": "Chicken Biryani", "category": "HALAL",
158
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_biryani.jpg",
159
+ "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
160
+ "price": "$12.99"}
161
+ # Add more items as needed
162
+ ]
163
+
164
+ # JavaScript for popup modal
165
+ popup_js = """
166
+ <script>
167
+ function showPopup(name, description, price, image) {
168
+ const popup = document.getElementById("custom-popup");
169
+ const overlay = document.getElementById("overlay");
170
+ popup.innerHTML = `
171
+ <img src="${image}" alt="${name}" style="width: auto; height: 250px; border-radius: 10px; margin-bottom: 10px;">
172
+ <h3 style="margin-top: 10px;">${name}</h3>
173
+ <p>${description}</p>
174
+ <p style="font-weight: bold;">Price: ${price}</p>
175
+ <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button>
176
+ <button onclick="closePopup()" style="margin-top: 20px; margin-left: 10px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
177
+ `;
178
+ popup.style.display = "block";
179
+ overlay.style.display = "block";
180
+ }
181
+
182
+ function closePopup() {
183
+ const popup = document.getElementById("custom-popup");
184
+ const overlay = document.getElementById("overlay");
185
+ popup.style.display = "none";
186
+ overlay.style.display = "none";
187
+ }
188
+ </script>
189
+ """
190
+
191
+ # HTML for popup modal
192
+ popup_html = """
193
+ <div id="overlay" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: none; z-index: 999;"></div>
194
+ <div id="custom-popup"
195
+ style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 60%; max-width: 600px; background: white; padding: 20px; border-radius: 10px; box-shadow: 0px 4px 6px rgba(0,0,0,0.1); display: none; z-index: 1000; text-align: center;">
196
+ </div>
197
+ """
198
+
199
  # Generate dish cards
200
  def display_dishes(category):
201
  html_content = "<div style='display: flex; flex-direction: column; gap: 20px; width: 80%; margin: auto;'>"
 
203
  if category == "ALL" or dish["category"] == category:
204
  html_content += f"""
205
  <div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;'>
 
 
 
 
 
 
 
206
  <div style='flex: 3; text-align: left;'>
207
  <h3 style='margin: 0; font-size: 20px;'>{dish['name']}</h3>
208
  <p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
209
  <p style='margin: 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
210
  </div>
211
+ <div style='flex: 1; display: flex; flex-direction: column; align-items: center;'>
212
+ <img src='{dish['image']}' alt='{dish['name']}' style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px; margin-bottom: 10px;'>
213
+ <button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')"
214
+ style='padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>
215
+ Add
216
+ </button>
217
+ </div>
218
  </div>
219
  """
220
  html_content += "</div>"
221
  return html_content
222
+
223
  # Main Gradio App
224
  with gr.Blocks() as demo:
225
  gr.HTML(popup_html) # Add the popup container and overlay