nagasurendra commited on
Commit
9da809b
·
verified ·
1 Parent(s): e767e0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -16
app.py CHANGED
@@ -65,40 +65,59 @@ def load_menu_from_salesforce():
65
  try:
66
  query = "SELECT Name, Price__c, Description__c, Image1__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c"
67
  result = sf.query(query)
68
- return result['records']
 
 
 
 
 
 
 
69
  except Exception as e:
70
  raise ValueError(f"Error loading menu data from Salesforce: {e}")
71
 
72
  # Function to filter menu items based on preference
73
  def filter_menu(preferences):
74
  menu_data = load_menu_from_salesforce()
 
 
 
 
 
 
75
  filtered_data = {}
76
 
77
  for item in menu_data:
 
78
  if item["Section__c"] not in filtered_data:
79
  filtered_data[item["Section__c"]] = []
80
 
81
- if "Veg" in preferences and item["Veg_NonVeg__c"] in ["Veg", "Both"]:
 
 
 
82
  filtered_data[item["Section__c"]].append(item)
83
  elif "Non-Veg" in preferences and item["Veg_NonVeg__c"] in ["Non-Veg", "Both"]:
84
  filtered_data[item["Section__c"]].append(item)
85
 
 
86
  html_content = '<div style="padding: 20px; max-width: 1200px; margin: auto;">'
87
  for section, items in filtered_data.items():
88
- html_content += f"<h2 style='text-align: center; color: #333;'>{section}</h2>"
89
- html_content += '<div style="display: flex; flex-wrap: wrap; justify-content: center; gap: 20px;">'
90
- for item in items:
91
- html_content += f"""
92
- <div style="width: 300px; border: 1px solid #ddd; border-radius: 10px; overflow: hidden; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
93
- <img src="{item['Image1__c']}" alt="{item['Name']}" style="width: 100%; height: 200px; object-fit: cover;">
94
- <div style="padding: 15px;">
95
- <h3 style="margin: 0; font-size: 20px; color: #333;">{item['Name']}</h3>
96
- <p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price__c']}</p>
97
- <p style="margin: 10px 0; font-size: 14px; color: #555;">{item['Description__c']}</p>
 
 
98
  </div>
99
- </div>
100
- """
101
- html_content += '</div>'
102
  html_content += '</div>'
103
  return html_content or "<p style='text-align: center;'>No items match your filter.</p>"
104
 
@@ -133,7 +152,7 @@ with gr.Blocks() as app:
133
  # Menu Page
134
  with gr.Row(visible=False) as menu_page:
135
  preferences = gr.CheckboxGroup(
136
- choices=["Veg", "Non-Veg"], label="Filter Preference"
137
  )
138
  menu_output = gr.HTML()
139
 
 
65
  try:
66
  query = "SELECT Name, Price__c, Description__c, Image1__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c"
67
  result = sf.query(query)
68
+ menu_data = result['records']
69
+
70
+ # Debug output for fetched data
71
+ print("Fetched Menu Items:")
72
+ for record in menu_data:
73
+ print(record)
74
+
75
+ return menu_data
76
  except Exception as e:
77
  raise ValueError(f"Error loading menu data from Salesforce: {e}")
78
 
79
  # Function to filter menu items based on preference
80
  def filter_menu(preferences):
81
  menu_data = load_menu_from_salesforce()
82
+
83
+ # Debug the data fetched from Salesforce
84
+ print("Menu Data Fetched from Salesforce:")
85
+ for item in menu_data:
86
+ print(item)
87
+
88
  filtered_data = {}
89
 
90
  for item in menu_data:
91
+ # Add the section to filtered data if not already present
92
  if item["Section__c"] not in filtered_data:
93
  filtered_data[item["Section__c"]] = []
94
 
95
+ # Apply filters based on preferences
96
+ if "All" in preferences:
97
+ filtered_data[item["Section__c"]].append(item)
98
+ elif "Veg" in preferences and item["Veg_NonVeg__c"] in ["Veg", "Both"]:
99
  filtered_data[item["Section__c"]].append(item)
100
  elif "Non-Veg" in preferences and item["Veg_NonVeg__c"] in ["Non-Veg", "Both"]:
101
  filtered_data[item["Section__c"]].append(item)
102
 
103
+ # Generate HTML content
104
  html_content = '<div style="padding: 20px; max-width: 1200px; margin: auto;">'
105
  for section, items in filtered_data.items():
106
+ if items: # Only render sections with items
107
+ html_content += f"<h2 style='text-align: center; color: #333;'>{section}</h2>"
108
+ html_content += '<div style="display: flex; flex-wrap: wrap; justify-content: center; gap: 20px;">'
109
+ for item in items:
110
+ html_content += f"""
111
+ <div style="width: 300px; border: 1px solid #ddd; border-radius: 10px; overflow: hidden; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
112
+ <img src="{item['Image1__c']}" alt="{item['Name']}" style="width: 100%; height: 200px; object-fit: cover;">
113
+ <div style="padding: 15px;">
114
+ <h3 style="margin: 0; font-size: 20px; color: #333;">{item['Name']}</h3>
115
+ <p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price__c']}</p>
116
+ <p style="margin: 10px 0; font-size: 14px; color: #555;">{item['Description__c']}</p>
117
+ </div>
118
  </div>
119
+ """
120
+ html_content += '</div>'
 
121
  html_content += '</div>'
122
  return html_content or "<p style='text-align: center;'>No items match your filter.</p>"
123
 
 
152
  # Menu Page
153
  with gr.Row(visible=False) as menu_page:
154
  preferences = gr.CheckboxGroup(
155
+ choices=["All", "Veg", "Non-Veg"], label="Filter Preference"
156
  )
157
  menu_output = gr.HTML()
158