Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
-
from utils.database_handler import check_credentials, save_user
|
| 4 |
|
| 5 |
# Function to load the menu data
|
| 6 |
def load_menu():
|
|
@@ -58,7 +58,7 @@ def create_account(name, phone, email, password):
|
|
| 58 |
def navigate_to_login():
|
| 59 |
return gr.update(visible=True), gr.update(visible=False)
|
| 60 |
|
| 61 |
-
# Gradio app with popup modal
|
| 62 |
def app():
|
| 63 |
with gr.Blocks() as demo:
|
| 64 |
# Login Page
|
|
@@ -101,21 +101,12 @@ def app():
|
|
| 101 |
<h2 id="modal-name" style="margin: 0; font-size: 22px; color: #333;"></h2>
|
| 102 |
<p id="modal-description" style="margin: 10px 0; font-size: 16px; color: #666;"></p>
|
| 103 |
<p id="modal-price" style="font-size: 18px; color: #28a745; font-weight: bold;"></p>
|
| 104 |
-
<label for="extras" style="display: block; font-size: 16px; margin-top: 10px;">
|
| 105 |
-
<div style="margin-bottom: 15px;">
|
| 106 |
-
<label><input type="checkbox" name="extra" value="Thums up" data-price="2" /> Thums up + $2.00</label><br>
|
| 107 |
-
<label><input type="checkbox" name="extra" value="Sprite" data-price="2" /> Sprite + $2.00</label><br>
|
| 108 |
-
<label><input type="checkbox" name="extra" value="Extra Raitha" data-price="1" /> Extra Raitha + $1.00</label><br>
|
| 109 |
-
<label><input type="checkbox" name="extra" value="Extra Salan" data-price="2" /> Extra Salan + $2.00</label><br>
|
| 110 |
-
<label><input type="checkbox" name="extra" value="Chilli Chicken" data-price="14" /> Chilli Chicken + $14.00</label><br>
|
| 111 |
-
<label><input type="checkbox" name="extra" value="Veg Manchurian" data-price="12" /> Veg Manchurian + $12.00</label>
|
| 112 |
-
</div>
|
| 113 |
-
<label for="quantity" style="display: block; font-size: 16px; margin-top: 10px;">Quantity:</label>
|
| 114 |
-
<input type="number" id="quantity" value="1" min="1" style="width: 100%; padding: 5px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 5px;" />
|
| 115 |
<textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 80px; padding: 10px; border: 1px solid #ccc; border-radius: 5px; margin-bottom: 10px;"></textarea>
|
| 116 |
<button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 16px; border-radius: 5px; cursor: pointer; width: 100%;" onclick="addToCart()">Add to Cart</button>
|
| 117 |
</div>
|
| 118 |
""")
|
|
|
|
| 119 |
|
| 120 |
# Button Actions
|
| 121 |
login_btn.click(authenticate_user, inputs=[email, password], outputs=[login_section, preference_section, error_box])
|
|
@@ -123,6 +114,52 @@ def app():
|
|
| 123 |
submit_btn.click(create_account, inputs=[name, phone, signup_email, signup_password], outputs=[success_message, signup_section, login_section])
|
| 124 |
back_to_login_btn.click(navigate_to_login, inputs=[], outputs=[login_section, signup_section])
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
return demo
|
| 127 |
|
| 128 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
+
from utils.database_handler import check_credentials, save_user
|
| 4 |
|
| 5 |
# Function to load the menu data
|
| 6 |
def load_menu():
|
|
|
|
| 58 |
def navigate_to_login():
|
| 59 |
return gr.update(visible=True), gr.update(visible=False)
|
| 60 |
|
| 61 |
+
# Gradio app with popup modal and cart system
|
| 62 |
def app():
|
| 63 |
with gr.Blocks() as demo:
|
| 64 |
# Login Page
|
|
|
|
| 101 |
<h2 id="modal-name" style="margin: 0; font-size: 22px; color: #333;"></h2>
|
| 102 |
<p id="modal-description" style="margin: 10px 0; font-size: 16px; color: #666;"></p>
|
| 103 |
<p id="modal-price" style="font-size: 18px; color: #28a745; font-weight: bold;"></p>
|
| 104 |
+
<label for="extras" style="display: block; font-size: 16px; margin-top: 10px;">Extras:</label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
<textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 80px; padding: 10px; border: 1px solid #ccc; border-radius: 5px; margin-bottom: 10px;"></textarea>
|
| 106 |
<button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 16px; border-radius: 5px; cursor: pointer; width: 100%;" onclick="addToCart()">Add to Cart</button>
|
| 107 |
</div>
|
| 108 |
""")
|
| 109 |
+
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
| 110 |
|
| 111 |
# Button Actions
|
| 112 |
login_btn.click(authenticate_user, inputs=[email, password], outputs=[login_section, preference_section, error_box])
|
|
|
|
| 114 |
submit_btn.click(create_account, inputs=[name, phone, signup_email, signup_password], outputs=[success_message, signup_section, login_section])
|
| 115 |
back_to_login_btn.click(navigate_to_login, inputs=[], outputs=[login_section, signup_section])
|
| 116 |
|
| 117 |
+
# JavaScript for Popup and Cart Management
|
| 118 |
+
gr.HTML("""
|
| 119 |
+
<script>
|
| 120 |
+
let cart = [];
|
| 121 |
+
function openModal(name, image, description, price) {
|
| 122 |
+
const modal = document.getElementById('modal');
|
| 123 |
+
modal.style.display = 'block';
|
| 124 |
+
document.getElementById('modal-image').src = image;
|
| 125 |
+
document.getElementById('modal-name').innerText = name;
|
| 126 |
+
document.getElementById('modal-description').innerText = description;
|
| 127 |
+
document.getElementById('modal-price').innerText = `$${price}`;
|
| 128 |
+
}
|
| 129 |
+
function closeModal() {
|
| 130 |
+
document.getElementById('modal').style.display = 'none';
|
| 131 |
+
}
|
| 132 |
+
function addToCart() {
|
| 133 |
+
const name = document.getElementById('modal-name').innerText;
|
| 134 |
+
const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
| 135 |
+
const instructions = document.getElementById('special-instructions').value || "None";
|
| 136 |
+
cart.push({ name, price, instructions });
|
| 137 |
+
alert(`${name} added to cart!`);
|
| 138 |
+
closeModal();
|
| 139 |
+
updateCart();
|
| 140 |
+
}
|
| 141 |
+
function updateCart() {
|
| 142 |
+
let totalBill = 0;
|
| 143 |
+
let cartHTML = '<div style="border: 1px solid #ddd; padding: 10px; border-radius: 8px;">';
|
| 144 |
+
cart.forEach((item, index) => {
|
| 145 |
+
totalBill += item.price;
|
| 146 |
+
cartHTML += `<div style="display: flex; justify-content: space-between; padding: 5px 0;">
|
| 147 |
+
<span>${item.name}</span>
|
| 148 |
+
<span>$${item.price.toFixed(2)}</span>
|
| 149 |
+
<span>Instructions: ${item.instructions}</span>
|
| 150 |
+
<button onclick="removeFromCart(${index})">Remove</button>
|
| 151 |
+
</div>`;
|
| 152 |
+
});
|
| 153 |
+
cartHTML += `<div><strong>Total Bill: $${totalBill.toFixed(2)}</strong></div></div>`;
|
| 154 |
+
document.getElementById('floating-cart').innerHTML = cartHTML;
|
| 155 |
+
}
|
| 156 |
+
function removeFromCart(index) {
|
| 157 |
+
cart.splice(index, 1);
|
| 158 |
+
updateCart();
|
| 159 |
+
}
|
| 160 |
+
</script>
|
| 161 |
+
""")
|
| 162 |
+
|
| 163 |
return demo
|
| 164 |
|
| 165 |
if __name__ == "__main__":
|