Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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,
|
| 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
|
| 75 |
menu_data = load_menu_from_salesforce()
|
| 76 |
filtered_data = []
|
| 77 |
|
| 78 |
for item in menu_data:
|
| 79 |
-
if
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 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 |
-
|
|
|
|
| 92 |
for item in filtered_data:
|
| 93 |
html_content += f"""
|
| 94 |
-
<div style="
|
| 95 |
-
<
|
| 96 |
-
|
|
|
|
| 97 |
<p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price__c']}</p>
|
| 98 |
-
<p style="margin:
|
| 99 |
-
|
| 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 |
-
|
|
|
|
| 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 |
-
|
| 135 |
-
|
|
|
|
| 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(
|
| 150 |
-
return
|
| 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 |
-
|
| 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()
|