Rammohan0504 commited on
Commit
0ba6306
·
verified ·
1 Parent(s): 01b9233

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -103
app.py CHANGED
@@ -138,109 +138,6 @@ with gr.Blocks() as demo:
138
 
139
  # Dish display
140
  dish_display = gr.HTML(value=display_dishes("ALL"))
141
-
142
- popup_js = """
143
- <script>
144
- let cursorX = 0;
145
- let cursorY = 0;
146
-
147
- document.addEventListener("mousemove", (event) => {
148
- cursorX = event.clientX;
149
- cursorY = event.clientY;
150
- });
151
-
152
- function showPopup(name, description, price) {
153
- const popup = document.getElementById("custom-popup");
154
- popup.style.left = cursorX + "px";
155
- popup.style.top = cursorY + "px";
156
- popup.innerHTML = `
157
- <h3 style="margin: 0;">${name}</h3>
158
- <p style="margin: 5px 0;">${description}</p>
159
- <p style="margin: 5px 0; font-weight: bold;">Price: ${price}</p>
160
- `;
161
- popup.style.display = "block";
162
- }
163
-
164
- function hidePopup() {
165
- const popup = document.getElementById("custom-popup");
166
- popup.style.display = "none";
167
- }
168
- </script>
169
- """
170
-
171
- # HTML for popup container
172
- popup_html = """
173
- <div id="custom-popup"
174
- style="position: fixed; display: none; background: white; border: 1px solid black;
175
- padding: 10px; z-index: 1000; border-radius: 10px; box-shadow: 0px 4px 6px rgba(0,0,0,0.1);">
176
- </div>
177
- """
178
-
179
- # Generate dish cards
180
- def display_dishes(category):
181
- html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: space-between;'>"
182
- for dish in menu_data:
183
- if category == "ALL" or dish["category"] == category:
184
- html_content += f"""
185
- <div style='margin: 10px; width: 30%; border: 1px solid #ddd; border-radius: 10px; padding: 10px;'>
186
- <img src='{dish['image']}' alt='{dish['name']}'
187
- style='width: 100%; height: auto; border-radius: 5px;'>
188
- <h3>{dish['name']}</h3>
189
- <p>{dish['description']}</p>
190
- <p>Price: {dish['price']}</p>
191
- <button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}')"
192
- style='background-color: #007bff; color: white; border: none; padding: 5px 10px; cursor: pointer;'>
193
- Add
194
- </button>
195
- </div>
196
- """
197
- html_content += "</div>"
198
- return html_content
199
-
200
-
201
- # Filter dishes by category
202
- def filter_dishes(category):
203
- if category == "ALL":
204
- return menu_data
205
- return [dish for dish in menu_data if dish["category"] == category]
206
-
207
- # Generate dish cards
208
- def display_dishes(category):
209
- filtered_dishes = filter_dishes(category)
210
- html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: space-between;'>"
211
- for dish in filtered_dishes:
212
- html_content += f"""
213
- <div style='margin: 10px; width: 30%; border: 1px solid #ddd; border-radius: 10px; padding: 10px;'>
214
- <img src='{dish['image']}' alt='{dish['name']}' style='width: 100%; height: auto; border-radius: 5px;'>
215
- <h3>{dish['name']}</h3>
216
- <p>{dish['description']}</p>
217
- <p>Price: {dish['price']}</p>
218
- <button onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}', '{dish['price']}')"
219
- style='background-color: #007bff; color: white; border: none; padding: 5px 10px; cursor: pointer;'>
220
- Add
221
- </button>
222
- </div>
223
- """
224
- html_content += "</div>"
225
- return html_content
226
-
227
- # Main Gradio App
228
- with gr.Blocks() as demo:
229
- gr.HTML(popup_html) # Add the popup container
230
- gr.HTML(popup_js) # Add the JavaScript
231
-
232
- gr.HTML("<h1 style='text-align: center;'>Dynamic Restaurant Menu</h1>")
233
-
234
- # Buttons for filtering categories
235
- with gr.Row():
236
- btn_all = gr.Button("ALL")
237
- btn_vegan = gr.Button("VEGAN")
238
- btn_halal = gr.Button("HALAL")
239
-
240
- # Dish display
241
- dish_display = gr.HTML(value=display_dishes("ALL"))
242
-
243
-
244
 
245
  # JavaScript for managing the pop-up
246
  gr.HTML(f"""
 
138
 
139
  # Dish display
140
  dish_display = gr.HTML(value=display_dishes("ALL"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
  # JavaScript for managing the pop-up
143
  gr.HTML(f"""