Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,78 +1,56 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
|
| 5 |
-
# Load menu data from the Excel file
|
| 6 |
def load_menu(file_path="menu.xlsx"):
|
| 7 |
menu_data = pd.read_excel(file_path)
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
# Generate HTML
|
| 14 |
-
def generate_menu_html(menu):
|
| 15 |
html_content = ""
|
| 16 |
-
for
|
| 17 |
-
html_content += f"
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
<div
|
| 21 |
-
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 150px; height: 100px; object-fit: cover; margin-bottom: 10px;">
|
| 22 |
<h4>{item['Dish Name']}</h4>
|
| 23 |
-
<p>
|
| 24 |
-
<
|
|
|
|
| 25 |
</div>
|
| 26 |
-
|
| 27 |
-
html_content += "</div>"
|
| 28 |
-
return html_content
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
# Fetch dish details for the pop-up card
|
| 32 |
-
def fetch_dish_details(dish_name, menu_data_path="menu.xlsx"):
|
| 33 |
-
menu_data = pd.read_excel(menu_data_path)
|
| 34 |
-
item = menu_data[menu_data["Dish Name"] == dish_name].to_dict(orient="records")
|
| 35 |
-
if item:
|
| 36 |
-
details = item[0]
|
| 37 |
-
html = f"""
|
| 38 |
-
<h2>{details['Dish Name']}</h2>
|
| 39 |
-
<img src="{details['Image URL']}" alt="{details['Dish Name']}" style="width: 200px; margin-bottom: 20px;">
|
| 40 |
-
<p><strong>Description:</strong> {details['Description']}</p>
|
| 41 |
-
<p><strong>Ingredients:</strong> {details['Ingredients']}</p>
|
| 42 |
-
<p><strong>Allergen Info:</strong> {details['Allergen Info']}</p>
|
| 43 |
-
<p><strong>Recommended Items:</strong> {details['Recommended Items']}</p>
|
| 44 |
-
<p><strong>Spice Levels:</strong> {details['Spice Levels']}</p>
|
| 45 |
"""
|
| 46 |
-
|
| 47 |
-
else:
|
| 48 |
-
return "<p style='color: red;'>Dish not found.</p>"
|
| 49 |
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
menu = load_menu()
|
| 54 |
-
menu_html = generate_menu_html(menu)
|
| 55 |
-
return menu_html
|
| 56 |
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
with gr.Blocks() as app:
|
| 65 |
-
with gr.Row():
|
| 66 |
-
gr.Markdown("# Dynamic Menu Display")
|
| 67 |
-
with gr.Row():
|
| 68 |
-
menu_output = gr.HTML()
|
| 69 |
-
detail_output = gr.HTML()
|
| 70 |
-
with gr.Row():
|
| 71 |
-
dish_name_input = gr.Textbox(label="Dish Name", placeholder="Enter dish name to view details.")
|
| 72 |
-
fetch_button = gr.Button("Fetch Details")
|
| 73 |
-
fetch_button.click(fn=detail_interface, inputs=[dish_name_input], outputs=[detail_output])
|
| 74 |
-
menu_output.value = main_interface()
|
| 75 |
|
| 76 |
-
#
|
| 77 |
if __name__ == "__main__":
|
| 78 |
-
app
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Load the menu data from the Excel file
|
|
|
|
| 5 |
def load_menu(file_path="menu.xlsx"):
|
| 6 |
menu_data = pd.read_excel(file_path)
|
| 7 |
+
return menu_data
|
| 8 |
+
|
| 9 |
+
# Filter the menu based on user preference
|
| 10 |
+
def filter_menu(preference):
|
| 11 |
+
menu_data = load_menu()
|
| 12 |
+
|
| 13 |
+
if preference != "All":
|
| 14 |
+
filtered_data = menu_data[menu_data["Category"] == preference]
|
| 15 |
+
else:
|
| 16 |
+
filtered_data = menu_data
|
| 17 |
|
| 18 |
+
# Generate HTML for filtered menu
|
|
|
|
| 19 |
html_content = ""
|
| 20 |
+
for _, item in filtered_data.iterrows():
|
| 21 |
+
html_content += f"""
|
| 22 |
+
<div style="border: 1px solid #ddd; margin: 10px; padding: 10px; border-radius: 8px; display: flex; align-items: center;">
|
| 23 |
+
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; object-fit: cover; margin-right: 10px;">
|
| 24 |
+
<div>
|
|
|
|
| 25 |
<h4>{item['Dish Name']}</h4>
|
| 26 |
+
<p>{item['Description']}</p>
|
| 27 |
+
<p><strong>Price:</strong> ${item['Price']}</p>
|
| 28 |
+
<button style="background-color: #28a745; color: white; border: none; padding: 5px 10px; border-radius: 5px; cursor: pointer;">Add</button>
|
| 29 |
</div>
|
| 30 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
"""
|
| 32 |
+
return html_content
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
# Gradio app definition
|
| 35 |
+
def app():
|
| 36 |
+
preferences = ["All", "Vegan", "Halal", "Guilt-Free"]
|
| 37 |
|
| 38 |
+
with gr.Blocks() as demo:
|
| 39 |
+
gr.Markdown("# Dynamic Menu with Preferences")
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
# Radio buttons for preferences
|
| 42 |
+
selected_preference = gr.Radio(preferences, label="Choose a Preference")
|
| 43 |
|
| 44 |
+
# Display the filtered menu
|
| 45 |
+
menu_output = gr.HTML()
|
| 46 |
+
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
| 47 |
|
| 48 |
+
# Initial menu load (all items)
|
| 49 |
+
menu_output.value = filter_menu("All")
|
| 50 |
|
| 51 |
+
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
# Run the app
|
| 54 |
if __name__ == "__main__":
|
| 55 |
+
demo = app()
|
| 56 |
+
demo.launch()
|