Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# Step 1: Define food items
|
| 4 |
+
food_items = [
|
| 5 |
+
{
|
| 6 |
+
"name": "Samosa",
|
| 7 |
+
"price": "$0.6",
|
| 8 |
+
"description": "Crispy fried pastry filled with spiced potatoes and peas. Serves 1. [Energy: 200 kcal, Protein: 5g, Carbohydrates: 25g, Fiber: 3g, Fat: 10g, Sugar: 1g]",
|
| 9 |
+
"image": "samosa.jpg"
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"name": "Onion Pakoda",
|
| 13 |
+
"price": "$0.75",
|
| 14 |
+
"description": "Deep-fried onion fritters seasoned with herbs and spices. Serves 2. [Energy: 250 kcal, Protein: 6g, Carbohydrates: 30g, Fiber: 4g, Fat: 12g, Sugar: 2g]",
|
| 15 |
+
"image": "pakoda.jpg"
|
| 16 |
+
}
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
# Step 2: Generate HTML for food items
|
| 20 |
+
def generate_food_menu():
|
| 21 |
+
html_content = "<div>"
|
| 22 |
+
for item in food_items:
|
| 23 |
+
html_content += f"""
|
| 24 |
+
<div class="menu-item">
|
| 25 |
+
<h3>{item['name']}</h3>
|
| 26 |
+
<p>{item['price']}</p>
|
| 27 |
+
<p>{item['description']}</p>
|
| 28 |
+
<img src="{item['image']}" alt="{item['name']}" class="menu-image" onclick="openPopup('{item['name']}', '{item['price']}', '{item['description']}', '{item['image']}')">
|
| 29 |
+
<button class="add-btn" onclick="openPopup('{item['name']}', '{item['price']}', '{item['description']}', '{item['image']}')">Add</button>
|
| 30 |
+
</div>
|
| 31 |
+
"""
|
| 32 |
+
html_content += "</div>"
|
| 33 |
+
return html_content
|
| 34 |
+
|
| 35 |
+
# Step 3: Add JavaScript for the pop-up
|
| 36 |
+
popup_js = """
|
| 37 |
+
<script>
|
| 38 |
+
function openPopup(name, price, description, image) {
|
| 39 |
+
document.getElementById('popup-name').innerText = name;
|
| 40 |
+
document.getElementById('popup-price').innerText = price;
|
| 41 |
+
document.getElementById('popup-description').innerText = description;
|
| 42 |
+
document.getElementById('popup-image').src = image;
|
| 43 |
+
document.getElementById('popup').style.display = 'block';
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
function closePopup() {
|
| 47 |
+
document.getElementById('popup').style.display = 'none';
|
| 48 |
+
}
|
| 49 |
+
</script>
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
# Step 4: Build the Gradio Interface
|
| 53 |
+
with gr.Blocks() as demo:
|
| 54 |
+
with gr.Row():
|
| 55 |
+
gr.HTML(generate_food_menu()) # Render food menu
|
| 56 |
+
gr.HTML("""
|
| 57 |
+
<div id="popup" class="popup" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0, 0, 0, 0.8); display:flex; justify-content:center; align-items:center;">
|
| 58 |
+
<div class="popup-content" style="background:#fff; padding:20px; border-radius:10px; width:50%; text-align:center;">
|
| 59 |
+
<img id="popup-image" src="" alt="Food Image" style="width:100%; border-radius:10px;">
|
| 60 |
+
<h2 id="popup-name"></h2>
|
| 61 |
+
<p id="popup-price"></p>
|
| 62 |
+
<p id="popup-description"></p>
|
| 63 |
+
<button onclick="closePopup()" style="margin-top:20px; padding:10px 20px; background:red; color:#fff; border:none; border-radius:5px; cursor:pointer;">Close</button>
|
| 64 |
+
</div>
|
| 65 |
+
</div>
|
| 66 |
+
""")
|
| 67 |
+
gr.HTML(popup_js) # Inject JavaScript
|
| 68 |
+
|
| 69 |
+
demo.launch()
|