File size: 3,517 Bytes
f65f970 8fb83ea c38ed3b b316f59 77b50a3 c38ed3b 1ff1c4f c38ed3b 77b50a3 b316f59 c38ed3b ec96e6b b316f59 c38ed3b 77b50a3 c38ed3b b316f59 77b50a3 c38ed3b 77b50a3 ec96e6b c38ed3b b316f59 c0caa98 c38ed3b b316f59 c38ed3b b316f59 c38ed3b b316f59 c38ed3b ec96e6b c38ed3b b316f59 c38ed3b b316f59 c38ed3b b316f59 c38ed3b b316f59 c38ed3b b316f59 1ff1c4f c38ed3b b316f59 c38ed3b b316f59 9b01074 1ff1c4f c38ed3b b316f59 c38ed3b ec96e6b c38ed3b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
import gradio as gr
from simple_salesforce import Salesforce
# Salesforce Connection
sf = Salesforce(username='[email protected]', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
# Local cart to manage food items
cart = {}
def fetch_menu_items():
"""Fetch menu items from Salesforce."""
query = "SELECT Id, Name, Price__c, Description__c, Image1__c FROM Menu_Item__c"
result = sf.query(query)
return result['records']
def generate_menu_html(menu_items):
"""Generate HTML for menu items."""
html = "<div>"
for item in menu_items:
html += f"""
<div style='display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;'>
<div>
<img src='{item['Image1__c']}' alt='{item['Name']}' style='width: 100px; height: 100px; object-fit: cover; margin-right: 10px;'>
<h3>{item['Name']}</h3>
<p>₹{item['Price__c']}</p>
<button onclick=\"addToCart('{item['Id']}', '{item['Name']}', {item['Price__c']})\">Add to Cart</button>
</div>
</div>
"""
html += "</div>"
return html
def add_to_cart(item_id, name, price):
"""Add an item to the cart."""
if item_id in cart:
cart[item_id]['quantity'] += 1
else:
cart[item_id] = {
'name': name,
'price': price,
'quantity': 1
}
return update_cart_display()
def update_cart_display():
"""Update the cart display."""
if not cart:
return "Cart is empty."
cart_html = "<div>"
total_price = 0
for item_id, details in cart.items():
total_price += details['price'] * details['quantity']
cart_html += f"""
<div style='display: flex; justify-content: space-between; align-items: center;'>
<span>{details['name']} (x{details['quantity']})</span>
<span>₹{details['price'] * details['quantity']}</span>
</div>
"""
cart_html += f"<div style='margin-top: 10px;'>Total: ₹{total_price}</div>"
cart_html += "</div>"
return cart_html
def proceed_to_order():
"""Place the order in Salesforce."""
if not cart:
return "Cart is empty. Cannot place an order."
# Create an Order record
order = sf.Order.create({
'Status': 'Draft',
'EffectiveDate': '2023-01-01', # Replace with dynamic date if needed
'AccountId': 'your_account_id' # Replace with actual Account ID
})
# Add Order Items
for item_id, details in cart.items():
sf.OrderItem.create({
'OrderId': order['id'],
'Quantity': details['quantity'],
'UnitPrice': details['price'],
'PricebookEntryId': 'your_pricebook_entry_id' # Replace accordingly
})
# Clear the cart after placing the order
cart.clear()
return "Order placed successfully!"
# Fetch menu items and generate HTML
menu_items = fetch_menu_items()
menu_html = generate_menu_html(menu_items)
with gr.Blocks() as demo:
gr.Markdown("# Welcome to Biryani Hub")
with gr.Row():
menu_display = gr.HTML(value=menu_html)
cart_display = gr.HTML(value="Cart is empty.")
with gr.Row():
add_button = gr.Button("Add to Cart")
proceed_button = gr.Button("Proceed to Order")
add_button.click(add_to_cart, inputs=[], outputs=cart_display)
proceed_button.click(proceed_to_order, inputs=[], outputs=cart_display)
demo.launch()
|