File size: 2,676 Bytes
f65f970
 
 
 
8fb83ea
 
f65f970
86b569b
 
f65f970
86b569b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f65f970
86b569b
48267cf
 
f65f970
 
c8ff656
f65f970
 
c8ff656
 
48267cf
86b569b
 
 
 
 
 
 
 
 
f65f970
86b569b
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
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 data from Salesforce
def fetch_menu_from_salesforce(preference):
    try:
        # Querying the Salesforce Menu_Item__c object
        query = "SELECT Name, Description__c, Price__c, Image1__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c"
        menu_items = sf.query(query)["records"]
        
        # Filter menu based on preference
        filtered_menu = [
            item for item in menu_items 
            if preference == "All" or item["Veg_NonVeg__c"] == preference
        ]

        # Group items by section
        sections = {}
        for item in filtered_menu:
            section = item["Section__c"]
            if section not in sections:
                sections[section] = []
            sections[section].append(item)

        # Generate HTML for menu display
        html = ""
        for section, items in sections.items():
            html += f"<h2 style='text-align: left;'>{section}</h2>"
            for item in items:
                html += f"""
                <div style="display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 10px; margin-bottom: 10px;">
                    <div style="flex: 1;">
                        <h3 style="margin: 0;">{item['Name']}</h3>
                        <p style="margin: 5px 0;">{item.get('Description__c', 'No description available')}</p>
                        <p style="margin: 5px 0;"><b>Price:</b> ${item['Price__c']}</p>
                    </div>
                    <div>
                        <img src="{item.get('Image1__c', '')}" alt="{item['Name']}" style="width: 100px; height: 100px; border-radius: 8px; margin-left: 10px;">
                    </div>
                </div>
                """
        return html if html else "<p>No menu items available.</p>"
    except Exception as e:
        return f"<p>Error fetching menu: {str(e)}</p>"

# Gradio App
with gr.Blocks() as app:
    with gr.Row():
        gr.HTML("<h1 style='text-align: center;'>Welcome to Biryani Hub</h1>")

    with gr.Row():
        preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
        menu_display = gr.HTML()

    # Update the menu display based on preference
    preference.change(
        lambda pref: fetch_menu_from_salesforce(pref),
        inputs=preference,
        outputs=menu_display
    )

    # Initial Load
    menu_display.value = fetch_menu_from_salesforce("All")

app.launch()