DSatishchandra commited on
Commit
920d44a
·
verified ·
1 Parent(s): a28f86c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -60
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
- 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()
 
 
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()