File size: 2,334 Bytes
262784e
 
 
9c7c1f6
c723413
 
9c7c1f6
 
c723413
262784e
9c7c1f6
 
 
 
 
 
 
 
c723413
9c7c1f6
 
 
262784e
 
 
 
9c7c1f6
 
262784e
 
9c7c1f6
262784e
9c7c1f6
160032f
c723413
9c7c1f6
c723413
 
941d51f
160032f
 
941d51f
 
 
 
160032f
c723413
9c7c1f6
262784e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
from food_data import FOOD_ITEMS

def get_food_details(name, image, nutrition_details):
    """Generate clean HTML content with the image and structured nutrition values."""
    # Split the nutrition details into separate lines
    nutrition_list = nutrition_details.split(", ")
    formatted_nutrition = "<br>".join(nutrition_list)

    return f"""
    <div style="text-align: center; padding: 15px; border: 2px solid #ddd; 
                border-radius: 10px; box-shadow: 0px 4px 8px rgba(0,0,0,0.2); 
                background-color: #fff; width: 100%; max-width: 400px; margin: auto;">
        <img src='{image}' alt='{name}' 
             style='width: 100%; max-height: 200px; border-radius: 10px; margin-bottom: 15px;'>
        <h2 style="color: #FF6347; margin: 10px 0; font-size: 1.8em;">{name}</h2>
        <div style="text-align: left; margin-top: 10px;">
            <h3 style="color: #555; text-align: center;">Nutrition</h3>
            <p style="font-size: 1em; color: #333; line-height: 1.6; margin-left: 20px;">
                {formatted_nutrition}
            </p>
        </div>
    </div>
    """

# Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("<h1 style='text-align:center; color:#FF6347;'>🍽️ Restaurant Menu 🍽️</h1>")
    
    for category, items in FOOD_ITEMS.items():
        gr.Markdown(f"<h2 style='text-align:center; color:#FF6347;'>{category} Menu</h2>")
        with gr.Row():
            for item in items:
                with gr.Column():
                    # Button for each food item
                    btn = gr.Button(item["name"], elem_id=f"menu-item-{item['name'].lower()}")
                    output_html = gr.HTML()  # Output will be formatted HTML

                    # Display clean HTML content on button click
                    btn.click(
                        fn=get_food_details, 
                        inputs=[gr.Text(value=item["name"], visible=False),
                                gr.Text(value=item["image"], visible=False),
                                gr.Text(value=item["nutrition"], visible=False)],
                        outputs=output_html
                    )

    gr.Markdown("<p style='text-align:center; margin-top:20px; color: gray;'>© 2024 Delicious Restaurant | Designed with ❤️</p>")

demo.launch()