Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Updated Cart Modal HTML
|
2 |
def create_cart_modal():
|
3 |
cart_modal_html = """
|
|
|
1 |
+
|
2 |
+
import bcrypt
|
3 |
+
import gradio as gr
|
4 |
+
from simple_salesforce import Salesforce
|
5 |
+
|
6 |
+
# Salesforce Connection
|
7 |
+
sf = Salesforce(username='[email protected]', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
|
8 |
+
|
9 |
+
# Function to Hash Password
|
10 |
+
def hash_password(password):
|
11 |
+
return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
|
12 |
+
|
13 |
+
# Function to Verify Password
|
14 |
+
def verify_password(plain_password, hashed_password):
|
15 |
+
return bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8'))
|
16 |
+
|
17 |
+
# Signup function
|
18 |
+
def signup(name, email, phone, password):
|
19 |
+
try:
|
20 |
+
email = email.strip()
|
21 |
+
query = f"SELECT Id FROM Customer_Login__c WHERE Email__c = '{email}'"
|
22 |
+
result = sf.query(query)
|
23 |
+
|
24 |
+
if len(result['records']) > 0:
|
25 |
+
return "Email already exists! Please use a different email."
|
26 |
+
|
27 |
+
hashed_password = hash_password(password)
|
28 |
+
|
29 |
+
sf.Customer_Login__c.create({
|
30 |
+
'Name': name.strip(),
|
31 |
+
'Email__c': email,
|
32 |
+
'Phone_Number__c': phone.strip(),
|
33 |
+
'Password__c': hashed_password
|
34 |
+
})
|
35 |
+
return "Signup successful! You can now login."
|
36 |
+
except Exception as e:
|
37 |
+
return f"Error during signup: {str(e)}"
|
38 |
+
|
39 |
+
# Login function
|
40 |
+
def login(email, password):
|
41 |
+
try:
|
42 |
+
email = email.strip()
|
43 |
+
query = f"SELECT Name, Password__c FROM Customer_Login__c WHERE Email__c = '{email}'"
|
44 |
+
result = sf.query(query)
|
45 |
+
|
46 |
+
if len(result['records']) == 0:
|
47 |
+
return "Invalid email or password.", None
|
48 |
+
|
49 |
+
user = result['records'][0]
|
50 |
+
stored_password = user['Password__c']
|
51 |
+
|
52 |
+
if verify_password(password.strip(), stored_password):
|
53 |
+
return "Login successful!", user['Name']
|
54 |
+
else:
|
55 |
+
return "Invalid email or password.", None
|
56 |
+
except Exception as e:
|
57 |
+
return f"Error during login: {str(e)}", None
|
58 |
+
|
59 |
+
# Function to load menu data
|
60 |
+
def load_menu_from_salesforce():
|
61 |
+
try:
|
62 |
+
query = "SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c"
|
63 |
+
result = sf.query(query)
|
64 |
+
return result['records']
|
65 |
+
except Exception as e:
|
66 |
+
return []
|
67 |
+
|
68 |
+
# Function to load add-ons data
|
69 |
+
def load_add_ons_from_salesforce():
|
70 |
+
try:
|
71 |
+
query = "SELECT Name, Price__c FROM Add_Ons__c"
|
72 |
+
result = sf.query(query)
|
73 |
+
return result['records']
|
74 |
+
except Exception as e:
|
75 |
+
return []
|
76 |
+
|
77 |
+
# Function to filter menu items
|
78 |
+
def filter_menu(preference):
|
79 |
+
menu_data = load_menu_from_salesforce()
|
80 |
+
|
81 |
+
filtered_data = {}
|
82 |
+
for item in menu_data:
|
83 |
+
if "Section__c" not in item or "Veg_NonVeg__c" not in item:
|
84 |
+
continue
|
85 |
+
|
86 |
+
if item["Section__c"] not in filtered_data:
|
87 |
+
filtered_data[item["Section__c"]] = []
|
88 |
+
|
89 |
+
if preference == "All" or (preference == "Veg" and item["Veg_NonVeg__c"] in ["Veg", "Both"]) or (preference == "Non-Veg" and item["Veg_NonVeg__c"] in ["Non veg", "Both"]):
|
90 |
+
filtered_data[item["Section__c"].strip()].append(item)
|
91 |
+
|
92 |
+
html_content = '<div style="padding: 0 10px; max-width: 1200px; margin: auto;">'
|
93 |
+
for section, items in filtered_data.items():
|
94 |
+
html_content += f"<h2 style='text-align: center; margin-top: 5px;'>{section}</h2>"
|
95 |
+
html_content += '<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 15px; justify-content: center; margin-top: 10px;">'
|
96 |
+
for item in items:
|
97 |
+
html_content += f"""
|
98 |
+
<div style="border: 1px solid #ddd; border-radius: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); overflow: hidden; height: 350px;">
|
99 |
+
<img src="{item.get('Image1__c', '')}" style="width: 100%; height: 200px; object-fit: cover;"
|
100 |
+
onclick="openModal('{item['Name']}', '{item.get('Image2__c', '')}', '{item['Description__c']}', '${item['Price__c']}')">
|
101 |
+
<div style="padding: 10px;">
|
102 |
+
<h3 style='font-size: 1.2em; text-align: center;'>{item['Name']}</h3>
|
103 |
+
<p style='font-size: 1.1em; color: green; text-align: center;'>${item['Price__c']}</p>
|
104 |
+
<p style='font-size: 0.9em; text-align: justify; margin: 5px;'>{item['Description__c']}</p>
|
105 |
+
</div>
|
106 |
+
</div>
|
107 |
+
"""
|
108 |
+
html_content += '</div>'
|
109 |
+
html_content += '</div>'
|
110 |
+
|
111 |
+
if not any(filtered_data.values()):
|
112 |
+
return "<p>No items match your filter.</p>"
|
113 |
+
|
114 |
+
return html_content
|
115 |
# Updated Cart Modal HTML
|
116 |
def create_cart_modal():
|
117 |
cart_modal_html = """
|