Spaces:
Build error
Build error
Create components/cards.py
Browse files- components/cards.py +27 -0
components/cards.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from components.data import FOOD_DATA
|
| 2 |
+
|
| 3 |
+
def create_food_card(food_name):
|
| 4 |
+
food_info = FOOD_DATA[food_name]
|
| 5 |
+
image_src = f"assets/images/{food_info['image']}"
|
| 6 |
+
nutrition = food_info["nutrition"]
|
| 7 |
+
portion_size = food_info["portion_size"]
|
| 8 |
+
|
| 9 |
+
# HTML for card
|
| 10 |
+
card_html = f"""
|
| 11 |
+
<div class="food-card">
|
| 12 |
+
<div class="card-header">
|
| 13 |
+
<img src="{image_src}" alt="{food_name}" class="food-image" />
|
| 14 |
+
<button class="close-btn" onclick="document.querySelector('.food-card').style.display='none'">✖</button>
|
| 15 |
+
</div>
|
| 16 |
+
<div class="card-body">
|
| 17 |
+
<h3>{food_name}</h3>
|
| 18 |
+
<table class="nutrition-table">
|
| 19 |
+
{"".join([f"<tr><td>{key}</td><td>{value}</td></tr>" for key, value in nutrition.items()])}
|
| 20 |
+
</table>
|
| 21 |
+
</div>
|
| 22 |
+
<div class="card-footer">
|
| 23 |
+
<p><strong>Portion Size:</strong> {portion_size}</p>
|
| 24 |
+
</div>
|
| 25 |
+
</div>
|
| 26 |
+
"""
|
| 27 |
+
return card_html
|