|
import gradio as gr |
|
from simple_salesforce import Salesforce |
|
|
|
|
|
sf = Salesforce(username='[email protected]', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q') |
|
|
|
|
|
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 |
|
|
|
|
|
cart_items = [] |
|
|
|
|
|
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 |
|
|
|
|
|
def view_cart(): |
|
cart_html = "" |
|
total_items = 0 |
|
total_price = 0 |
|
for item in cart_items: |
|
cart_html += f"<p>{item['name']} - ₹{item['price']} x {item['quantity']}</p>" |
|
total_items += item["quantity"] |
|
total_price += item["price"] * item["quantity"] |
|
cart_html += f"<h3>Total: ₹{total_price} ({total_items} items)</h3>" |
|
return cart_html |
|
|
|
|
|
def generate_menu_page(menu_items): |
|
menu_html = "" |
|
for item in menu_items: |
|
menu_html += f""" |
|
<div style="display: flex; align-items: center; margin-bottom: 20px;"> |
|
<img src="{item['Image1__c']}" style="width: 100px; height: 100px; margin-right: 20px;"> |
|
<div> |
|
<h4>{item['Name']}</h4> |
|
<p>₹{item['Price__c']}</p> |
|
<button onclick="add_to_cart('{item['Id']}', '{item['Name']}', {item['Price__c']})">Add</button> |
|
</div> |
|
</div> |
|
""" |
|
return menu_html |
|
|
|
|
|
menu_items = fetch_menu_items() |
|
menu_html = generate_menu_page(menu_items) |
|
|
|
|
|
def menu_interface(): |
|
return menu_html, gr.update(visible=False) |
|
|
|
def cart_interface(): |
|
return view_cart(), gr.update(visible=True) |
|
|
|
|
|
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]) |
|
|
|
|
|
demo.launch() |