File size: 2,441 Bytes
f65f970
 
 
 
8fb83ea
 
ccac902
 
f65f970
ccac902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f65f970
ccac902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48267cf
 
f65f970
 
c8ff656
f65f970
 
c8ff656
 
48267cf
ccac902
f65f970
ccac902
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
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 fetch_menu():
    try:
        query = "SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c"
        menu_items = sf.query(query)['records']

        # Format the menu items into a dictionary grouped by section
        formatted_menu = {}
        for item in menu_items:
            section = item['Section__c'] or "Miscellaneous"
            if section not in formatted_menu:
                formatted_menu[section] = []

            formatted_menu[section].append({
                "name": item['Name'],
                "price": item['Price__c'],
                "description": item['Description__c'],
                "image1": item['Image1__c'],
                "image2": item['Image2__c'],
                "veg_nonveg": item['Veg_NonVeg__c']
            })

        return formatted_menu
    except Exception as e:
        return f"Error fetching menu from Salesforce: {str(e)}"

# Function to display menu based on user preference
def display_menu(preference):
    menu = fetch_menu()
    if isinstance(menu, str):  # Error handling
        return menu

    html_output = ""
    for section, items in menu.items():
        html_output += f"<h2>{section}</h2>"
        for item in items:
            if preference == "All" or item['veg_nonveg'] == preference:
                html_output += f"<div style='border: 1px solid #ddd; padding: 10px; margin-bottom: 10px;'>"
                html_output += f"<h3>{item['name']}</h3>"
                html_output += f"<p>{item['description']}</p>"
                html_output += f"<p>Price: ${item['price']}</p>"
                html_output += f"<img src='{item['image1']}' alt='{item['name']}' style='width: 100px; height: 100px;'>"
                html_output += f"</div>"
    return html_output

# 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()

    preference.change(display_menu, inputs=preference, outputs=menu_display)

    app.launch()