Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,9 +77,18 @@ def display_dishes(category):
|
|
| 77 |
return html_content
|
| 78 |
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
with gr.Blocks() as demo:
|
| 82 |
-
gr.HTML("<h1 style='text-align: center;'>
|
| 83 |
|
| 84 |
with gr.Row():
|
| 85 |
btn_all = gr.Button("ALL")
|
|
@@ -87,77 +96,71 @@ with gr.Blocks() as demo:
|
|
| 87 |
btn_halal = gr.Button("HALAL")
|
| 88 |
|
| 89 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
|
|
|
| 90 |
|
| 91 |
btn_all.click(lambda: display_dishes("ALL"), outputs=dish_display)
|
| 92 |
btn_vegan.click(lambda: display_dishes("VEGAN"), outputs=dish_display)
|
| 93 |
btn_halal.click(lambda: display_dishes("HALAL"), outputs=dish_display)
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
<
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
<
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
<button onclick='placeOrder()' style='margin-top: 10px; padding: 10px; background-color: #007bff; color: white; border: none; border-radius: 5px; display: block; width: 100%;'>Place Order</button>
|
| 108 |
</div>
|
| 109 |
|
| 110 |
-
<
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
<h4 id='popup-title'></h4>
|
| 114 |
-
<p id='popup-description'></p>
|
| 115 |
-
<p id='popup-price'></p>
|
| 116 |
-
<button onclick='addItemToCartFromPopup()' style='padding: 5px 10px; background-color: #28a745; color: white; border: none; border-radius: 5px; width: 100%;'>Add to Cart</button>
|
| 117 |
</div>
|
| 118 |
|
| 119 |
-
<
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
demo.launch()
|
|
|
|
| 77 |
return html_content
|
| 78 |
|
| 79 |
|
| 80 |
+
Spice levels and extras options
|
| 81 |
+
spice_levels = ["Mild", "Medium", "Spicy", "Extra Spicy"]
|
| 82 |
+
extras = [
|
| 83 |
+
{"name": "Extra Cheese", "price": "$2.00"},
|
| 84 |
+
{"name": "Extra Sauce", "price": "$1.50"},
|
| 85 |
+
{"name": "No Onions", "price": "$0.00"},
|
| 86 |
+
{"name": "No Garlic", "price": "$0.00"}
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
# Main Gradio Application
|
| 90 |
with gr.Blocks() as demo:
|
| 91 |
+
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu 🍴</h1>")
|
| 92 |
|
| 93 |
with gr.Row():
|
| 94 |
btn_all = gr.Button("ALL")
|
|
|
|
| 96 |
btn_halal = gr.Button("HALAL")
|
| 97 |
|
| 98 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 99 |
+
cart_display = gr.HTML(value="<p>Your cart is empty.</p>")
|
| 100 |
|
| 101 |
btn_all.click(lambda: display_dishes("ALL"), outputs=dish_display)
|
| 102 |
btn_vegan.click(lambda: display_dishes("VEGAN"), outputs=dish_display)
|
| 103 |
btn_halal.click(lambda: display_dishes("HALAL"), outputs=dish_display)
|
| 104 |
|
| 105 |
+
demo.append(gr.HTML(f"""
|
| 106 |
+
<div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 107 |
+
background-color: white; padding: 20px; border-radius: 10px;
|
| 108 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
|
| 109 |
+
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 110 |
+
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 111 |
+
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 112 |
+
<p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
|
| 113 |
+
|
| 114 |
+
<h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
|
| 115 |
+
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 116 |
+
""" + "".join([f'<label style="margin-right: 10px; display: block;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>' for spice in spice_levels]) + """
|
|
|
|
| 117 |
</div>
|
| 118 |
|
| 119 |
+
<h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
|
| 120 |
+
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 121 |
+
""" + "".join([f'<label style="margin-right: 10px; display: block;"><input type="checkbox" name="extras" value="{extra["name"]}" style="margin-right: 5px;">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
</div>
|
| 123 |
|
| 124 |
+
<button onclick="addToCartFromPopup()"
|
| 125 |
+
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 126 |
+
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 127 |
+
<button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
|
| 128 |
+
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 129 |
+
</div>
|
| 130 |
+
<script>
|
| 131 |
+
let selectedItem = '';
|
| 132 |
+
let selectedPrice = 0;
|
| 133 |
+
|
| 134 |
+
function showPopup(image, title, description, price) {
|
| 135 |
+
document.getElementById('popup-image').src = image;
|
| 136 |
+
document.getElementById('popup-title').textContent = title;
|
| 137 |
+
document.getElementById('popup-description').textContent = description;
|
| 138 |
+
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 139 |
+
selectedItem = title;
|
| 140 |
+
selectedPrice = price;
|
| 141 |
+
|
| 142 |
+
// Display the popup
|
| 143 |
+
document.getElementById('popup').style.display = 'block';
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
function closePopup() {
|
| 147 |
+
document.getElementById('popup').style.display = 'none';
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
function addToCartFromPopup() {
|
| 151 |
+
const spiceLevel = document.querySelector('input[name=spice]:checked')?.value || "None";
|
| 152 |
+
const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
|
| 153 |
+
fetch('/run/predict', {
|
| 154 |
+
method: 'POST',
|
| 155 |
+
headers: { 'Content-Type': 'application/json' },
|
| 156 |
+
body: JSON.stringify({ data: [selectedItem, selectedPrice, spiceLevel, selectedExtras] })
|
| 157 |
+
}).then(response => response.json()).then(data => {
|
| 158 |
+
document.querySelector('.cart-html').innerHTML = data.data[0];
|
| 159 |
+
alert(selectedItem + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
|
| 160 |
+
closePopup();
|
| 161 |
+
});
|
| 162 |
+
}
|
| 163 |
+
</script>
|
| 164 |
+
"""))
|
| 165 |
+
|
| 166 |
+
demo.launch()
|
|
|
|
|
|