Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import gradio as gr
|
|
| 3 |
from simple_salesforce import Salesforce
|
| 4 |
|
| 5 |
# Salesforce Connection
|
| 6 |
-
sf = Salesforce(username='
|
| 7 |
|
| 8 |
# Hash Password
|
| 9 |
def hash_password(password):
|
|
@@ -59,14 +59,10 @@ def load_menu_from_salesforce():
|
|
| 59 |
|
| 60 |
# Filter Menu Items
|
| 61 |
def filter_menu(preference):
|
| 62 |
-
"""
|
| 63 |
-
Filters the menu items based on the given preference.
|
| 64 |
-
Normalizes Veg_NonVeg__c values to avoid mismatch issues.
|
| 65 |
-
"""
|
| 66 |
menu_data = load_menu_from_salesforce()
|
| 67 |
filtered_data = []
|
| 68 |
for item in menu_data:
|
| 69 |
-
veg_nonveg = item.get("Veg_NonVeg__c", "").strip().lower()
|
| 70 |
if preference == "All":
|
| 71 |
filtered_data.append(item)
|
| 72 |
elif preference == "Veg" and veg_nonveg in ["veg", "vegetarian"]:
|
|
@@ -75,23 +71,20 @@ def filter_menu(preference):
|
|
| 75 |
filtered_data.append(item)
|
| 76 |
return filtered_data
|
| 77 |
|
| 78 |
-
# Render Menu as HTML
|
| 79 |
def render_menu_html(menu_data):
|
| 80 |
-
"""
|
| 81 |
-
Renders menu items as HTML cards in a grid layout.
|
| 82 |
-
"""
|
| 83 |
if not menu_data:
|
| 84 |
return '<div style="text-align: center; font-size: 1.2em; color: gray;">No items match your filter.</div>'
|
| 85 |
-
|
| 86 |
-
html_content = '<div style="display: flex; flex-
|
| 87 |
for item in menu_data:
|
| 88 |
html_content += f"""
|
| 89 |
-
<div
|
| 90 |
-
<img src="{item.get('Image1__c', '')}" alt="{item['Name']}"
|
| 91 |
-
<div
|
| 92 |
-
<h3
|
| 93 |
-
<p
|
| 94 |
-
<p
|
| 95 |
</div>
|
| 96 |
</div>
|
| 97 |
"""
|
|
@@ -102,15 +95,10 @@ def render_menu_html(menu_data):
|
|
| 102 |
menu_styles = """
|
| 103 |
<style>
|
| 104 |
body {
|
| 105 |
-
margin: 0;
|
| 106 |
font-family: Arial, sans-serif;
|
| 107 |
-
display: flex;
|
| 108 |
-
flex-direction: column;
|
| 109 |
-
justify-content: flex-start;
|
| 110 |
-
align-items: center;
|
| 111 |
}
|
| 112 |
.header {
|
| 113 |
-
margin
|
| 114 |
padding: 20px;
|
| 115 |
font-size: 2.5em;
|
| 116 |
font-weight: bold;
|
|
@@ -121,66 +109,14 @@ menu_styles = """
|
|
| 121 |
position: sticky;
|
| 122 |
top: 0;
|
| 123 |
}
|
| 124 |
-
.filter-container {
|
| 125 |
-
margin: 20px 0;
|
| 126 |
-
text-align: center;
|
| 127 |
-
width: 100%;
|
| 128 |
-
}
|
| 129 |
-
.menu-container {
|
| 130 |
-
display: flex;
|
| 131 |
-
flex-wrap: wrap;
|
| 132 |
-
gap: 20px;
|
| 133 |
-
justify-content: center;
|
| 134 |
-
align-items: center;
|
| 135 |
-
padding: 20px;
|
| 136 |
-
width: 100%;
|
| 137 |
-
}
|
| 138 |
-
.menu-card {
|
| 139 |
-
border: 1px solid #ddd;
|
| 140 |
-
border-radius: 10px;
|
| 141 |
-
width: 300px;
|
| 142 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 143 |
-
overflow: hidden;
|
| 144 |
-
transition: transform 0.2s, box-shadow 0.2s;
|
| 145 |
-
cursor: pointer;
|
| 146 |
-
text-align: center;
|
| 147 |
-
}
|
| 148 |
-
.menu-card:hover {
|
| 149 |
-
transform: scale(1.05);
|
| 150 |
-
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
|
| 151 |
-
}
|
| 152 |
-
.menu-image {
|
| 153 |
-
width: 100%;
|
| 154 |
-
height: 180px;
|
| 155 |
-
object-fit: cover;
|
| 156 |
-
}
|
| 157 |
-
.menu-content {
|
| 158 |
-
padding: 15px;
|
| 159 |
-
}
|
| 160 |
-
.menu-title {
|
| 161 |
-
font-size: 1.5em;
|
| 162 |
-
margin: 0;
|
| 163 |
-
}
|
| 164 |
-
.menu-price {
|
| 165 |
-
font-size: 1.2em;
|
| 166 |
-
color: green;
|
| 167 |
-
margin: 5px 0;
|
| 168 |
-
}
|
| 169 |
-
.menu-description {
|
| 170 |
-
font-size: 1em;
|
| 171 |
-
color: #555;
|
| 172 |
-
}
|
| 173 |
</style>
|
| 174 |
"""
|
| 175 |
|
| 176 |
# Gradio App
|
| 177 |
with gr.Blocks() as app:
|
| 178 |
-
gr.HTML(menu_styles)
|
| 179 |
-
|
| 180 |
-
# Header
|
| 181 |
gr.HTML('<div class="header">Welcome to Biryani Hub</div>')
|
| 182 |
|
| 183 |
-
# Login Page
|
| 184 |
with gr.Row(visible=True) as login_page:
|
| 185 |
with gr.Column():
|
| 186 |
login_email = gr.Textbox(label="Email")
|
|
@@ -189,7 +125,6 @@ with gr.Blocks() as app:
|
|
| 189 |
signup_button = gr.Button("Go to Signup")
|
| 190 |
login_output = gr.Textbox(label="Status")
|
| 191 |
|
| 192 |
-
# Signup Page
|
| 193 |
with gr.Row(visible=False) as signup_page:
|
| 194 |
with gr.Column():
|
| 195 |
signup_name = gr.Textbox(label="Name")
|
|
@@ -200,7 +135,6 @@ with gr.Blocks() as app:
|
|
| 200 |
login_redirect = gr.Button("Go to Login")
|
| 201 |
signup_output = gr.Textbox(label="Status")
|
| 202 |
|
| 203 |
-
# Menu Page
|
| 204 |
with gr.Row(visible=False) as menu_page:
|
| 205 |
preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
|
| 206 |
menu_output = gr.HTML()
|
|
|
|
| 3 |
from simple_salesforce import Salesforce
|
| 4 |
|
| 5 |
# Salesforce Connection
|
| 6 |
+
sf = Salesforce(username='YOUR_USERNAME', password='YOUR_PASSWORD', security_token='YOUR_SECURITY_TOKEN')
|
| 7 |
|
| 8 |
# Hash Password
|
| 9 |
def hash_password(password):
|
|
|
|
| 59 |
|
| 60 |
# Filter Menu Items
|
| 61 |
def filter_menu(preference):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
menu_data = load_menu_from_salesforce()
|
| 63 |
filtered_data = []
|
| 64 |
for item in menu_data:
|
| 65 |
+
veg_nonveg = item.get("Veg_NonVeg__c", "").strip().lower()
|
| 66 |
if preference == "All":
|
| 67 |
filtered_data.append(item)
|
| 68 |
elif preference == "Veg" and veg_nonveg in ["veg", "vegetarian"]:
|
|
|
|
| 71 |
filtered_data.append(item)
|
| 72 |
return filtered_data
|
| 73 |
|
| 74 |
+
# Render Menu as HTML (Row-Wise Layout)
|
| 75 |
def render_menu_html(menu_data):
|
|
|
|
|
|
|
|
|
|
| 76 |
if not menu_data:
|
| 77 |
return '<div style="text-align: center; font-size: 1.2em; color: gray;">No items match your filter.</div>'
|
| 78 |
+
|
| 79 |
+
html_content = '<div style="width: 100%; display: flex; flex-direction: column; gap: 20px; padding: 20px;">'
|
| 80 |
for item in menu_data:
|
| 81 |
html_content += f"""
|
| 82 |
+
<div style="display: flex; align-items: center; gap: 20px; border: 1px solid #ddd; border-radius: 10px; padding: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);">
|
| 83 |
+
<img src="{item.get('Image1__c', '')}" alt="{item['Name']}" style="width: 120px; height: 120px; object-fit: cover; border-radius: 8px;">
|
| 84 |
+
<div style="flex: 1;">
|
| 85 |
+
<h3 style="margin: 0; font-size: 1.5em;">{item['Name']}</h3>
|
| 86 |
+
<p style="margin: 5px 0; color: green; font-size: 1.2em;">${item['Price__c']}</p>
|
| 87 |
+
<p style="margin: 0; font-size: 1em; color: #555;">{item['Description__c']}</p>
|
| 88 |
</div>
|
| 89 |
</div>
|
| 90 |
"""
|
|
|
|
| 95 |
menu_styles = """
|
| 96 |
<style>
|
| 97 |
body {
|
|
|
|
| 98 |
font-family: Arial, sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
}
|
| 100 |
.header {
|
| 101 |
+
margin: 0;
|
| 102 |
padding: 20px;
|
| 103 |
font-size: 2.5em;
|
| 104 |
font-weight: bold;
|
|
|
|
| 109 |
position: sticky;
|
| 110 |
top: 0;
|
| 111 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
</style>
|
| 113 |
"""
|
| 114 |
|
| 115 |
# Gradio App
|
| 116 |
with gr.Blocks() as app:
|
| 117 |
+
gr.HTML(menu_styles)
|
|
|
|
|
|
|
| 118 |
gr.HTML('<div class="header">Welcome to Biryani Hub</div>')
|
| 119 |
|
|
|
|
| 120 |
with gr.Row(visible=True) as login_page:
|
| 121 |
with gr.Column():
|
| 122 |
login_email = gr.Textbox(label="Email")
|
|
|
|
| 125 |
signup_button = gr.Button("Go to Signup")
|
| 126 |
login_output = gr.Textbox(label="Status")
|
| 127 |
|
|
|
|
| 128 |
with gr.Row(visible=False) as signup_page:
|
| 129 |
with gr.Column():
|
| 130 |
signup_name = gr.Textbox(label="Name")
|
|
|
|
| 135 |
login_redirect = gr.Button("Go to Login")
|
| 136 |
signup_output = gr.Textbox(label="Status")
|
| 137 |
|
|
|
|
| 138 |
with gr.Row(visible=False) as menu_page:
|
| 139 |
preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
|
| 140 |
menu_output = gr.HTML()
|