Spaces:
Sleeping
Sleeping
File size: 4,263 Bytes
6a94706 b537c3b 7980609 af61c2f b537c3b 2eb1a73 96fe3dc b537c3b 920d44a af61c2f f03d6fd af61c2f f03d6fd af61c2f f03d6fd af61c2f f03d6fd af61c2f f03d6fd af61c2f f03d6fd af61c2f f03d6fd af61c2f 920d44a af61c2f 2eb1a73 af61c2f 6a94706 af61c2f 6a94706 af61c2f b16d730 af61c2f ad4e58e af61c2f 013b172 af61c2f 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 |
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
menu_html = ""
for _, item in filtered_data.iterrows():
menu_html += f"""
<div style="display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; margin-bottom: 10px;">
<div style="flex: 1; margin-right: 15px;">
<h3 style="margin: 0;">{item['Dish Name']}</h3>
<p style="margin: 5px 0;">${item['Price ($)']}</p>
<p>{item['Description']}</p>
</div>
<div>
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover;">
<button style="background-color: #28a745; color: white; padding: 8px 15px; border: none; cursor: pointer;"
onclick="return '{item['Dish Name']}'">View Details</button>
</div>
</div>
"""
return menu_html
# 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 {
"image": dish["Image URL"],
"name": dish_name,
"description": dish["Description"],
"price": dish["Price ($)"]
}
# Add to cart
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_html = gr.HTML(render_menu("All"))
detailed_view = gr.Column(visible=False)
cart_view = gr.Column(visible=False)
# Detailed view inputs
spice_level = gr.Dropdown(choices=["Mild", "Medium", "Spicy"], label="Spice Level")
extras = gr.CheckboxGroup(choices=["Extra Raita", "Extra Salan", "Extra Onion"], label="Extras")
quantity = gr.Number(value=1, label="Quantity")
special_instructions = gr.Textbox(placeholder="Add instructions", label="Special Instructions")
add_button = gr.Button("Add to Cart")
back_button = gr.Button("Back to Menu")
# Cart view
cart_html = gr.HTML(value="Your cart is empty.")
# Switch to detailed view
def show_dish_details(dish_name):
details = render_dish_details(dish_name)
return gr.update(visible=False), gr.update(visible=True), details["image"], details["name"], details["description"], details["price"]
# Add to cart
def handle_add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart):
return add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart)
# Navigation
menu_html.change(show_dish_details, inputs=["dish_name"], outputs=[menu_html, detailed_view])
add_button.click(handle_add_to_cart, inputs=[spice_level, extras, quantity, special_instructions, cart_state], outputs=[cart_state, cart_html])
back_button.click(lambda: (gr.update(visible=True), gr.update(visible=False)), outputs=[menu_html, detailed_view])
return demo
if __name__ == "__main__":
demo = app()
demo.launch()
|