Rammohan0504 commited on
Commit
de176b0
·
verified ·
1 Parent(s): 03dc2c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -39
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import gradio as gr
2
 
3
  menu_data = [
@@ -98,7 +100,7 @@ popup_js = """
98
  function showPopup(name, description, price, image) {
99
  const popup = document.getElementById("custom-popup");
100
  const overlay = document.getElementById("overlay");
101
- popup.innerHTML = `
102
  <img src="${image}" alt="${name}" style="width: 100%; height: 250px; border-radius: 10px; margin-bottom: 10px;">
103
  <h3 style="margin-top: 10px;">${name}</h3>
104
  <p>${description}</p>
@@ -106,25 +108,25 @@ popup_js = """
106
 
107
  <h4 style="margin-top: 20px;">Choose a Spice Level</h4>
108
  <div style="display: flex; flex-wrap: wrap; gap: 10px;">
109
- ${["American Mild", "American Medium", "American Spicy", "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"].map(spice => `
110
  <label style="margin-right: 10px;">
111
  <input type="radio" name="spice" value="${spice}"> ${spice}
112
  </label>
113
- `).join("")}
114
  </div>
115
 
116
  <h4 style="margin-top: 20px;">Choose Extras</h4>
117
  <div style="display: flex; flex-wrap: wrap; gap: 10px;">
118
- ${["Extra Raitha 4oz + $1.00", "Extra Raitha 8oz + $2.00", "Extra Onion + $1.00", "Extra Onion & Lemon + $2.00"].map(extra => `
119
  <label style="margin-right: 10px;">
120
  <input type="checkbox" name="extras" value="${extra}"> ${extra}
121
  </label>
122
- `).join("")}
123
  </div>
124
 
125
  <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button>
126
  <button onclick="closePopup()" style="margin-top: 20px; margin-left: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
127
- `;
128
  popup.style.display = "block";
129
  overlay.style.display = "block";
130
  }
@@ -147,11 +149,10 @@ popup_html = """
147
  """
148
 
149
  # Generate dish cards
150
- def display_dishes(category, keyword=""):
151
  html_content = "<div style='display: flex; flex-direction: column; gap: 20px; padding-bottom: 20px; box-sizing: border-box;'>"
152
  for dish in menu_data:
153
- # Filter by category and keyword
154
- if (category == "ALL" or dish["category"] == category) and (keyword.lower() in dish["name"].lower()):
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: 3; text-align: left;'>
@@ -166,48 +167,48 @@ def display_dishes(category, keyword=""):
166
  Add
167
  </button>
168
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  </div>
170
  """
171
  html_content += "</div>"
172
  return html_content
173
 
174
-
175
  # Main Gradio App
176
- with gr.Blocks(css="#dish-container {min-height: 100vh; overflow-y: auto;}") as demo:
177
  gr.HTML(popup_html) # Add the popup container and overlay
178
  gr.HTML(popup_js) # Add the JavaScript
179
 
180
  gr.HTML("<h1 style='text-align: center;'>🍛 Biryani Hub Menu 🍛</h1>")
181
 
182
- # Two containers
183
- with gr.Row():
184
- with gr.Column():
185
- gr.HTML("<h2 style='text-align: center;'>All Dishes</h2>")
186
- all_dishes_display = gr.HTML(value=display_dishes("ALL"))
187
- with gr.Column():
188
- gr.HTML("<h2 style='text-align: center;'>Vegan and Halal Dishes</h2>")
189
- vegan_halal_display = gr.HTML(value=display_dishes("ALL", keyword=""))
190
-
191
- # Inputs to filter containers
192
- keyword_input_all = gr.Textbox(
193
- label="Search in All Dishes",
194
- placeholder="Enter keyword to filter (e.g., Chicken)"
195
- )
196
- keyword_input_vegan_halal = gr.Textbox(
197
- label="Search in Vegan and Halal",
198
- placeholder="Enter keyword to filter (e.g., Curry)"
199
  )
200
 
201
- # Update containers dynamically
202
- keyword_input_all.change(
203
- lambda keyword: gr.update(value=display_dishes("ALL", keyword)),
204
- inputs=keyword_input_all,
205
- outputs=all_dishes_display
206
- )
207
- keyword_input_vegan_halal.change(
208
- lambda keyword: gr.update(value=display_dishes("VEGAN", keyword) + display_dishes("HALAL", keyword)),
209
- inputs=keyword_input_vegan_halal,
210
- outputs=vegan_halal_display
211
  )
212
 
213
- demo.launch()
 
1
+
2
+ You said:
3
  import gradio as gr
4
 
5
  menu_data = [
 
100
  function showPopup(name, description, price, image) {
101
  const popup = document.getElementById("custom-popup");
102
  const overlay = document.getElementById("overlay");
103
+ popup.innerHTML =
104
  <img src="${image}" alt="${name}" style="width: 100%; height: 250px; border-radius: 10px; margin-bottom: 10px;">
105
  <h3 style="margin-top: 10px;">${name}</h3>
106
  <p>${description}</p>
 
108
 
109
  <h4 style="margin-top: 20px;">Choose a Spice Level</h4>
110
  <div style="display: flex; flex-wrap: wrap; gap: 10px;">
111
+ ${["American Mild", "American Medium", "American Spicy", "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"].map(spice =>
112
  <label style="margin-right: 10px;">
113
  <input type="radio" name="spice" value="${spice}"> ${spice}
114
  </label>
115
+ ).join("")}
116
  </div>
117
 
118
  <h4 style="margin-top: 20px;">Choose Extras</h4>
119
  <div style="display: flex; flex-wrap: wrap; gap: 10px;">
120
+ ${["Extra Raitha 4oz + $1.00", "Extra Raitha 8oz + $2.00", "Extra Onion + $1.00", "Extra Onion & Lemon + $2.00"].map(extra =>
121
  <label style="margin-right: 10px;">
122
  <input type="checkbox" name="extras" value="${extra}"> ${extra}
123
  </label>
124
+ ).join("")}
125
  </div>
126
 
127
  <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button>
128
  <button onclick="closePopup()" style="margin-top: 20px; margin-left: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
129
+ ;
130
  popup.style.display = "block";
131
  overlay.style.display = "block";
132
  }
 
149
  """
150
 
151
  # Generate dish cards
152
+ def display_dishes(category):
153
  html_content = "<div style='display: flex; flex-direction: column; gap: 20px; padding-bottom: 20px; box-sizing: border-box;'>"
154
  for dish in menu_data:
155
+ if category == "ALL":
 
156
  html_content += f"""
157
  <div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;'>
158
  <div style='flex: 3; text-align: left;'>
 
167
  Add
168
  </button>
169
  </div>
170
+
171
+ elif category == dish["category"] == category:
172
+ html_content += f"""
173
+ <div style='display: flex; align-items: center; justify-content: space-between; padding: 20px; height:100%; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;'>
174
+ <div style='flex: 3; text-align: left;'>
175
+ <h3 style='margin: 0; font-size: 20px;'>{dish['name']}</h3>
176
+ <p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p>
177
+ <p style='margin: 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p>
178
+ </div>
179
+ <div style='flex: 1; text-align: center;'>
180
+ <img src='{dish['image']}' alt='{dish['name']}' style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px;'>
181
+ <button onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')"
182
+ style='margin-top: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>
183
+ Add
184
+ </button>
185
+ </div>
186
  </div>
187
  """
188
  html_content += "</div>"
189
  return html_content
190
 
 
191
  # Main Gradio App
192
+ with gr.Blocks (css="#dish-container {min-height: 100vh; overflow-y: auto;}") as demo:
193
  gr.HTML(popup_html) # Add the popup container and overlay
194
  gr.HTML(popup_js) # Add the JavaScript
195
 
196
  gr.HTML("<h1 style='text-align: center;'>🍛 Biryani Hub Menu 🍛</h1>")
197
 
198
+ category_selector = gr.Radio(
199
+ ["ALL", "VEGAN", "HALAL"],
200
+ label="Select Category",
201
+ value="ALL"
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  )
203
 
204
+ # Dish display
205
+ dish_display = gr.HTML(value=display_dishes("ALL"))
206
+
207
+ # Radio button change event
208
+ category_selector.change(
209
+ lambda category: gr.update(value=display_dishes(category)),
210
+ inputs=category_selector,
211
+ outputs=dish_display
 
 
212
  )
213
 
214
+ demo.launch()