Update app.py
Browse files
app.py
CHANGED
@@ -5,50 +5,55 @@ from simple_salesforce import Salesforce
|
|
5 |
sf = Salesforce(username='[email protected]', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
|
6 |
|
7 |
# Fetch menu items from Salesforce
|
8 |
-
def
|
9 |
-
query = "SELECT Id, Name, Price__c, Description__c, Image1__c,
|
10 |
-
|
11 |
-
return
|
12 |
|
13 |
# Fetch add-ons from Salesforce
|
14 |
def fetch_add_ons():
|
15 |
-
query = "SELECT
|
16 |
-
|
17 |
-
return
|
18 |
|
19 |
-
# Generate
|
20 |
-
def generate_menu_html(menu_items, add_ons
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
<
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
</div>
|
41 |
-
"""
|
42 |
html += "</div>"
|
43 |
return html
|
44 |
|
45 |
# JavaScript for popup functionality
|
46 |
popup_script = """
|
47 |
<script>
|
48 |
-
function openPopup(name, price, image, addOnsHtml) {
|
49 |
const popup = document.getElementById('popup');
|
50 |
popup.style.display = 'block';
|
51 |
-
|
|
|
|
|
|
|
52 |
document.getElementById('popup-price').innerText = `$${price}`;
|
53 |
document.getElementById('popup-image').src = image;
|
54 |
document.getElementById('popup-addons').innerHTML = addOnsHtml;
|
@@ -60,30 +65,31 @@ popup_script = """
|
|
60 |
</script>
|
61 |
"""
|
62 |
|
63 |
-
# Gradio
|
|
|
|
|
|
|
|
|
64 |
with gr.Blocks() as app:
|
65 |
with gr.Row():
|
66 |
-
gr.
|
67 |
-
|
68 |
-
preference = gr.Radio(label="Filter Preference", choices=["All", "Veg", "Non-Veg"], value="All")
|
69 |
-
menu_html = gr.HTML()
|
70 |
|
71 |
with gr.Row():
|
72 |
-
gr.HTML(""
|
73 |
-
<div id='popup' style='display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.2);'>
|
74 |
-
<img id='popup-image' src='' alt='' style='width: 100%; height: 150px; object-fit: cover; border-radius: 8px;'>
|
75 |
-
<h2 id='popup-name'></h2>
|
76 |
-
<p id='popup-price'></p>
|
77 |
-
<div id='popup-addons'></div>
|
78 |
-
<button onclick='closePopup()'>Close</button>
|
79 |
-
</div>
|
80 |
-
""" + popup_script)
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
add_ons = fetch_add_ons()
|
85 |
-
return generate_menu_html(menu_items, add_ons, preference)
|
86 |
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
app.launch()
|
|
|
5 |
sf = Salesforce(username='[email protected]', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
|
6 |
|
7 |
# Fetch menu items from Salesforce
|
8 |
+
def fetch_menu_items():
|
9 |
+
query = "SELECT Id, Name, Price__c, Description__c, Image1__c, Section__c, Veg_NonVeg__c FROM Menu_Item__c"
|
10 |
+
results = sf.query(query)['records']
|
11 |
+
return results
|
12 |
|
13 |
# Fetch add-ons from Salesforce
|
14 |
def fetch_add_ons():
|
15 |
+
query = "SELECT Name, Price__c, Menu_Item__c FROM Add_Ons__c"
|
16 |
+
results = sf.query(query)['records']
|
17 |
+
return results
|
18 |
|
19 |
+
# Generate menu HTML
|
20 |
+
def generate_menu_html(menu_items, add_ons):
|
21 |
+
add_ons_by_item = {}
|
22 |
+
for add_on in add_ons:
|
23 |
+
item_id = add_on['Menu_Item__c']
|
24 |
+
if item_id not in add_ons_by_item:
|
25 |
+
add_ons_by_item[item_id] = []
|
26 |
+
add_ons_by_item[item_id].append(f"{add_on['Name']} (+${add_on['Price__c']})")
|
27 |
|
28 |
+
html = ""
|
29 |
+
sections = {item['Section__c'] for item in menu_items}
|
30 |
+
for section in sections:
|
31 |
+
html += f"<h2>{section}</h2><div style='display: flex; flex-wrap: wrap;'>"
|
32 |
+
for item in [i for i in menu_items if i['Section__c'] == section]:
|
33 |
+
add_ons_list = add_ons_by_item.get(item['Id'], [])
|
34 |
+
add_ons_html = "<br>".join(add_ons_list)
|
35 |
+
html += f"""
|
36 |
+
<div style='width: 250px; margin: 10px; border: 1px solid #ccc; border-radius: 8px; padding: 10px;'>
|
37 |
+
<img src='{item['Image1__c']}' alt='{item['Name']}' style='width: 100%; height: 150px; object-fit: cover;'>
|
38 |
+
<h3>{item['Name']}</h3>
|
39 |
+
<p>{item['Description__c']}</p>
|
40 |
+
<p>Price: ${item['Price__c']}</p>
|
41 |
+
<button onclick="openPopup('{item['Id']}', '{item['Name']}', '{item['Price__c']}', '{item['Image1__c']}', `{add_ons_html}`)">Customize & Add</button>
|
42 |
+
</div>
|
43 |
+
"""
|
|
|
|
|
44 |
html += "</div>"
|
45 |
return html
|
46 |
|
47 |
# JavaScript for popup functionality
|
48 |
popup_script = """
|
49 |
<script>
|
50 |
+
function openPopup(id, name, price, image, addOnsHtml) {
|
51 |
const popup = document.getElementById('popup');
|
52 |
popup.style.display = 'block';
|
53 |
+
popup.style.width = '400px';
|
54 |
+
popup.style.height = '600px';
|
55 |
+
popup.style.margin = 'auto';
|
56 |
+
document.getElementById('popup-title').innerText = name;
|
57 |
document.getElementById('popup-price').innerText = `$${price}`;
|
58 |
document.getElementById('popup-image').src = image;
|
59 |
document.getElementById('popup-addons').innerHTML = addOnsHtml;
|
|
|
65 |
</script>
|
66 |
"""
|
67 |
|
68 |
+
# Gradio App
|
69 |
+
menu_items = fetch_menu_items()
|
70 |
+
add_ons = fetch_add_ons()
|
71 |
+
menu_html = generate_menu_html(menu_items, add_ons)
|
72 |
+
|
73 |
with gr.Blocks() as app:
|
74 |
with gr.Row():
|
75 |
+
gr.HTML("<h1 style='text-align: center;'>Welcome to Biryani Hub</h1>")
|
|
|
|
|
|
|
76 |
|
77 |
with gr.Row():
|
78 |
+
gr.HTML("<div>Filter Preference: <input type='radio' name='filter' value='All' checked> All <input type='radio' name='filter' value='Veg'> Veg <input type='radio' name='filter' value='Non-Veg'> Non-Veg</div>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
+
with gr.Row():
|
81 |
+
gr.HTML(menu_html)
|
|
|
|
|
82 |
|
83 |
+
# Popup
|
84 |
+
gr.HTML("""
|
85 |
+
<div id='popup' style='display: none; position: fixed; top: 20%; left: 50%; transform: translate(-50%, -20%); background: white; border: 1px solid #ccc; border-radius: 8px; padding: 20px; z-index: 1000;'>
|
86 |
+
<img id='popup-image' src='' style='width: 100%; height: 200px; object-fit: cover;'>
|
87 |
+
<h2 id='popup-title'></h2>
|
88 |
+
<p id='popup-price'></p>
|
89 |
+
<textarea id='popup-instructions' placeholder='Special Instructions' style='width: 100%; height: 80px;'></textarea>
|
90 |
+
<div id='popup-addons'></div>
|
91 |
+
<button onclick='closePopup()'>Close</button>
|
92 |
+
</div>
|
93 |
+
""" + popup_script)
|
94 |
|
95 |
app.launch()
|