Rammohan0504 commited on
Commit
f597f53
Β·
verified Β·
1 Parent(s): aeab0c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -42
app.py CHANGED
@@ -65,7 +65,6 @@ menu_data = [
65
  # The rest of the code remains unchanged
66
 
67
 
68
- # Function to filter dishes by category
69
  def filter_dishes(category):
70
  if category == "ALL":
71
  return menu_data
@@ -96,67 +95,46 @@ def display_dishes(category):
96
  with gr.Blocks() as demo:
97
  gr.HTML("<h1 style='text-align: center; color: #333;'>πŸ› Biryani Hub Menu πŸ›</h1>")
98
 
 
 
 
 
 
 
99
  # Dish display
100
  dish_display = gr.HTML(value=display_dishes("ALL"))
101
 
102
- # JavaScript for managing the selected button and pop-up
103
  gr.HTML("""
104
- <div style="text-align: center; margin-bottom: 20px;">
105
- <button id="btn-all" class="category-btn" onclick="filterCategory('ALL', this)">ALL</button>
106
- <button id="btn-vegan" class="category-btn" onclick="filterCategory('VEGAN', this)">VEGAN</button>
107
- <button id="btn-halal" class="category-btn" onclick="filterCategory('HALAL', this)">HALAL</button>
 
 
 
 
108
  </div>
109
  <script>
110
- function filterCategory(category, button) {
111
- const input = document.querySelector('input[aria-label="dish_display"]');
112
- input.value = category;
113
- input.dispatchEvent(new Event('input'));
114
-
115
- // Highlight the selected button
116
- const buttons = document.querySelectorAll('.category-btn');
117
- buttons.forEach(btn => btn.style.backgroundColor = '');
118
- button.style.backgroundColor = 'green';
119
- button.style.color = 'white';
120
- }
121
-
122
  function showPopup(image, title, description) {
123
  document.getElementById('popup-image').src = image;
124
  document.getElementById('popup-title').textContent = title;
125
  document.getElementById('popup-description').textContent = description;
126
 
127
- // Adjust the popup to always appear in the middle
128
  const popup = document.getElementById('popup');
129
  popup.style.top = window.pageYOffset + 'px';
130
  popup.style.display = 'block';
131
  }
132
-
133
  function closePopup() {
134
  document.getElementById('popup').style.display = 'none';
135
  }
136
  </script>
137
  """)
138
 
139
- # Pop-up for dish details
140
- gr.HTML("""
141
- <div id="popup" style="
142
- display: none; position: fixed; top: 50%; align-items:center; justify-content:center; left: 50%; transform: translate(-50%, 100%);
143
- background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
144
- z-index: 11999; inset:0px; text-align: center; width: 300px;">
145
- <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
146
- <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
147
- <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
148
- <button onclick="closePopup()" style="
149
- margin-top: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
150
- border-radius: 5px; cursor: pointer;">Close</button>
151
- </div>
152
- """)
153
-
154
- # Dish display input for Gradio interaction
155
- gr.Textbox(visible=False, label="dish_display", interactive=False)
156
-
157
- # Link button clicks to Gradio logic
158
- btn_all = gr.Button("ALL").click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
159
- btn_vegan = gr.Button("VEGAN").click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
160
- btn_halal = gr.Button("HALAL").click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
161
 
162
  demo.launch()
 
65
  # The rest of the code remains unchanged
66
 
67
 
 
68
  def filter_dishes(category):
69
  if category == "ALL":
70
  return menu_data
 
95
  with gr.Blocks() as demo:
96
  gr.HTML("<h1 style='text-align: center; color: #333;'>πŸ› Biryani Hub Menu πŸ›</h1>")
97
 
98
+ # Buttons for category selection
99
+ with gr.Row():
100
+ btn_all = gr.Button("ALL")
101
+ btn_vegan = gr.Button("VEGAN")
102
+ btn_halal = gr.Button("HALAL")
103
+
104
  # Dish display
105
  dish_display = gr.HTML(value=display_dishes("ALL"))
106
 
107
+ # JavaScript for managing the pop-up
108
  gr.HTML("""
109
+ <div id="popup" style="display: none; position: fixed; left: 50%; transform: translate(-50%, 0);
110
+ background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
111
+ z-index: 1000; text-align: center; width: 300px;">
112
+ <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
113
+ <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
114
+ <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
115
+ <button onclick="closePopup()" style="margin-top: 10px; padding: 10px 20px; background-color: #28a745;
116
+ color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
117
  </div>
118
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
119
  function showPopup(image, title, description) {
120
  document.getElementById('popup-image').src = image;
121
  document.getElementById('popup-title').textContent = title;
122
  document.getElementById('popup-description').textContent = description;
123
 
124
+ // Adjust the popup to always appear at the top of the viewport
125
  const popup = document.getElementById('popup');
126
  popup.style.top = window.pageYOffset + 'px';
127
  popup.style.display = 'block';
128
  }
 
129
  function closePopup() {
130
  document.getElementById('popup').style.display = 'none';
131
  }
132
  </script>
133
  """)
134
 
135
+ # Button click events
136
+ btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
137
+ btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
138
+ btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  demo.launch()