nagasurendra commited on
Commit
45a308e
·
verified ·
1 Parent(s): 8cd3037

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -7
app.py CHANGED
@@ -65,17 +65,37 @@ 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
 
 
 
 
 
 
 
 
 
 
76
  filtered_data = {}
77
 
78
  for item in menu_data:
 
 
 
 
79
  # Add the section to filtered data if not already present
80
  if item["Section__c"] not in filtered_data:
81
  filtered_data[item["Section__c"]] = []
@@ -97,17 +117,22 @@ def filter_menu(preferences):
97
  for item in items:
98
  html_content += f"""
99
  <div style="width: 300px; border: 1px solid #ddd; border-radius: 10px; overflow: hidden; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
100
- <img src="{item['Image1__c']}" alt="{item['Name']}" style="width: 100%; height: 200px; object-fit: cover;">
101
  <div style="padding: 15px;">
102
- <h3 style="margin: 0; font-size: 20px; color: #333;'>{item['Name']}</h3>
103
- <p style="margin: 5px 0; font-size: 16px; color: #888;'>${item['Price__c']}</p>
104
- <p style="margin: 10px 0; font-size: 14px; color: #555;'>{item['Description__c']}</p>
105
  </div>
106
  </div>
107
  """
108
  html_content += '</div>'
109
  html_content += '</div>'
110
- return html_content or "<p style='text-align: center;'>No items match your filter.</p>"
 
 
 
 
 
111
 
112
  # Gradio App
113
  with gr.Blocks() as app:
@@ -170,4 +195,4 @@ with gr.Blocks() as app:
170
  login_redirect.click(lambda: (gr.update(visible=False), gr.update(visible=True)), None, [signup_page, login_page])
171
  preferences.change(handle_menu, [preferences], menu_output)
172
 
173
- app.launch()
 
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
+
69
+ # Debugging: Print fetched records
70
+ print("Fetched Records from Salesforce:")
71
+ for record in result['records']:
72
+ print(record)
73
+
74
  return result['records']
75
  except Exception as e:
76
+ print(f"Error fetching menu data: {e}")
77
+ return []
78
 
79
  # Function to filter menu items based on preference
80
  def filter_menu(preferences):
81
  menu_data = load_menu_from_salesforce()
82
 
83
+ # Debugging: Print the fetched menu data
84
+ print("Menu Data Fetched:")
85
+ for item in menu_data:
86
+ print(item)
87
+
88
+ # Check if data exists
89
+ if not menu_data:
90
+ return "<p style='text-align: center;'>No menu data available. Please try again later.</p>"
91
+
92
  filtered_data = {}
93
 
94
  for item in menu_data:
95
+ # Ensure the required fields exist
96
+ if "Section__c" not in item or "Veg_NonVeg__c" not in item:
97
+ continue
98
+
99
  # Add the section to filtered data if not already present
100
  if item["Section__c"] not in filtered_data:
101
  filtered_data[item["Section__c"]] = []
 
117
  for item in items:
118
  html_content += f"""
119
  <div style="width: 300px; border: 1px solid #ddd; border-radius: 10px; overflow: hidden; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
120
+ <img src="{item.get('Image1__c', '')}" alt="{item.get('Name', '')}" style="width: 100%; height: 200px; object-fit: cover;">
121
  <div style="padding: 15px;">
122
+ <h3 style="margin: 0; font-size: 20px; color: #333;'>{item.get('Name', 'Unknown Item')}</h3>
123
+ <p style="margin: 5px 0; font-size: 16px; color: #888;'>${item.get('Price__c', '0.00')}</p>
124
+ <p style="margin: 10px 0; font-size: 14px; color: #555;'>{item.get('Description__c', 'No description available.')}</p>
125
  </div>
126
  </div>
127
  """
128
  html_content += '</div>'
129
  html_content += '</div>'
130
+
131
+ # Check if no items were matched
132
+ if not any(filtered_data.values()):
133
+ return "<p style='text-align: center;'>No items match your filter. Please try a different preference.</p>"
134
+
135
+ return html_content
136
 
137
  # Gradio App
138
  with gr.Blocks() as app:
 
195
  login_redirect.click(lambda: (gr.update(visible=False), gr.update(visible=True)), None, [signup_page, login_page])
196
  preferences.change(handle_menu, [preferences], menu_output)
197
 
198
+ app.launch