import gradio as gr from simple_salesforce import Salesforce # Salesforce Connection sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q') # Fetch menu items from Salesforce def fetch_menu_items(): query = "SELECT Id, Name, Price__c, Description__c, Image1__c FROM Menu_Item__c" records = sf.query(query)["records"] return records # Fetch cart items (local data structure for demonstration) cart_items = [] # Add item to cart def add_to_cart(item_id, name, price): for item in cart_items: if item["id"] == item_id: item["quantity"] += 1 return f"{name} added to the cart!", cart_items cart_items.append({"id": item_id, "name": name, "price": price, "quantity": 1}) return f"{name} added to the cart!", cart_items # Display cart items def view_cart(): cart_html = "" total_items = 0 total_price = 0 for item in cart_items: cart_html += f"

{item['name']} - ₹{item['price']} x {item['quantity']}

" total_items += item["quantity"] total_price += item["price"] * item["quantity"] cart_html += f"

Total: ₹{total_price} ({total_items} items)

" return cart_html # Generate menu page HTML def generate_menu_page(menu_items): menu_html = "" for item in menu_items: menu_html += f"""

{item['Name']}

₹{item['Price__c']}

""" return menu_html # Fetch menu items for display menu_items = fetch_menu_items() menu_html = generate_menu_page(menu_items) # Gradio interface for menu page def menu_interface(): return menu_html, gr.update(visible=False) def cart_interface(): return view_cart(), gr.update(visible=True) # Gradio setup with gr.Blocks() as demo: with gr.Row(): gr.Markdown("# Welcome to Biryani Hub") with gr.Row(): menu_display = gr.HTML(value=menu_html, interactive=False) cart_button = gr.Button("View Cart", visible=True) cart_display = gr.HTML(value=view_cart(), visible=False) cart_button.click(cart_interface, inputs=[], outputs=[menu_display, cart_display]) # Launch the app demo.launch()