Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
-
# Function to load menu data
|
| 5 |
def load_menu():
|
|
|
|
| 6 |
try:
|
| 7 |
-
return pd.read_excel(
|
| 8 |
except Exception as e:
|
| 9 |
raise ValueError(f"Error loading menu file: {e}")
|
| 10 |
|
| 11 |
-
# Function to filter menu items
|
| 12 |
def filter_menu(preference):
|
|
|
|
| 13 |
menu_data = load_menu()
|
|
|
|
|
|
|
| 14 |
if preference == "Halal/Non-Veg":
|
| 15 |
filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
|
| 16 |
elif preference == "Vegetarian":
|
|
@@ -20,39 +24,41 @@ def filter_menu(preference):
|
|
| 20 |
else: # Default to "All"
|
| 21 |
filtered_data = menu_data
|
| 22 |
|
| 23 |
-
# Generate HTML for menu
|
| 24 |
html_content = ""
|
| 25 |
for _, item in filtered_data.iterrows():
|
| 26 |
html_content += f"""
|
| 27 |
<div class="menu-card">
|
| 28 |
-
<div class="menu-card-
|
| 29 |
<h3>{item['Dish Name']}</h3>
|
|
|
|
| 30 |
<p>{item['Description']}</p>
|
| 31 |
-
<p><strong>${item['Price ($)']}</strong></p>
|
| 32 |
</div>
|
| 33 |
<div class="menu-card-actions">
|
| 34 |
<img src="{item['Image URL']}" alt="{item['Dish Name']}" class="menu-card-image">
|
| 35 |
-
<button
|
| 36 |
</div>
|
| 37 |
</div>
|
| 38 |
"""
|
| 39 |
return html_content
|
| 40 |
|
| 41 |
-
#
|
| 42 |
def app():
|
| 43 |
with gr.Blocks(css="style.css") as demo:
|
| 44 |
gr.Markdown("## Dynamic Menu with Preferences")
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
| 48 |
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
| 49 |
value="All",
|
| 50 |
-
label="Choose a Preference"
|
| 51 |
)
|
|
|
|
|
|
|
| 52 |
menu_output = gr.HTML(value=filter_menu("All"))
|
| 53 |
|
| 54 |
-
# Modal
|
| 55 |
-
|
| 56 |
<div id="modal" class="modal">
|
| 57 |
<div class="modal-content">
|
| 58 |
<span class="close-button" onclick="closeModal()">×</span>
|
|
@@ -86,16 +92,20 @@ def app():
|
|
| 86 |
</script>
|
| 87 |
""")
|
| 88 |
|
|
|
|
|
|
|
|
|
|
| 89 |
# Layout
|
| 90 |
with gr.Row():
|
| 91 |
-
|
| 92 |
with gr.Row():
|
| 93 |
menu_output
|
| 94 |
with gr.Row():
|
| 95 |
-
|
| 96 |
|
| 97 |
return demo
|
| 98 |
|
| 99 |
-
|
| 100 |
if __name__ == "__main__":
|
| 101 |
-
app()
|
|
|
|
|
|
| 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":
|
|
|
|
| 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 class="menu-card">
|
| 32 |
+
<div class="menu-card-details">
|
| 33 |
<h3>{item['Dish Name']}</h3>
|
| 34 |
+
<p>${item['Price ($)']}</p>
|
| 35 |
<p>{item['Description']}</p>
|
|
|
|
| 36 |
</div>
|
| 37 |
<div class="menu-card-actions">
|
| 38 |
<img src="{item['Image URL']}" alt="{item['Dish Name']}" class="menu-card-image">
|
| 39 |
+
<button onclick="openModal('{item['Dish Name']}', '{item['Image URL']}', '{item['Description']}', '{item['Price ($)']}')" class="add-button">Add</button>
|
| 40 |
</div>
|
| 41 |
</div>
|
| 42 |
"""
|
| 43 |
return html_content
|
| 44 |
|
| 45 |
+
# Gradio app definition
|
| 46 |
def app():
|
| 47 |
with gr.Blocks(css="style.css") 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 |
+
# Modal window (hidden by default)
|
| 61 |
+
modal_window = gr.HTML("""
|
| 62 |
<div id="modal" class="modal">
|
| 63 |
<div class="modal-content">
|
| 64 |
<span class="close-button" onclick="closeModal()">×</span>
|
|
|
|
| 92 |
</script>
|
| 93 |
""")
|
| 94 |
|
| 95 |
+
# Interactivity
|
| 96 |
+
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
| 97 |
+
|
| 98 |
# Layout
|
| 99 |
with gr.Row():
|
| 100 |
+
selected_preference
|
| 101 |
with gr.Row():
|
| 102 |
menu_output
|
| 103 |
with gr.Row():
|
| 104 |
+
modal_window
|
| 105 |
|
| 106 |
return demo
|
| 107 |
|
| 108 |
+
# Run the app
|
| 109 |
if __name__ == "__main__":
|
| 110 |
+
demo = app()
|
| 111 |
+
demo.launch()
|