nagasurendra commited on
Commit
f9601e7
·
verified ·
1 Parent(s): 012d61e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -28
app.py CHANGED
@@ -64,46 +64,39 @@ def login(email, password):
64
  # Function to load menu items from Salesforce
65
  def load_menu_from_salesforce():
66
  try:
67
- query = "SELECT Name, Price__c, Description__c, Image1__c, Ingredients__c FROM Menu_Item__c"
68
  result = sf.query(query)
69
  return result['records']
70
  except Exception as e:
71
  raise ValueError(f"Error loading menu data from Salesforce: {e}")
72
 
73
  # Function to filter menu items based on preference
74
- def filter_menu_from_salesforce(preference):
75
  menu_data = load_menu_from_salesforce()
76
  filtered_data = []
77
 
78
  for item in menu_data:
79
- if preference == "Halal/Non-Veg":
80
- if any(x in item.get("Ingredients__c", "").lower() for x in ["chicken", "mutton", "fish", "prawns", "goat"]):
81
- filtered_data.append(item)
82
- elif preference == "Vegetarian":
83
- if not any(x in item.get("Ingredients__c", "").lower() for x in ["chicken", "mutton", "fish", "prawns", "goat"]):
84
- filtered_data.append(item)
85
- elif preference == "Guilt-Free":
86
- if "fat:" in item.get("Description__c", "").lower():
87
- filtered_data.append(item)
88
- else:
89
- filtered_data = menu_data
90
 
91
- html_content = ""
 
92
  for item in filtered_data:
93
  html_content += f"""
94
- <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);">
95
- <div style="flex: 1; margin-right: 15px;">
96
- <h3 style="margin: 0; font-size: 18px;">{item['Name']}</h3>
 
97
  <p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price__c']}</p>
98
- <p style="margin: 5px 0; font-size: 14px; color: #555;">{item['Description__c']}</p>
99
- </div>
100
- <div style="flex-shrink: 0; text-align: center;">
101
- <img src="{item['Image1__c']}" alt="{item['Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
102
- <button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;">Add</button>
103
  </div>
104
  </div>
105
  """
106
- return html_content
 
107
 
108
  # Gradio App
109
  with gr.Blocks() as app:
@@ -131,8 +124,9 @@ with gr.Blocks() as app:
131
 
132
  # Menu Page
133
  with gr.Row(visible=False) as menu_page:
134
- preference = gr.Radio(["All", "Halal/Non-Veg", "Vegetarian", "Guilt-Free"], label="Filter Preference")
135
- show_menu = gr.Button("Show Menu")
 
136
  menu_output = gr.HTML()
137
 
138
  # Functions for page transitions and operations
@@ -146,14 +140,14 @@ with gr.Blocks() as app:
146
  def handle_signup(name, email, phone, password):
147
  return signup(name, email, phone, password)
148
 
149
- def handle_menu(preference):
150
- return filter_menu_from_salesforce(preference)
151
 
152
  # Button Actions
153
  login_button.click(handle_login, [login_email, login_password], [login_page, menu_page, login_output])
154
  signup_button.click(lambda: (gr.update(visible=False), gr.update(visible=True)), None, [login_page, signup_page])
155
  submit_signup.click(handle_signup, [signup_name, signup_email, signup_phone, signup_password], signup_output)
156
  login_redirect.click(lambda: (gr.update(visible=False), gr.update(visible=True)), None, [signup_page, login_page])
157
- show_menu.click(handle_menu, [preference], menu_output)
158
 
159
  app.launch()
 
64
  # Function to load menu items from Salesforce
65
  def load_menu_from_salesforce():
66
  try:
67
+ query = "SELECT Name, Price__c, Description__c, Image1__c, Veg_NonVeg__c FROM Menu_Item__c"
68
  result = sf.query(query)
69
  return result['records']
70
  except Exception as e:
71
  raise ValueError(f"Error loading menu data from Salesforce: {e}")
72
 
73
  # Function to filter menu items based on preference
74
+ def filter_menu(preferences):
75
  menu_data = load_menu_from_salesforce()
76
  filtered_data = []
77
 
78
  for item in menu_data:
79
+ if "Veg" in preferences and item["Veg_NonVeg__c"] in ["Veg", "Both"]:
80
+ filtered_data.append(item)
81
+ elif "Non-Veg" in preferences and item["Veg_NonVeg__c"] in ["Non-Veg", "Both"]:
82
+ filtered_data.append(item)
 
 
 
 
 
 
 
83
 
84
+ # Generate HTML content
85
+ html_content = '<div style="display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;">'
86
  for item in filtered_data:
87
  html_content += f"""
88
+ <div style="width: 300px; border: 1px solid #ddd; border-radius: 10px; overflow: hidden; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
89
+ <img src="{item['Image1__c']}" alt="{item['Name']}" style="width: 100%; height: 200px; object-fit: cover;">
90
+ <div style="padding: 15px;">
91
+ <h3 style="margin: 0; font-size: 20px; color: #333;">{item['Name']}</h3>
92
  <p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price__c']}</p>
93
+ <p style="margin: 10px 0; font-size: 14px; color: #555;">{item['Description__c']}</p>
94
+ <button style="width: 100%; padding: 10px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button>
 
 
 
95
  </div>
96
  </div>
97
  """
98
+ html_content += '</div>'
99
+ return html_content or "<p style='text-align: center;'>No items match your filter.</p>"
100
 
101
  # Gradio App
102
  with gr.Blocks() as app:
 
124
 
125
  # Menu Page
126
  with gr.Row(visible=False) as menu_page:
127
+ preferences = gr.CheckboxGroup(
128
+ choices=["Veg", "Non-Veg"], label="Filter Preference", value=["Veg", "Non-Veg"]
129
+ )
130
  menu_output = gr.HTML()
131
 
132
  # Functions for page transitions and operations
 
140
  def handle_signup(name, email, phone, password):
141
  return signup(name, email, phone, password)
142
 
143
+ def handle_menu(preferences):
144
+ return filter_menu(preferences)
145
 
146
  # Button Actions
147
  login_button.click(handle_login, [login_email, login_password], [login_page, menu_page, login_output])
148
  signup_button.click(lambda: (gr.update(visible=False), gr.update(visible=True)), None, [login_page, signup_page])
149
  submit_signup.click(handle_signup, [signup_name, signup_email, signup_phone, signup_password], signup_output)
150
  login_redirect.click(lambda: (gr.update(visible=False), gr.update(visible=True)), None, [signup_page, login_page])
151
+ preferences.change(handle_menu, [preferences], menu_output)
152
 
153
  app.launch()