Spaces:
Sleeping
Sleeping
app.py
Browse files
app.py
DELETED
|
@@ -1,72 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import pandas as pd
|
| 3 |
-
|
| 4 |
-
# Function to load the menu data from Excel
|
| 5 |
-
def load_menu():
|
| 6 |
-
menu_file = "menu.xlsx" # Ensure this file exists in the same directory
|
| 7 |
-
try:
|
| 8 |
-
return pd.read_excel(menu_file)
|
| 9 |
-
except Exception as e:
|
| 10 |
-
raise ValueError(f"Error loading menu file: {e}")
|
| 11 |
-
|
| 12 |
-
# Function to filter menu items based on preference
|
| 13 |
-
def filter_menu(preference):
|
| 14 |
-
# Load menu data
|
| 15 |
-
menu_data = load_menu()
|
| 16 |
-
|
| 17 |
-
# Define filter conditions
|
| 18 |
-
if preference == "Halal/Non-Veg":
|
| 19 |
-
filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
|
| 20 |
-
elif preference == "Vegetarian":
|
| 21 |
-
filtered_data = menu_data[~menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
|
| 22 |
-
elif preference == "Guilt-Free":
|
| 23 |
-
filtered_data = menu_data[menu_data["Description"].str.contains(r"Fat: ([0-9]|10)g", case=False, na=False)]
|
| 24 |
-
else: # Default to "All"
|
| 25 |
-
filtered_data = menu_data
|
| 26 |
-
|
| 27 |
-
# Generate HTML for the menu
|
| 28 |
-
html_content = ""
|
| 29 |
-
for _, item in filtered_data.iterrows():
|
| 30 |
-
html_content += f"""
|
| 31 |
-
<div style="display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; margin-bottom: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
|
| 32 |
-
<div style="flex: 1; margin-right: 15px;">
|
| 33 |
-
<h3 style="margin: 0; font-size: 18px;">{item['Dish Name']}</h3>
|
| 34 |
-
<p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price ($)']}</p>
|
| 35 |
-
<p style="margin: 5px 0; font-size: 14px; color: #555;">{item['Description']}</p>
|
| 36 |
-
</div>
|
| 37 |
-
<div style="flex-shrink: 0; text-align: center;">
|
| 38 |
-
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
|
| 39 |
-
<button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;">Add</button>
|
| 40 |
-
</div>
|
| 41 |
-
</div>
|
| 42 |
-
"""
|
| 43 |
-
return html_content
|
| 44 |
-
|
| 45 |
-
# Gradio app definition
|
| 46 |
-
def app():
|
| 47 |
-
with gr.Blocks(title="Dynamic Menu with Filters") as demo:
|
| 48 |
-
gr.Markdown("## Dynamic Menu with Preferences")
|
| 49 |
-
|
| 50 |
-
# Radio button for selecting preference
|
| 51 |
-
selected_preference = gr.Radio(
|
| 52 |
-
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
| 53 |
-
value="All",
|
| 54 |
-
label="Choose a Preference",
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
# Output area for menu items
|
| 58 |
-
menu_output = gr.HTML(value=filter_menu("All"))
|
| 59 |
-
|
| 60 |
-
# Define interactivity
|
| 61 |
-
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
| 62 |
-
|
| 63 |
-
# Layout
|
| 64 |
-
gr.Row([selected_preference])
|
| 65 |
-
gr.Row(menu_output)
|
| 66 |
-
|
| 67 |
-
return demo
|
| 68 |
-
|
| 69 |
-
# Run the app
|
| 70 |
-
if __name__ == "__main__":
|
| 71 |
-
demo = app()
|
| 72 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|