|
import gradio as gr |
|
from simple_salesforce import Salesforce |
|
|
|
|
|
sf = Salesforce(username='[email protected]', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q') |
|
|
|
|
|
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'] |
|
|
|
|
|
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)}" |
|
|
|
|
|
def display_menu(preference): |
|
menu = fetch_menu() |
|
if isinstance(menu, str): |
|
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 |
|
|
|
|
|
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() |
|
|