|
import gradio as gr |
|
from simple_salesforce import Salesforce |
|
|
|
|
|
sf = Salesforce(username='[email protected]', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q') |
|
|
|
|
|
|
|
def fetch_menu_from_salesforce(preference): |
|
try: |
|
|
|
query = "SELECT Name, Description__c, Price__c, Image1__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c" |
|
menu_items = sf.query(query)["records"] |
|
|
|
|
|
filtered_menu = [ |
|
item for item in menu_items |
|
if preference == "All" or item["Veg_NonVeg__c"] == preference |
|
] |
|
|
|
|
|
sections = {} |
|
for item in filtered_menu: |
|
section = item["Section__c"] |
|
if section not in sections: |
|
sections[section] = [] |
|
sections[section].append(item) |
|
|
|
|
|
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>" |
|
|
|
|
|
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( |
|
lambda pref: fetch_menu_from_salesforce(pref), |
|
inputs=preference, |
|
outputs=menu_display |
|
) |
|
|
|
|
|
menu_display.value = fetch_menu_from_salesforce("All") |
|
|
|
app.launch() |
|
|