File size: 5,300 Bytes
ba4dd53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7dfd949
ba4dd53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7dfd949
ba4dd53
7dfd949
 
ba4dd53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7dfd949
 
 
ba4dd53
7dfd949
d0024b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7dfd949
d0024b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7980609
 
 
920d44a
013b172
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import gradio as gr
import pandas as pd

# Load menu data from Excel
def load_menu():
    menu_file = "menu.xlsx"  # Ensure this file exists in the same directory
    try:
        return pd.read_excel(menu_file)
    except Exception as e:
        raise ValueError(f"Error loading menu file: {e}")

# Main menu view
def render_menu(preference):
    menu_data = load_menu()

    if preference == "Halal/Non-Veg":
        filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
    elif preference == "Vegetarian":
        filtered_data = menu_data[~menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
    elif preference == "Guilt-Free":
        filtered_data = menu_data[menu_data["Description"].str.contains(r"Fat: ([0-9]|10)g", case=False, na=False)]
    else:
        filtered_data = menu_data

    # Generate menu as a list of tuples (dish_name, button_label)
    return [{"label": f"{row['Dish Name']} - ${row['Price ($)']}", "value": row['Dish Name']} for _, row in filtered_data.iterrows()]

# Dish details view
def render_dish_details(dish_name):
    menu_data = load_menu()
    dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0]
    return (
        dish["Image URL"],
        dish_name,
        dish["Description"],
        dish["Price ($)"]
    )

# Add to cart function
def add_to_cart(dish_name, spice_level, extras, quantity, special_instructions, cart):
    cart.append({
        "name": dish_name,
        "spice_level": spice_level,
        "extras": extras,
        "quantity": quantity,
        "instructions": special_instructions
    })
    return cart, f"Added {dish_name} to cart!"

# Gradio app
def app():
    with gr.Blocks() as demo:
        cart_state = gr.State([])

        # Menu page
        menu_dropdown = gr.Dropdown(
            label="Select a dish to view details",
            choices=[],
            interactive=True,
        )
        cart_view = gr.HTML(value="Your cart is empty.", interactive=False)

        # Dish details view
        detailed_view = gr.Column(visible=False)
        dish_image = gr.Image()
        dish_name = gr.Markdown()
        dish_description = gr.Markdown()
        dish_price = gr.Markdown()
        spice_level = gr.Radio(
            choices=["Mild", "Medium", "Spicy"],
            label="Choose Spice Level",
        )
        extras = gr.CheckboxGroup(
            choices=["Extra Raita", "Extra Salan", "Extra Fried Onion"],
            label="Choose Extras",
        )
        quantity = gr.Number(label="Quantity", value=1, interactive=True)
        special_instructions = gr.Textbox(
            label="Special Instructions",
            placeholder="Add any special instructions here",
        )
        add_button = gr.Button("Add to Cart")
        back_button = gr.Button("Back to Menu")

        # Update menu with dish options
        def update_menu(preference):
            menu_choices = render_menu(preference)
            return gr.update(choices=[choice["label"] for choice in menu_choices])

        # Show dish details
        def show_dish_details(dish_name):
            img, name, desc, price = render_dish_details(dish_name)
            return (
                gr.update(visible=False),
                gr.update(visible=True),
                img,
                f"## {name}",
                desc,
                f"**Price:** ${price}",
            )

        # Add to cart
        def handle_add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart):
            updated_cart, message = add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart)
            cart_html = "<br>".join(
                [f"{item['quantity']}x {item['name']} - {item['spice_level']}" for item in updated_cart]
            )
            return updated_cart, cart_html

        # Switch back to menu
        def back_to_menu():
            return gr.update(visible=True), gr.update(visible=False)

        # Interactions
        menu_dropdown.change(
            show_dish_details,
            inputs=[menu_dropdown],
            outputs=[
                menu_dropdown,
                detailed_view,
                dish_image,
                dish_name,
                dish_description,
                dish_price,
            ],
        )
        add_button.click(
            handle_add_to_cart,
            inputs=[
                dish_name,
                spice_level,
                extras,
                quantity,
                special_instructions,
                cart_state,
            ],
            outputs=[cart_state, cart_view],
        )
        back_button.click(
            back_to_menu,
            outputs=[menu_dropdown, detailed_view],
        )

        # Layout for Gradio app
        with gr.Row():
            gr.Markdown("## Menu")
            menu_dropdown
            cart_view

        with detailed_view:
            dish_image
            dish_name
            dish_description
            dish_price
            spice_level
            extras
            quantity
            special_instructions
            add_button
            back_button

    return demo


if __name__ == "__main__":
    demo = app()
    demo.launch()