Rammohan0504 commited on
Commit
1be82e7
·
verified ·
1 Parent(s): b45c843

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -50
app.py CHANGED
@@ -68,8 +68,7 @@ def filter_dishes(category):
68
  return menu_data
69
  return [dish for dish in menu_data if dish["category"] == category]
70
 
71
- # Function to generate dish cards
72
- # Function to generate dish cards with "Add" button
73
  def display_dishes(category):
74
  filtered_dishes = filter_dishes(category)
75
  html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%;'>"
@@ -92,55 +91,65 @@ def display_dishes(category):
92
  html_content += "</div>"
93
  return html_content
94
 
95
- # JavaScript for managing the pop-up and "Add" button
96
- gr.HTML("""
97
- <div id="popup" style="display: none; position: fixed; left: 50%; justify-content: center; align-items: center;
98
- transform: translate(-50%, 100%) background-color: white; padding: 20px; border-radius: 10px;
99
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 300px;">
100
- <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
101
- <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
102
- <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
103
- <button onclick="addToCart(document.getElementById('popup-title').textContent)"
104
- style="margin-top: 10px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
105
- border-radius: 5px; cursor: pointer;">Add to Cart</button>
106
- <button onclick="closePopup()" style="margin-top: 10px; padding: 10px 20px; background-color: #28a745;
107
- color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
108
- </div>
109
- <script>
110
- function showPopup(image, title, description) {
111
- document.getElementById('popup-image').src = image;
112
- document.getElementById('popup-title').textContent = title;
113
- document.getElementById('popup-description').textContent = description;
114
 
115
- // Adjust the popup to always appear at the top of the viewport
116
- const popup = document.getElementById('popup');
117
- popup.style.top = window.pageYOffset + 'px';
118
- popup.style.display = 'block';
119
- }
120
- function closePopup() {
121
- document.getElementById('popup').style.display = 'none';
122
- }
123
- function addToCart(dishName) {
124
- alert(dishName + " has been added to the cart!");
125
- }
126
- </script>
127
- """)
128
 
129
- dish_display = gr.HTML(value=display_dishes("ALL"))
 
130
 
131
- # Button click events
132
- btn_all.click(
133
- lambda: gr.update(value=display_dishes("ALL")),
134
- outputs=dish_display
135
- )
136
- btn_vegan.click(
137
- lambda: gr.update(value=display_dishes("VEGAN")),
138
- outputs=dish_display
139
- )
140
- btn_halal.click(
141
- lambda: gr.update(value=display_dishes("HALAL")),
142
- outputs=dish_display
143
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
-
146
- demo.launch()
 
68
  return menu_data
69
  return [dish for dish in menu_data if dish["category"] == category]
70
 
71
+ # Generate dish cards with "Add" button
 
72
  def display_dishes(category):
73
  filtered_dishes = filter_dishes(category)
74
  html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%;'>"
 
91
  html_content += "</div>"
92
  return html_content
93
 
94
+ # Main Gradio App
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 and "Add" button
108
+ gr.HTML("""
109
+ <div id="popup" style="display: none; position: fixed; left: 50%; justify-content: center; align-items: center;
110
+ transform: translate(-50%, 100%) background-color: white; padding: 20px; border-radius: 10px;
111
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); 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="addToCart(document.getElementById('popup-title').textContent)"
116
+ style="margin-top: 10px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
117
+ border-radius: 5px; cursor: pointer;">Add to Cart</button>
118
+ <button onclick="closePopup()" style="margin-top: 10px; padding: 10px 20px; background-color: #28a745;
119
+ color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
120
+ </div>
121
+ <script>
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 at the top of the viewport
128
+ const popup = document.getElementById('popup');
129
+ popup.style.top = window.pageYOffset + 'px';
130
+ popup.style.display = 'block';
131
+ }
132
+ function closePopup() {
133
+ document.getElementById('popup').style.display = 'none';
134
+ }
135
+ function addToCart(dishName) {
136
+ alert(dishName + " has been added to the cart!");
137
+ }
138
+ </script>
139
+ """)
140
+
141
+ # Button click events
142
+ btn_all.click(
143
+ lambda: gr.update(value=display_dishes("ALL")),
144
+ outputs=dish_display
145
+ )
146
+ btn_vegan.click(
147
+ lambda: gr.update(value=display_dishes("VEGAN")),
148
+ outputs=dish_display
149
+ )
150
+ btn_halal.click(
151
+ lambda: gr.update(value=display_dishes("HALAL")),
152
+ outputs=dish_display
153
+ )
154
 
155
+ demo.launch()