Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,78 @@
|
|
1 |
-
from flask import Flask, render_template, request, jsonify
|
2 |
import pandas as pd
|
|
|
3 |
|
4 |
-
app = Flask(__name__)
|
5 |
|
6 |
-
# Load the
|
7 |
def load_menu(file_path="menu.xlsx"):
|
8 |
menu_data = pd.read_excel(file_path)
|
9 |
grouped_menu = menu_data.groupby("Category")
|
10 |
-
return grouped_menu
|
11 |
-
|
12 |
-
# Route to serve the menu
|
13 |
-
@app.route("/")
|
14 |
-
def index():
|
15 |
-
grouped_menu = load_menu()
|
16 |
menu = {category: items.to_dict(orient="records") for category, items in grouped_menu}
|
17 |
-
return
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
def
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
if item:
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
else:
|
32 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
|
|
34 |
if __name__ == "__main__":
|
35 |
-
app.
|
|
|
|
|
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 |
grouped_menu = menu_data.groupby("Category")
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
menu = {category: items.to_dict(orient="records") for category, items in grouped_menu}
|
10 |
+
return menu
|
11 |
+
|
12 |
+
|
13 |
+
# Generate HTML content for the menu
|
14 |
+
def generate_menu_html(menu):
|
15 |
+
html_content = ""
|
16 |
+
for category, items in menu.items():
|
17 |
+
html_content += f"<h2>{category}</h2><div style='margin-bottom: 20px;'>"
|
18 |
+
for item in items:
|
19 |
+
html_content += f"""
|
20 |
+
<div style="border: 1px solid #ddd; margin: 10px; padding: 10px; border-radius: 8px; display: inline-block; width: 200px; vertical-align: top; text-align: center;">
|
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>Price: ${item['Price']}</p>
|
24 |
+
<button onclick="showDetails('{item['Dish Name']}')">Add</button>
|
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 |
+
return html
|
47 |
else:
|
48 |
+
return "<p style='color: red;'>Dish not found.</p>"
|
49 |
+
|
50 |
+
|
51 |
+
# Gradio interface for the main menu and dish details
|
52 |
+
def main_interface():
|
53 |
+
menu = load_menu()
|
54 |
+
menu_html = generate_menu_html(menu)
|
55 |
+
return menu_html
|
56 |
+
|
57 |
+
|
58 |
+
def detail_interface(dish_name):
|
59 |
+
details_html = fetch_dish_details(dish_name)
|
60 |
+
return details_html
|
61 |
+
|
62 |
+
|
63 |
+
# Gradio App
|
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 |
+
# Launch the app
|
77 |
if __name__ == "__main__":
|
78 |
+
app.launch()
|