File size: 3,965 Bytes
f65f970
 
 
 
8fb83ea
 
9b01074
c0caa98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b01074
c0caa98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b01074
c0caa98
 
 
9b01074
 
 
c0caa98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b01074
c0caa98
 
 
 
 
9b01074
c0caa98
 
 
9b01074
 
 
f65f970
c0caa98
 
9b01074
c0caa98
 
 
 
9b01074
c0caa98
 
 
 
9b01074
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import gradio as gr
from simple_salesforce import Salesforce

# Salesforce Connection
sf = Salesforce(username='[email protected]', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')


# Function to fetch menu items from Salesforce
def load_menu_from_salesforce():
    try:
        query = "SELECT Id, Name, Price__c, Description__c, Image1__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c"
        result = sf.query(query)
        return result['records']
    except Exception as e:
        print(f"Error fetching menu items: {e}")
        return []

# Function to fetch add-ons from Salesforce
def load_add_ons_from_salesforce():
    try:
        query = "SELECT Name, Price__c, Menu_Item__c FROM Add_Ons__c"
        result = sf.query(query)
        return result['records']
    except Exception as e:
        print(f"Error fetching add-ons: {e}")
        return []

# Function to generate HTML for menu items
def generate_menu_html(menu_items, add_ons):
    add_ons_by_item = {}
    for add_on in add_ons:
        menu_item_id = add_on.get('Menu_Item__c', None)
        if menu_item_id:
            if menu_item_id not in add_ons_by_item:
                add_ons_by_item[menu_item_id] = []
            add_ons_by_item[menu_item_id].append({
                "name": add_on["Name"],
                "price": add_on["Price__c"]
            })

    html = ""
    current_section = None
    for item in menu_items:
        if item["Section__c"] != current_section:
            if current_section is not None:
                html += "</div>"
            current_section = item["Section__c"]
            html += f"<h2>{current_section}</h2><div class='menu-section'>"

        add_ons_list = add_ons_by_item.get(item['Id'], [])
        html += f"""
        <div class="menu-item">
            <img src="{item.get('Image1__c', '')}" alt="{item['Name']}" style="width: 150px; height: 150px; object-fit: cover;">
            <h3>{item['Name']}</h3>
            <p>{item.get('Description__c', 'No description available.')}</p>
            <p>Price: ${item['Price__c']}</p>
            <button onclick="openPopup('{item['Name']}', '{item['Price__c']}', {add_ons_list})">Customize & Add</button>
        </div>
        """

    if current_section is not None:
        html += "</div>"
    return html

# JavaScript for popup functionality
popup_script = """
<script>
    function openPopup(name, price, addOns) {
        const popup = document.getElementById('popup');
        const addOnsContainer = document.getElementById('add-ons-container');
        
        popup.style.display = 'block';
        document.getElementById('popup-item-name').innerText = name;
        document.getElementById('popup-item-price').innerText = `Price: $${price}`;

        addOnsContainer.innerHTML = "";
        addOns.forEach(addOn => {
            const addOnElement = document.createElement('div');
            addOnElement.innerHTML = `${addOn.name} (+$${addOn.price}) <input type='checkbox' value='${addOn.name}'>`;
            addOnsContainer.appendChild(addOnElement);
        });
    }

    function closePopup() {
        document.getElementById('popup').style.display = 'none';
    }
</script>
"""

# Load data from Salesforce
menu_items = load_menu_from_salesforce()
add_ons = load_add_ons_from_salesforce()
menu_html = generate_menu_html(menu_items, add_ons)

# Gradio app
with gr.Blocks() as app:
    with gr.Row():
        gr.HTML("<h1>Welcome to Biryani Hub</h1>")

    with gr.Row():
        gr.HTML(menu_html)

    gr.HTML(popup_script)
    gr.HTML("""
    <div id="popup" style="display: none; position: fixed; top: 20%; left: 30%; width: 40%; background: white; padding: 20px; border: 1px solid #ccc; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);">
        <h2 id="popup-item-name"></h2>
        <p id="popup-item-price"></p>
        <div id="add-ons-container"></div>
        <button onclick="closePopup()">Close</button>
    </div>
    """)

app.launch()