File size: 2,948 Bytes
f65f970
 
 
 
8fb83ea
 
77b50a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec96e6b
77b50a3
ec96e6b
 
77b50a3
 
 
 
 
 
 
 
 
ec96e6b
 
c0caa98
 
34938c5
f65f970
77b50a3
ec96e6b
c0caa98
ec96e6b
9b01074
c0caa98
77b50a3
ec96e6b
77b50a3
ec96e6b
77b50a3
 
9b01074
ec96e6b
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
import gradio as gr
from simple_salesforce import Salesforce

# Salesforce Connection
sf = Salesforce(username='[email protected]', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')

# Sample menu items from Salesforce
def fetch_menu_items():
    try:
        query = "SELECT Id, Name, Price__c, Image1__c, Description__c, Section__c FROM Menu_Item__c"
        menu_items = sf.query(query)['records']
        return menu_items
    except Exception as e:
        print(f"Error fetching menu items: {e}")
        return []

# Cart management
cart = {}

def update_cart(item_id, name, price, quantity):
    if item_id in cart:
        cart[item_id]['quantity'] += quantity
        if cart[item_id]['quantity'] <= 0:
            del cart[item_id]
    else:
        if quantity > 0:
            cart[item_id] = {'name': name, 'price': price, 'quantity': quantity}
    return cart_summary()

def cart_summary():
    total_items = sum(item['quantity'] for item in cart.values())
    total_cost = sum(item['quantity'] * item['price'] for item in cart.values())
    return f"{total_items} items | Total: ₹{total_cost:.2f}"

# Cart Page
def cart_page():
    items_html = "".join(
        f"""
        <div>
            <h4>{item['name']} (₹{item['price']})</h4>
            <p>Quantity: {item['quantity']}</p>
        </div>
        """
        for item in cart.values()
    )
    total_cost = sum(item['quantity'] * item['price'] for item in cart.values())
    return f"""
    <h3>Your Cart</h3>
    <div>{items_html}</div>
    <h4>Total Cost: ₹{total_cost:.2f}</h4>
    <button onclick="alert('Checkout functionality to be implemented')">Proceed to Checkout</button>
    """

# Generate HTML for Menu Items
def generate_menu_html(menu_items):
    html = ""
    for item in menu_items:
        html += f"""
        <div style="border: 1px solid #ddd; padding: 10px; margin: 10px; border-radius: 8px; display: flex; align-items: center;">
            <img src="{item['Image1__c']}" alt="{item['Name']}" style="width: 100px; height: 100px; margin-right: 10px;">
            <div>
                <h4>{item['Name']}</h4>
                <p>₹{item['Price__c']}</p>
                <button onclick="updateCart('{item['Id']}', '{item['Name']}', {item['Price__c']}, -1)">-</button>
                <span>0</span>
                <button onclick="updateCart('{item['Id']}', '{item['Name']}', {item['Price__c']}, 1)">+</button>
            </div>
        </div>
        """
    return html

# Gradio App
with gr.Blocks() as app:
    menu_items = fetch_menu_items()

    with gr.Row():
        gr.HTML("<h1>Welcome to Biryani Hub</h1>")

    with gr.Row():
        gr.HTML(generate_menu_html(menu_items))

    # Floating Cart Button
    with gr.Row():
        cart_display = gr.HTML("0 items | Total: ₹0.00", elem_id="cart-summary")
        gr.Button("View Cart", elem_id="view-cart-btn").click(cart_page, [], cart_display)

app.launch()