nagasurendra commited on
Commit
fc7416b
·
verified ·
1 Parent(s): e8fd9dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -118
app.py CHANGED
@@ -1,126 +1,49 @@
1
-
2
-
3
-
4
- import bcrypt
5
- import gradio as gr
6
  from simple_salesforce import Salesforce
 
7
  # Salesforce Connection
8
  sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
9
 
10
-
11
- # Function to Hash Password
12
- def hash_password(password):
13
- return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
14
-
15
- # Function to Verify Password
16
- def verify_password(plain_password, hashed_password):
17
- return bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8'))
18
-
19
- # Signup function with email validation
20
- def signup(name, email, phone, password):
21
  try:
22
- email = email.strip()
23
-
24
- # Check if the email already exists in Salesforce
25
- query = f"SELECT Id FROM Customer_Login__c WHERE Email__c = '{email}'"
26
  result = sf.query(query)
27
-
28
- if len(result['records']) > 0:
29
- # Email already exists
30
- return "Email already exists! Please use a different email."
31
-
32
- # Hash the password
33
- hashed_password = hash_password(password)
34
-
35
- # Create the new user record
36
- sf.Customer_Login__c.create({
37
- 'Name': name.strip(),
38
- 'Email__c': email,
39
- 'Phone_Number__c': phone.strip(),
40
- 'Password__c': hashed_password # Use Password3__c field for hashed passwords
41
- })
42
- return "Signup successful! You can now login."
43
  except Exception as e:
44
- return f"Error during signup: {str(e)}"
45
-
46
- # Login function
47
- def login(email, password):
48
- try:
49
- email = email.strip()
50
- password = password.strip()
51
-
52
- # Query Salesforce for user details
53
- query = f"SELECT Name, Email__c, Phone_Number__c, Password__c FROM Customer_Login__c WHERE Email__c = '{email}'"
54
- result = sf.query(query)
55
-
56
- if len(result['records']) == 0:
57
- return "Invalid email or password.", None, None, None
58
-
59
- user = result['records'][0]
60
- stored_password = user['Password__c']
61
-
62
- print(f"Entered Email: {email}")
63
- print(f"Entered Password: {password}")
64
- print(f"Stored Hashed Password: {stored_password}")
65
-
66
- # Verify the entered password with the stored hash
67
- if verify_password(password, stored_password):
68
- print("Password matched!")
69
- return "Login successful!", user['Name'], user['Email__c'], user['Phone_Number__c']
70
  else:
71
- print("Password did not match!")
72
- return "Invalid email or password.", None, None, None
73
- except Exception as e:
74
- print(f"Error during login: {str(e)}")
75
- return f"Error during login: {str(e)}", None, None, None
76
-
77
- # Gradio Signup Page
78
- def signup_page(name, email, phone, password):
79
- response = signup(name, email, phone, password)
80
- return response
81
-
82
- signup_interface = gr.Interface(
83
- fn=signup_page,
84
- inputs=[
85
- gr.Textbox(label="Name"),
86
- gr.Textbox(label="Email"),
87
- gr.Textbox(label="Phone"),
88
- gr.Textbox(label="Password", type="password"),
89
- ],
90
- outputs=gr.Textbox(label="Signup Status"),
91
- title="Signup Page"
92
- )
93
-
94
- # Gradio Login Page
95
- def login_page(email, password):
96
- login_status, name, email, phone = login(email, password)
97
- if login_status == "Login successful!":
98
- return login_status, name, email, phone
99
- else:
100
- return login_status, "Error", "Error", "Error"
101
-
102
- login_interface = gr.Interface(
103
- fn=login_page,
104
- inputs=[
105
- gr.Textbox(label="Email"),
106
- gr.Textbox(label="Password", type="password"),
107
- ],
108
- outputs=[
109
- gr.Textbox(label="Login Status"),
110
- gr.Textbox(label="Name"),
111
- gr.Textbox(label="Email"),
112
- gr.Textbox(label="Phone"),
113
- ],
114
- title="Login Page"
115
- )
116
-
117
- # Combine Pages in Gradio
118
- with gr.Blocks() as app:
119
- with gr.Tab("Signup"):
120
- signup_interface.render()
121
-
122
- with gr.Tab("Login"):
123
- login_interface.render()
124
-
125
- # Launch Gradio App
126
- app.launch()
 
 
 
 
 
 
1
  from simple_salesforce import Salesforce
2
+
3
  # Salesforce Connection
4
  sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
5
 
6
+ # Function to fetch menu items from Salesforce
7
+ def load_menu_from_salesforce():
 
 
 
 
 
 
 
 
 
8
  try:
9
+ query = "SELECT Name, Price__c, Description__c, Image1__c, Ingredients__c FROM Menu_Item__c"
 
 
 
10
  result = sf.query(query)
11
+ return result['records']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  except Exception as e:
13
+ raise ValueError(f"Error loading menu data from Salesforce: {e}")
14
+
15
+ # Function to filter menu items based on preference
16
+ def filter_menu_from_salesforce(preference):
17
+ menu_data = load_menu_from_salesforce()
18
+ filtered_data = []
19
+
20
+ for item in menu_data:
21
+ if preference == "Halal/Non-Veg":
22
+ if any(x in item.get("Ingredients__c", "").lower() for x in ["chicken", "mutton", "fish", "prawns", "goat"]):
23
+ filtered_data.append(item)
24
+ elif preference == "Vegetarian":
25
+ if not any(x in item.get("Ingredients__c", "").lower() for x in ["chicken", "mutton", "fish", "prawns", "goat"]):
26
+ filtered_data.append(item)
27
+ elif preference == "Guilt-Free":
28
+ if "fat:" in item.get("Description__c", "").lower():
29
+ filtered_data.append(item)
 
 
 
 
 
 
 
 
 
30
  else:
31
+ filtered_data = menu_data
32
+
33
+ # Generate HTML content
34
+ html_content = ""
35
+ for item in filtered_data:
36
+ html_content += f"""
37
+ <div style="display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; margin-bottom: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
38
+ <div style="flex: 1; margin-right: 15px;">
39
+ <h3 style="margin: 0; font-size: 18px;">{item['Name']}</h3>
40
+ <p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price__c']}</p>
41
+ <p style="margin: 5px 0; font-size: 14px; color: #555;">{item['Description__c']}</p>
42
+ </div>
43
+ <div style="flex-shrink: 0; text-align: center;">
44
+ <img src="{item['Image1__c']}" alt="{item['Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
45
+ <button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="openModal('{item['Name']}', '{item['Image1__c']}', '{item['Description__c']}', '{item['Price__c']}')">Add</button>
46
+ </div>
47
+ </div>
48
+ """
49
+ return html_content