Spaces:
Sleeping
Sleeping
Update app.py
Browse files45 unmodified lines4647484950515253541 unmodified line565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612726 unmodified lines15415515615745 unmodified lines<h3 style='margin: 10px 0; font-size: 18px;'>{dish['name']}</h3><p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p><p style='margin: 10px 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p><button style='padding: 10px 20px; background-color: #28a745; color: white; border: none;border-radius: 5px; cursor: pointer;'onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')">Add to Cart</button></div>1 unmodified linehtml_content += "</div>"return html_content# JavaScript for handling the popuppopup_js = """<script>async function showPopup(name, description, price, image) {const popup = document.getElementById("custom-popup");const overlay = document.getElementById("overlay");popup.innerHTML = `<button onclick="closePopup()" style="position: absolute; top: 10px; right: 10px; background: none; border: none; font-size: 20px; cursor: pointer;">×</button><img src="${image}" alt="${name}" style="width: 100%; height: 200px; object-fit: cover; border-radius: 10px; margin-bottom: 10px;"><h3>${name}</h3><p>${description}</p><p style="font-weight: bold;">Price: ${price}</p><button id="add-to-cart-button" style="padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button>`;popup.style.display = "block";overlay.style.display = "block";document.getElementById("add-to-cart-button").onclick = async function () {try {const response = await fetch("/add_to_cart", {method: "POST",headers: { "Content-Type": "application/json" },body: JSON.stringify({ item_name: name })});const result = await response.json();if (result.status === "success") {alert(result.message); // Show success message} else {alert("Error adding item to cart: " + result.message);}} catch (error) {console.error("Error:", error);alert("Something went wrong while adding the item.");}closePopup();};}function closePopup() {document.getElementById("custom-popup").style.display = "none";document.getElementById("overlay").style.display = "none";}</script>"""# HTML structure for the popuppopup_html = """<div id="overlay" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: none; z-index: 999;"></div><div id="custom-popup"style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 400px; max-width: 90%; background: white; padding: 20px; border-radius: 10px; box-shadow: 0px 4px 6px rgba(0,0,0,0.1); display: none; z-index: 1000; position: relative;"></div>"""# Main Gradio appwith gr.Blocks() as demo:gr.HTML(popup_html) # Add popup containergr.HTML(popup_js) # Add popup JavaScriptgr.HTML("<h1 style='text-align: center;'>π Welcome to the Biryani Hub π</h1>")with gr.Tabs():# Menu Tabwith gr.Tab("Menu"):26 unmodified linesoutputs=cart_display)demo.launch()45 unmodified lines464748495051521 unmodified line5455565758596061626364656667686970717273747576777879808182838485868788899026 unmodified lines11711811912012145 unmodified lines<h3 style='margin: 10px 0; font-size: 18px;'>{dish['name']}</h3><p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p><p style='margin: 10px 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p><button onclick="addItemToCart('{dish['name']}')" style='padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;'>Add to Cart</button></div>1 unmodified linehtml_content += "</div>"return html_content# JavaScript for Popup Handlingpopup_js = """<script>async function addItemToCart(itemName) {try {const response = await fetch("/add_to_cart", {method: "POST",headers: { "Content-Type": "application/json" },body: JSON.stringify({ item_name: itemName })});const result = await response.json();if (result.status === "success") {alert(result.message); // Show success message} else {alert("Error: " + result.message); // Show error message}} catch (error) {console.error("Error:", error);alert("Something went wrong!");}}</script>"""# Main Gradio appwith gr.Blocks() as demo:gr.HTML("<h1 style='text-align: center;'>π Welcome to the Biryani Hub π</h1>")gr.HTML(popup_js) # Add JavaScript for handling interactions# Tabs for Menu and Cartwith gr.Tabs():# Menu Tabwith gr.Tab("Menu"):26 unmodified linesoutputs=cart_display)# Launch Gradio appdemo.launch()
app.py+22-58