import gradio as gr from simple_salesforce import Salesforce # Salesforce Connection sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q') # Initialize cart cart = {} # Fetch menu items from Salesforce def fetch_menu_items(): query = "SELECT Id, Name, Price__c, Description__c, Image1__c FROM Menu_Item__c" menu_items = sf.query(query)["records"] return menu_items # Generate menu HTML with add-to-cart functionality def generate_menu_html(menu_items): html = "" for item in menu_items: html += f"""
{item.get('Description__c', '')}
₹{item['Price__c']}
Total: ₹{total_price}
" return cart_html # Place order and sync with Salesforce def place_order(): # Create Order in Salesforce order = sf.Order.create({ "Status": "Draft", "TotalAmount": sum(details["price"] * details["quantity"] for details in cart.values()) }) order_id = order["id"] # Add Order Items for item_id, details in cart.items(): sf.OrderItem.create({ "OrderId": order_id, "Product2Id": item_id, "UnitPrice": details["price"], "Quantity": details["quantity"] }) # Clear the cart cart.clear() return "Order placed successfully!" # Set up Gradio interface menu_items = fetch_menu_items() menu_html = generate_menu_html(menu_items) with gr.Blocks() as demo: with gr.Row(): gr.Markdown("# Welcome to Biryani Hub") with gr.Row(): menu_display = gr.HTML(value=menu_html) with gr.Row(): cart_display = gr.HTML(value=view_cart()) place_order_button = gr.Button("Place Order") menu_display.change(update_cart, inputs=["item_id", "quantity"], outputs=cart_display) place_order_button.click(place_order, inputs=[], outputs=cart_display) # Launch the app demo.launch()