nagasurendra commited on
Commit
93a5360
·
verified ·
1 Parent(s): cc5a2e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -24
app.py CHANGED
@@ -66,7 +66,7 @@ def login(email, password):
66
  # Function to load menu data
67
  def load_menu_from_salesforce():
68
  try:
69
- query = "SELECT Name, Price__c, Description__c, Image1__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c"
70
  result = sf.query(query)
71
  return result['records']
72
  except Exception as e:
@@ -94,7 +94,8 @@ def filter_menu(preference):
94
  for item in items:
95
  html_content += f"""
96
  <div style="border: 1px solid #ddd; border-radius: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); overflow: hidden; height: 350px;">
97
- <img src="{item.get('Image1__c', '')}" style="width: 100%; height: 200px; object-fit: cover;">
 
98
  <div style="padding: 10px;">
99
  <h3 style='font-size: 1.2em; text-align: center;'>{item['Name']}</h3>
100
  <p style='font-size: 1.1em; color: green; text-align: center;'>${item['Price__c']}</p>
@@ -110,6 +111,82 @@ def filter_menu(preference):
110
 
111
  return html_content
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  # Gradio App
114
  with gr.Blocks() as app:
115
  with gr.Row():
@@ -137,30 +214,14 @@ with gr.Blocks() as app:
137
  with gr.Column():
138
  preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
139
  menu_output = gr.HTML()
140
-
141
- with gr.Row(visible=False) as footer:
142
- gr.HTML("<footer style='text-align: center;'>Thank you! Welcome again!</footer>")
143
-
144
- def handle_login(email, password):
145
- status, user = login(email, password)
146
- if status == "Login successful!":
147
- content = filter_menu("All") # Default to "All" on login
148
- return gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(value=content), status
149
- else:
150
- return gr.update(), gr.update(), gr.update(), gr.update(), status
151
-
152
- def handle_signup(name, email, phone, password):
153
- return signup(name, email, phone, password)
154
-
155
- def handle_menu(preference):
156
- content = filter_menu(preference)
157
- return content
158
 
159
  login_button.click(
160
- handle_login, [login_email, login_password], [login_page, menu_page, footer, menu_output, login_output]
 
 
161
  )
162
- signup_button.click(lambda: (gr.update(visible=False), gr.update(visible=True)), None, [login_page, signup_page])
163
- submit_signup.click(handle_signup, [signup_name, signup_email, signup_phone, signup_password], signup_output)
164
- preference.change(handle_menu, [preference], menu_output)
165
 
166
  app.launch()
 
66
  # Function to load menu data
67
  def load_menu_from_salesforce():
68
  try:
69
+ query = "SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c"
70
  result = sf.query(query)
71
  return result['records']
72
  except Exception as e:
 
94
  for item in items:
95
  html_content += f"""
96
  <div style="border: 1px solid #ddd; border-radius: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); overflow: hidden; height: 350px;">
97
+ <img src="{item.get('Image1__c', '')}" style="width: 100%; height: 200px; object-fit: cover;"
98
+ onclick="openModal('{item['Name']}', '{item.get('Image2__c', '')}', '{item['Description__c']}', '${item['Price__c']}')">
99
  <div style="padding: 10px;">
100
  <h3 style='font-size: 1.2em; text-align: center;'>{item['Name']}</h3>
101
  <p style='font-size: 1.1em; color: green; text-align: center;'>${item['Price__c']}</p>
 
111
 
112
  return html_content
113
 
114
+ # Create Modal Window HTML
115
+ def create_modal_window():
116
+ modal_html = """
117
+ <div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
118
+ <div style="text-align: right;">
119
+ <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
120
+ </div>
121
+ <img id="modal-image" style="width: 100%; height: 300px; border-radius: 8px; margin-bottom: 20px;" />
122
+ <h2 id="modal-name"></h2>
123
+ <p id="modal-description"></p>
124
+ <p id="modal-price"></p>
125
+ <!-- Add-ons Section -->
126
+ <label for="biryani-extras"><strong>Add-ons :</strong></label>
127
+ <div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
128
+ <label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label>
129
+ <label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label>
130
+ <label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label>
131
+ <label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label>
132
+ </div>
133
+ <!-- Quantity and Special Instructions -->
134
+ <label for="quantity">Quantity:</label>
135
+ <input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
136
+ <br><br>
137
+ <textarea id="special-instructions" placeholder="Add your special instructions here..." style="width: 100%; height: 60px;"></textarea>
138
+ <br><br>
139
+ <!-- Add to Cart Button -->
140
+ <button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
141
+ </div>
142
+ """
143
+ return modal_html
144
+
145
+ # JavaScript for Modal Functionality
146
+ def modal_js():
147
+ modal_script = """
148
+ <script>
149
+ function openModal(name, image2, description, price) {
150
+ const modal = document.getElementById('modal');
151
+ modal.style.display = 'block';
152
+ modal.style.position = 'fixed';
153
+ if (window.innerWidth <= 768) {
154
+ modal.style.width = '90%';
155
+ modal.style.top = `${event.touches ? event.touches[0].screenY : event.clientY}px`;
156
+ } else {
157
+ modal.style.width = '30%';
158
+ modal.style.top = `${event.clientY}px`;
159
+ }
160
+ modal.style.left = '50%';
161
+ modal.style.transform = 'translate(-50%, -50%)';
162
+ document.getElementById('modal-image').src = image2;
163
+ document.getElementById('modal-name').innerText = name;
164
+ document.getElementById('modal-description').innerText = description;
165
+ document.getElementById('modal-price').innerText = price;
166
+ document.getElementById('quantity').value = 1;
167
+ document.getElementById('special-instructions').value = '';
168
+ }
169
+
170
+ function closeModal() {
171
+ document.getElementById('modal').style.display = 'none';
172
+ }
173
+
174
+ function addToCart() {
175
+ const name = document.getElementById('modal-name').innerText;
176
+ const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
177
+ const quantity = parseInt(document.getElementById('quantity').value) || 1;
178
+ const instructions = document.getElementById('special-instructions').value;
179
+ const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra => extra.value);
180
+ const extrasCost = extras.length * 2; // Assuming $2 per extra
181
+ const totalCost = (price + extrasCost) * quantity;
182
+
183
+ alert(`${quantity} x ${name} added to cart! Total: $${totalCost.toFixed(2)}`);
184
+ closeModal();
185
+ }
186
+ </script>
187
+ """
188
+ return modal_script
189
+
190
  # Gradio App
191
  with gr.Blocks() as app:
192
  with gr.Row():
 
214
  with gr.Column():
215
  preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
216
  menu_output = gr.HTML()
217
+ gr.HTML(create_modal_window()) # Add modal window HTML
218
+ gr.HTML(modal_js()) # Add modal JavaScript
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
220
  login_button.click(
221
+ lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value=filter_menu("All")), "Login successful!")
222
+ if login(email, password)[0] == "Login successful!" else (gr.update(), gr.update(), gr.update(), "Invalid email or password."),
223
+ [login_email, login_password], [login_page, menu_page, menu_output, login_output]
224
  )
225
+ preference.change(lambda pref: filter_menu(pref), [preference], menu_output)
 
 
226
 
227
  app.launch()