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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -20
app.py CHANGED
@@ -5,7 +5,6 @@ from simple_salesforce import Salesforce
5
  # Salesforce Connection
6
  sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
7
 
8
-
9
  # Function to Hash Password
10
  def hash_password(password):
11
  return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
@@ -64,7 +63,7 @@ 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, Veg_NonVeg__c FROM Menu_Item__c"
68
  result = sf.query(query)
69
  return result['records']
70
  except Exception as e:
@@ -73,28 +72,33 @@ def load_menu_from_salesforce():
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
 
@@ -102,6 +106,10 @@ def filter_menu(preferences):
102
  with gr.Blocks() as app:
103
  login_status = gr.State(value=False)
104
 
 
 
 
 
105
  # Login Page
106
  with gr.Row(visible=True) as login_page:
107
  with gr.Column():
@@ -125,10 +133,14 @@ with gr.Blocks() as app:
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
133
  def handle_login(email, password):
134
  status, user = login(email, password)
 
5
  # Salesforce Connection
6
  sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
7
 
 
8
  # Function to Hash Password
9
  def hash_password(password):
10
  return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
 
63
  # Function to load menu items from Salesforce
64
  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:
 
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
 
 
106
  with gr.Blocks() as app:
107
  login_status = gr.State(value=False)
108
 
109
+ # Header
110
+ with gr.Row():
111
+ gr.HTML("<h1 style='text-align: center; color: #222;'>Welcome to Biryani Hub</h1>")
112
+
113
  # Login Page
114
  with gr.Row(visible=True) as login_page:
115
  with gr.Column():
 
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
 
140
+ # Footer
141
+ with gr.Row():
142
+ gr.HTML("<footer style='text-align: center; color: #666; padding: 20px; background-color: #f9f9f9;'>Thank you! Welcome again!</footer>")
143
+
144
  # Functions for page transitions and operations
145
  def handle_login(email, password):
146
  status, user = login(email, password)