import bcrypt import gradio as gr from datetime import datetime from simple_salesforce import Salesforce # Salesforce Connection sf = Salesforce( username='your_username', password='your_password', security_token='your_security_token' ) # Sample Menu Data in JSON Format sample_menu = [ { "name": "Samosa", "price": 9.0, "description": "Crispy fried pastry filled with spiced potatoes and peas.", "image": "https://via.placeholder.com/200x200", # Replace with your image URLs "veg_nonveg": "Veg", "section": "Starters", }, { "name": "Chicken Biryani", "price": 15.0, "description": "Flavorful rice dish cooked with chicken and spices.", "image": "https://via.placeholder.com/200x200", "veg_nonveg": "Non-Veg", "section": "Biryani", }, { "name": "Paneer Butter Masala", "price": 12.0, "description": "Paneer cubes cooked in a creamy tomato-based gravy.", "image": "https://via.placeholder.com/200x200", "veg_nonveg": "Veg", "section": "Curries", } ] # Sample Add-Ons sample_add_ons = [ {"name": "Extra Cheese", "price": 2.0}, {"name": "Extra Spicy", "price": 1.5}, {"name": "No Onions", "price": 0.5}, ] # Function to Save Cart Summary to Salesforce def save_cart_to_salesforce(cart, total_cost): try: if not cart or total_cost <= 0: return "Cart is empty or invalid total cost." # Create Order Record order_record = { 'Name': f"Order {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}", 'Total_Cost__c': total_cost, 'Order_Date__c': datetime.now().isoformat(), } order_result = sf.Order__c.create(order_record) order_id = order_result['id'] # Create Order Items for item in cart: extras = ", ".join(extra['name'] for extra in item.get('extras', [])) order_item_record = { 'Name': item['name'], 'Order__c': order_id, 'Quantity__c': item['quantity'], 'Price__c': item['price'], 'Extras__c': extras, 'Instructions__c': item.get('instructions', ''), 'Total_Cost__c': item['totalCost'], } sf.Order_Item__c.create(order_item_record) return "Order saved successfully!" except Exception as e: return f"Error saving order: {str(e)}" # Function to Load Menu Items def load_menu(preference): filtered_menu = [ item for item in sample_menu if preference == "All" or item["veg_nonveg"] == preference ] html = "" sections = {item["section"] for item in filtered_menu} for section in sections: html += f"

{section}

" for item in filtered_menu: if item["section"] == section: html += f"""

{item['name']}

{item['description']}

Price: ${item['price']}

""" return html # Function to Add Items to Cart def add_to_cart(name, price, quantity, extras, instructions): total_cost = (price * quantity) + sum(extra["price"] for extra in extras) cart_item = { "name": name, "price": price, "quantity": quantity, "extras": extras, "instructions": instructions, "totalCost": total_cost, } return cart_item, total_cost # Gradio Interface with gr.Blocks() as app: with gr.Row(): gr.HTML("

Welcome to Biryani Hub

") preference = gr.Radio(["All", "Veg", "Non-Veg"], value="All", label="Filter Preference") menu_display = gr.HTML() with gr.Row(): cart = gr.JSON(label="Cart Items") total_cost = gr.Textbox(label="Total Cost") add_item_button = gr.Button("Add to Cart") with gr.Row(): checkout_button = gr.Button("Checkout") checkout_status = gr.Textbox(label="Status") # Load Menu on Filter Change preference.change( lambda pref: load_menu(pref), inputs=preference, outputs=menu_display ) # Add Item to Cart add_item_button.click( lambda name, price, quantity, extras, instructions: add_to_cart( name, price, quantity, extras, instructions ), inputs=["name", "price", "quantity", "extras", "instructions"], outputs=[cart, total_cost], ) # Checkout and Save to Salesforce checkout_button.click( lambda cart_items, total: save_cart_to_salesforce(cart_items, total), inputs=[cart, total_cost], outputs=checkout_status, ) app.launch()