SathvikGanta commited on
Commit
358b6a5
·
verified ·
1 Parent(s): 23e35cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -63
app.py CHANGED
@@ -1,72 +1,35 @@
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()
 
1
  import gradio as gr
2
+ from components.menu import generate_menu
3
+ from components.cart import cart
4
  import pandas as pd
5
 
6
+ # Load menu data
7
+ menu_data = pd.read_excel("data/menu.xlsx")
8
+
9
+ # Initialize the app
10
+ def main():
11
+ with gr.Blocks(css="static/styles.css") as app:
12
+ gr.Markdown("# Dynamic Menu with Popups and Cart")
13
+
14
+ # Preference Selection
15
+ preference = gr.Radio(
16
+ label="Select Preference",
17
+ choices=["All", "Vegetarian", "Non-Vegetarian", "Guilt-Free"],
18
+ value="All"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  )
20
+
21
+ # Menu Display
22
+ menu_display = gr.Column()
23
+ preference.change(generate_menu, inputs=[preference, menu_data], outputs=menu_display)
24
 
25
+ # Popup Display
26
+ popup_display = gr.Column(visible=False) # Placeholder for popups
 
 
 
27
 
28
+ # Cart Display
29
+ gr.Markdown("## Your Cart")
30
+ cart_display = gr.Dataframe(headers=["Dish", "Spice Level", "Extras", "Instructions", "Quantity", "Price"])
31
 
32
+ app.launch()
33
 
 
34
  if __name__ == "__main__":
35
+ main()