Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
import gradio as gr
|
2 |
import bcrypt
|
|
|
3 |
from simple_salesforce import Salesforce
|
4 |
|
5 |
# Salesforce Connection
|
@@ -152,7 +152,6 @@ def modal_js():
|
|
152 |
<script>
|
153 |
let cart = [];
|
154 |
let totalCartCost = 0;
|
155 |
-
|
156 |
function openModal(name, image2, description, price) {
|
157 |
const modal = document.getElementById('modal');
|
158 |
modal.style.display = 'block';
|
@@ -169,11 +168,9 @@ def modal_js():
|
|
169 |
document.getElementById('special-instructions').value = '';
|
170 |
resetAddOns(); // Reset add-ons when opening the modal
|
171 |
}
|
172 |
-
|
173 |
function closeModal() {
|
174 |
document.getElementById('modal').style.display = 'none';
|
175 |
}
|
176 |
-
|
177 |
function addToCart() {
|
178 |
const name = document.getElementById('modal-name').innerText;
|
179 |
const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
@@ -187,7 +184,6 @@ def modal_js():
|
|
187 |
}));
|
188 |
const extrasCost = extras.reduce((total, extra) => total + (extra.price * extra.quantity), 0);
|
189 |
const totalCost = (price * quantity) + extrasCost;
|
190 |
-
|
191 |
// Add the item to the cart with its specific add-ons
|
192 |
cart.push({ name, price, quantity, extras, instructions, totalCost });
|
193 |
totalCartCost += totalCost; // Update the total cost of the cart
|
@@ -195,12 +191,10 @@ def modal_js():
|
|
195 |
updateCartTotalCost(); // Update total cost displayed
|
196 |
closeModal();
|
197 |
}
|
198 |
-
|
199 |
function updateCartButton() {
|
200 |
const cartButton = document.getElementById('cart-button');
|
201 |
cartButton.innerText = `View Cart (${cart.length} items)`;
|
202 |
}
|
203 |
-
|
204 |
function openCartModal() {
|
205 |
const cartModal = document.getElementById('cart-modal');
|
206 |
const cartItemsContainer = document.getElementById('cart-items');
|
@@ -220,11 +214,9 @@ def modal_js():
|
|
220 |
});
|
221 |
cartModal.style.display = 'block';
|
222 |
}
|
223 |
-
|
224 |
function closeCartModal() {
|
225 |
document.getElementById('cart-modal').style.display = 'none';
|
226 |
}
|
227 |
-
|
228 |
function removeFromCart(index) {
|
229 |
totalCartCost -= cart[index].totalCost; // Deduct the cost of the removed item from total cost
|
230 |
cart.splice(index, 1);
|
@@ -232,7 +224,6 @@ def modal_js():
|
|
232 |
updateCartTotalCost(); // Update total cost displayed
|
233 |
openCartModal();
|
234 |
}
|
235 |
-
|
236 |
function updateCartItem(index, type, value) {
|
237 |
if (type === 'item') {
|
238 |
cart[index].quantity = parseInt(value);
|
@@ -246,50 +237,41 @@ def modal_js():
|
|
246 |
document.getElementById(`item-${index}-total`).innerText = item.totalCost.toFixed(2);
|
247 |
updateCartTotalCost(); // Update total cost displayed
|
248 |
}
|
249 |
-
|
250 |
function updateCartTotalCost() {
|
251 |
const totalCostElement = document.getElementById('cart-total-cost');
|
252 |
totalCartCost = cart.reduce((total, item) => total + item.totalCost, 0);
|
253 |
totalCostElement.innerText = `Total Cart Cost: $${totalCartCost.toFixed(2)}`;
|
254 |
}
|
255 |
-
|
256 |
function proceedToCheckout() {
|
257 |
-
//
|
258 |
-
|
259 |
-
const cartPage = document.getElementById('cart-section');
|
260 |
-
cartPage.style.display = 'none';
|
261 |
-
finalOrderPage.style.display = 'block';
|
262 |
-
|
263 |
-
// Show the cart details on the final order page
|
264 |
-
const finalOrderItems = document.getElementById('final-order-items');
|
265 |
-
const finalOrderTotal = document.getElementById('final-order-total');
|
266 |
-
let itemsHtml = '';
|
267 |
-
let totalBill = 0;
|
268 |
cart.forEach(item => {
|
269 |
-
|
270 |
-
|
|
|
|
|
|
|
|
|
|
|
271 |
});
|
272 |
-
|
273 |
-
|
|
|
|
|
274 |
}
|
275 |
-
|
276 |
function goBackToMenu() {
|
277 |
-
|
278 |
-
|
279 |
-
finalOrderPage.style.display = 'none';
|
280 |
-
cartPage.style.display = 'block';
|
281 |
}
|
282 |
</script>
|
283 |
"""
|
284 |
return modal_script
|
285 |
|
286 |
-
|
287 |
# Gradio App
|
288 |
with gr.Blocks() as app:
|
289 |
with gr.Row():
|
290 |
gr.HTML("<h1 style='text-align: center;'>Welcome to Biryani Hub</h1>")
|
291 |
|
292 |
-
# Login Page
|
293 |
with gr.Row(visible=True) as login_page:
|
294 |
with gr.Column():
|
295 |
login_email = gr.Textbox(label="Email")
|
@@ -298,7 +280,6 @@ with gr.Blocks() as app:
|
|
298 |
signup_button = gr.Button("Go to Signup")
|
299 |
login_output = gr.Textbox(label="Status")
|
300 |
|
301 |
-
# Signup Page
|
302 |
with gr.Row(visible=False) as signup_page:
|
303 |
with gr.Column():
|
304 |
signup_name = gr.Textbox(label="Name")
|
@@ -309,31 +290,22 @@ with gr.Blocks() as app:
|
|
309 |
login_redirect = gr.Button("Go to Login")
|
310 |
signup_output = gr.Textbox(label="Status")
|
311 |
|
312 |
-
# Menu Page
|
313 |
with gr.Row(visible=False) as menu_page:
|
314 |
with gr.Column():
|
315 |
preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
|
316 |
menu_output = gr.HTML()
|
317 |
gr.HTML("<div id='cart-button' style='position: fixed; top: 20px; right: 20px; background: #28a745; color: white; padding: 10px 20px; border-radius: 30px; cursor: pointer; z-index: 1000;' onclick='openCartModal()'>View Cart</div>")
|
318 |
-
gr.HTML("<div id='cart-modal' style='display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 1000; overflow-y: auto;'><div style='padding: 20px;'><div style='text-align: right;'><button onclick='closeCartModal()' style='background: none; border: none; font-size: 24px; cursor: pointer;'>×</button></div><h1>Your Cart</h1><div id='cart-items'></div><p id='cart-total-cost' style='font-size: 1.2em; font-weight: bold;'>Total Cart Cost: $0.00</p><button style='background: #ff5722; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;' onclick='proceedToCheckout()'
|
319 |
gr.HTML(create_modal_window())
|
320 |
gr.HTML(modal_js())
|
321 |
|
322 |
-
|
323 |
-
with gr.Row(visible=False) as final_order_page:
|
324 |
with gr.Column():
|
325 |
-
gr.HTML("<
|
326 |
-
final_order_items = gr.HTML()
|
327 |
-
final_order_total = gr.HTML()
|
328 |
-
back_to_menu_button = gr.Button("Go Back to Menu")
|
329 |
-
back_to_menu_button.click(goBackToMenu, inputs=[], outputs=[final_order_page, menu_page])
|
330 |
|
331 |
login_button.click(
|
332 |
lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value=filter_menu("All")), "Login successful!")
|
333 |
if login(email, password)[0] == "Login successful!" else (gr.update(), gr.update(), gr.update(), "Invalid email or password."),
|
334 |
[login_email, login_password], [login_page, menu_page, menu_output, login_output]
|
335 |
)
|
336 |
-
|
337 |
-
preference.change(lambda pref: filter_menu(pref), [preference], menu_output)
|
338 |
-
|
339 |
-
app.launch()
|
|
|
|
|
1 |
import bcrypt
|
2 |
+
import gradio as gr
|
3 |
from simple_salesforce import Salesforce
|
4 |
|
5 |
# Salesforce Connection
|
|
|
152 |
<script>
|
153 |
let cart = [];
|
154 |
let totalCartCost = 0;
|
|
|
155 |
function openModal(name, image2, description, price) {
|
156 |
const modal = document.getElementById('modal');
|
157 |
modal.style.display = 'block';
|
|
|
168 |
document.getElementById('special-instructions').value = '';
|
169 |
resetAddOns(); // Reset add-ons when opening the modal
|
170 |
}
|
|
|
171 |
function closeModal() {
|
172 |
document.getElementById('modal').style.display = 'none';
|
173 |
}
|
|
|
174 |
function addToCart() {
|
175 |
const name = document.getElementById('modal-name').innerText;
|
176 |
const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
|
|
184 |
}));
|
185 |
const extrasCost = extras.reduce((total, extra) => total + (extra.price * extra.quantity), 0);
|
186 |
const totalCost = (price * quantity) + extrasCost;
|
|
|
187 |
// Add the item to the cart with its specific add-ons
|
188 |
cart.push({ name, price, quantity, extras, instructions, totalCost });
|
189 |
totalCartCost += totalCost; // Update the total cost of the cart
|
|
|
191 |
updateCartTotalCost(); // Update total cost displayed
|
192 |
closeModal();
|
193 |
}
|
|
|
194 |
function updateCartButton() {
|
195 |
const cartButton = document.getElementById('cart-button');
|
196 |
cartButton.innerText = `View Cart (${cart.length} items)`;
|
197 |
}
|
|
|
198 |
function openCartModal() {
|
199 |
const cartModal = document.getElementById('cart-modal');
|
200 |
const cartItemsContainer = document.getElementById('cart-items');
|
|
|
214 |
});
|
215 |
cartModal.style.display = 'block';
|
216 |
}
|
|
|
217 |
function closeCartModal() {
|
218 |
document.getElementById('cart-modal').style.display = 'none';
|
219 |
}
|
|
|
220 |
function removeFromCart(index) {
|
221 |
totalCartCost -= cart[index].totalCost; // Deduct the cost of the removed item from total cost
|
222 |
cart.splice(index, 1);
|
|
|
224 |
updateCartTotalCost(); // Update total cost displayed
|
225 |
openCartModal();
|
226 |
}
|
|
|
227 |
function updateCartItem(index, type, value) {
|
228 |
if (type === 'item') {
|
229 |
cart[index].quantity = parseInt(value);
|
|
|
237 |
document.getElementById(`item-${index}-total`).innerText = item.totalCost.toFixed(2);
|
238 |
updateCartTotalCost(); // Update total cost displayed
|
239 |
}
|
|
|
240 |
function updateCartTotalCost() {
|
241 |
const totalCostElement = document.getElementById('cart-total-cost');
|
242 |
totalCartCost = cart.reduce((total, item) => total + item.totalCost, 0);
|
243 |
totalCostElement.innerText = `Total Cart Cost: $${totalCartCost.toFixed(2)}`;
|
244 |
}
|
|
|
245 |
function proceedToCheckout() {
|
246 |
+
// Display checkout summary
|
247 |
+
let checkoutSummary = "<h1>Checkout Summary</h1>";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
cart.forEach(item => {
|
249 |
+
checkoutSummary += `
|
250 |
+
<h3>${item.name}</h3>
|
251 |
+
<p>Quantity: ${item.quantity}</p>
|
252 |
+
<p>Extras: ${item.extras.map(extra => `${extra.name} x${extra.quantity}`).join(', ')}</p>
|
253 |
+
<p>Special Instructions: ${item.instructions}</p>
|
254 |
+
<p>Total: $${item.totalCost.toFixed(2)}</p>
|
255 |
+
`;
|
256 |
});
|
257 |
+
checkoutSummary += `<p><strong>Total Cart Cost: $${totalCartCost.toFixed(2)}</strong></p>`;
|
258 |
+
document.getElementById('checkout-summary').innerHTML = checkoutSummary;
|
259 |
+
document.getElementById('cart-modal').style.display = 'none';
|
260 |
+
document.getElementById('checkout-page').style.display = 'block';
|
261 |
}
|
|
|
262 |
function goBackToMenu() {
|
263 |
+
document.getElementById('menu-page').style.display = 'block';
|
264 |
+
document.getElementById('cart-modal').style.display = 'none';
|
|
|
|
|
265 |
}
|
266 |
</script>
|
267 |
"""
|
268 |
return modal_script
|
269 |
|
|
|
270 |
# Gradio App
|
271 |
with gr.Blocks() as app:
|
272 |
with gr.Row():
|
273 |
gr.HTML("<h1 style='text-align: center;'>Welcome to Biryani Hub</h1>")
|
274 |
|
|
|
275 |
with gr.Row(visible=True) as login_page:
|
276 |
with gr.Column():
|
277 |
login_email = gr.Textbox(label="Email")
|
|
|
280 |
signup_button = gr.Button("Go to Signup")
|
281 |
login_output = gr.Textbox(label="Status")
|
282 |
|
|
|
283 |
with gr.Row(visible=False) as signup_page:
|
284 |
with gr.Column():
|
285 |
signup_name = gr.Textbox(label="Name")
|
|
|
290 |
login_redirect = gr.Button("Go to Login")
|
291 |
signup_output = gr.Textbox(label="Status")
|
292 |
|
|
|
293 |
with gr.Row(visible=False) as menu_page:
|
294 |
with gr.Column():
|
295 |
preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
|
296 |
menu_output = gr.HTML()
|
297 |
gr.HTML("<div id='cart-button' style='position: fixed; top: 20px; right: 20px; background: #28a745; color: white; padding: 10px 20px; border-radius: 30px; cursor: pointer; z-index: 1000;' onclick='openCartModal()'>View Cart</div>")
|
298 |
+
gr.HTML("<div id='cart-modal' style='display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 1000; overflow-y: auto;'><div style='padding: 20px;'><div style='text-align: right;'><button onclick='closeCartModal()' style='background: none; border: none; font-size: 24px; cursor: pointer;'>×</button></div><h1>Your Cart</h1><div id='cart-items'></div><p id='cart-total-cost' style='font-size: 1.2em; font-weight: bold;'>Total Cart Cost: $0.00</p><button onclick='goBackToMenu()' style='background: #ff5722; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;'>Back</button><button onclick='proceedToCheckout()' style='background: #28a745; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;'>Submit</button></div></div>")
|
299 |
gr.HTML(create_modal_window())
|
300 |
gr.HTML(modal_js())
|
301 |
|
302 |
+
with gr.Row(visible=False) as checkout_page:
|
|
|
303 |
with gr.Column():
|
304 |
+
gr.HTML("<div id='checkout-summary'></div>")
|
|
|
|
|
|
|
|
|
305 |
|
306 |
login_button.click(
|
307 |
lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value=filter_menu("All")), "Login successful!")
|
308 |
if login(email, password)[0] == "Login successful!" else (gr.update(), gr.update(), gr.update(), "Invalid email or password."),
|
309 |
[login_email, login_password], [login_page, menu_page, menu_output, login_output]
|
310 |
)
|
311 |
+
preference.change(lambda pref: filter_menu
|
|
|
|
|
|