Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,11 +2,11 @@ import gradio as gr
|
|
2 |
from food_data import FOOD_ITEMS
|
3 |
|
4 |
def get_food_details(name, image, nutrition_details):
|
5 |
-
"""Generate clean HTML content with image and structured nutrition values."""
|
6 |
-
#
|
7 |
nutrition_list = nutrition_details.split(", ")
|
8 |
formatted_nutrition = "<br>".join(nutrition_list)
|
9 |
-
|
10 |
return f"""
|
11 |
<div style="text-align: center; padding: 15px; border: 2px solid #ddd;
|
12 |
border-radius: 10px; box-shadow: 0px 4px 8px rgba(0,0,0,0.2);
|
@@ -16,7 +16,7 @@ def get_food_details(name, image, nutrition_details):
|
|
16 |
<h2 style="color: #FF6347; margin: 10px 0; font-size: 1.8em;">{name}</h2>
|
17 |
<div style="text-align: left; margin-top: 10px;">
|
18 |
<h3 style="color: #555; text-align: center;">Nutrition</h3>
|
19 |
-
<p style="font-size: 1em; color: #333; line-height: 1.6;">
|
20 |
{formatted_nutrition}
|
21 |
</p>
|
22 |
</div>
|
@@ -29,21 +29,21 @@ with gr.Blocks() as demo:
|
|
29 |
|
30 |
for category, items in FOOD_ITEMS.items():
|
31 |
gr.Markdown(f"<h2 style='text-align:center; color:#FF6347;'>{category} Menu</h2>")
|
32 |
-
|
33 |
-
# Generate buttons for each item
|
34 |
with gr.Row():
|
35 |
for item in items:
|
36 |
with gr.Column():
|
|
|
37 |
btn = gr.Button(item["name"], elem_id=f"menu-item-{item['name'].lower()}")
|
38 |
-
output_html = gr.HTML() #
|
39 |
-
|
40 |
-
#
|
41 |
btn.click(
|
42 |
fn=get_food_details,
|
43 |
-
inputs=[
|
44 |
-
outputs=output_html
|
|
|
45 |
)
|
46 |
-
|
47 |
gr.Markdown("<p style='text-align:center; margin-top:20px; color: gray;'>© 2024 Delicious Restaurant | Designed with ❤️</p>")
|
48 |
|
49 |
demo.launch()
|
|
|
2 |
from food_data import FOOD_ITEMS
|
3 |
|
4 |
def get_food_details(name, image, nutrition_details):
|
5 |
+
"""Generate clean HTML content with the image and structured nutrition values."""
|
6 |
+
# Split the nutrition details into separate lines
|
7 |
nutrition_list = nutrition_details.split(", ")
|
8 |
formatted_nutrition = "<br>".join(nutrition_list)
|
9 |
+
|
10 |
return f"""
|
11 |
<div style="text-align: center; padding: 15px; border: 2px solid #ddd;
|
12 |
border-radius: 10px; box-shadow: 0px 4px 8px rgba(0,0,0,0.2);
|
|
|
16 |
<h2 style="color: #FF6347; margin: 10px 0; font-size: 1.8em;">{name}</h2>
|
17 |
<div style="text-align: left; margin-top: 10px;">
|
18 |
<h3 style="color: #555; text-align: center;">Nutrition</h3>
|
19 |
+
<p style="font-size: 1em; color: #333; line-height: 1.6; margin-left: 20px;">
|
20 |
{formatted_nutrition}
|
21 |
</p>
|
22 |
</div>
|
|
|
29 |
|
30 |
for category, items in FOOD_ITEMS.items():
|
31 |
gr.Markdown(f"<h2 style='text-align:center; color:#FF6347;'>{category} Menu</h2>")
|
|
|
|
|
32 |
with gr.Row():
|
33 |
for item in items:
|
34 |
with gr.Column():
|
35 |
+
# Button for each food item
|
36 |
btn = gr.Button(item["name"], elem_id=f"menu-item-{item['name'].lower()}")
|
37 |
+
output_html = gr.HTML() # Output will be formatted HTML
|
38 |
+
|
39 |
+
# Display only formatted HTML content
|
40 |
btn.click(
|
41 |
fn=get_food_details,
|
42 |
+
inputs=[], # No textboxes used here
|
43 |
+
outputs=output_html,
|
44 |
+
_js=f'() => {{"name": "{item["name"]}", "image": "{item["image"]}", "nutrition_details": "{item["nutrition"]}"}}'
|
45 |
)
|
46 |
+
|
47 |
gr.Markdown("<p style='text-align:center; margin-top:20px; color: gray;'>© 2024 Delicious Restaurant | Designed with ❤️</p>")
|
48 |
|
49 |
demo.launch()
|