Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -45,87 +45,48 @@ def login(email, password):
|
|
45 |
email = email.strip()
|
46 |
password = password.strip()
|
47 |
|
48 |
-
# Debug: Print entered email and password
|
49 |
-
print(f"Entered Email: {email}")
|
50 |
-
print(f"Entered Password: {password}")
|
51 |
-
|
52 |
# Query Salesforce for user details
|
53 |
query = f"SELECT Name, Password__c FROM Customer_Login__c WHERE Email__c = '{email}'"
|
54 |
result = sf.query(query)
|
55 |
|
56 |
-
# Debug: Print query results
|
57 |
-
print(f"Query Result: {result}")
|
58 |
-
|
59 |
if len(result['records']) == 0:
|
60 |
-
print("No matching user found.")
|
61 |
return "Invalid email or password.", None
|
62 |
|
63 |
user = result['records'][0]
|
64 |
stored_password = user['Password__c']
|
65 |
|
66 |
-
# Debug: Print stored hashed password
|
67 |
-
print(f"Stored Hashed Password: {stored_password}")
|
68 |
-
|
69 |
# Verify the entered password with the stored hash
|
70 |
if verify_password(password, stored_password):
|
71 |
-
print("Password matched!")
|
72 |
return "Login successful!", user['Name']
|
73 |
else:
|
74 |
-
print("Password did not match!")
|
75 |
return "Invalid email or password.", None
|
76 |
except Exception as e:
|
77 |
-
print(f"Error during login: {e}")
|
78 |
return f"Error during login: {str(e)}", None
|
79 |
|
80 |
-
#
|
81 |
def load_menu_from_salesforce():
|
82 |
try:
|
83 |
query = "SELECT Name, Price__c, Description__c, Image1__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c"
|
84 |
result = sf.query(query)
|
85 |
-
|
86 |
-
# Debugging: Print fetched records
|
87 |
-
print("Fetched Records from Salesforce:")
|
88 |
-
for record in result['records']:
|
89 |
-
print(record)
|
90 |
-
|
91 |
return result['records']
|
92 |
except Exception as e:
|
93 |
-
print(f"Error fetching menu data: {e}")
|
94 |
return []
|
95 |
|
96 |
-
# Function to filter menu items
|
97 |
-
def filter_menu(
|
98 |
menu_data = load_menu_from_salesforce()
|
99 |
|
100 |
-
# Debugging: Print the fetched menu data
|
101 |
-
print("Menu Data Fetched:")
|
102 |
-
for item in menu_data:
|
103 |
-
print(item)
|
104 |
-
|
105 |
-
# Check if data exists
|
106 |
-
if not menu_data:
|
107 |
-
return "<p style='text-align: center;'>No menu data available. Please try again later.</p>"
|
108 |
-
|
109 |
filtered_data = {}
|
110 |
-
|
111 |
for item in menu_data:
|
112 |
-
# Ensure the required fields exist
|
113 |
if "Section__c" not in item or "Veg_NonVeg__c" not in item:
|
114 |
continue
|
115 |
|
116 |
-
# Add the section to filtered data if not already present
|
117 |
if item["Section__c"] not in filtered_data:
|
118 |
filtered_data[item["Section__c"]] = []
|
119 |
|
120 |
-
|
121 |
-
if "All" in preferences:
|
122 |
-
filtered_data[item["Section__c"]].append(item)
|
123 |
-
elif "Veg" in preferences and item["Veg_NonVeg__c"] in ["Veg", "Both"]:
|
124 |
-
filtered_data[item["Section__c"]].append(item)
|
125 |
-
elif "Non-Veg" in preferences and item["Veg_NonVeg__c"] in ["Non veg", "Both"]:
|
126 |
filtered_data[item["Section__c"]].append(item)
|
127 |
|
128 |
-
# Generate HTML content
|
129 |
html_content = '<div style="padding: 20px; max-width: 1200px; margin: auto;">'
|
130 |
for section, items in filtered_data.items():
|
131 |
if items:
|
@@ -152,11 +113,9 @@ def filter_menu(preferences):
|
|
152 |
|
153 |
# Gradio App
|
154 |
with gr.Blocks() as app:
|
155 |
-
# Header
|
156 |
with gr.Row():
|
157 |
gr.HTML("<h1 style='text-align: center;'>Welcome to Biryani Hub</h1>")
|
158 |
|
159 |
-
# Login Page
|
160 |
with gr.Row(visible=True) as login_page:
|
161 |
with gr.Column():
|
162 |
login_email = gr.Textbox(label="Email")
|
@@ -165,7 +124,6 @@ with gr.Blocks() as app:
|
|
165 |
signup_button = gr.Button("Go to Signup")
|
166 |
login_output = gr.Textbox(label="Status")
|
167 |
|
168 |
-
# Signup Page
|
169 |
with gr.Row(visible=False) as signup_page:
|
170 |
with gr.Column():
|
171 |
signup_name = gr.Textbox(label="Name")
|
@@ -176,39 +134,33 @@ with gr.Blocks() as app:
|
|
176 |
login_redirect = gr.Button("Go to Login")
|
177 |
signup_output = gr.Textbox(label="Status")
|
178 |
|
179 |
-
# Menu Page
|
180 |
with gr.Row(visible=False) as menu_page:
|
181 |
-
|
182 |
-
choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value=["All"]
|
183 |
-
)
|
184 |
menu_output = gr.HTML()
|
185 |
|
186 |
-
# Footer
|
187 |
with gr.Row(visible=False) as footer:
|
188 |
gr.HTML("<footer style='text-align: center;'>Thank you! Welcome again!</footer>")
|
189 |
|
190 |
-
# Login Button Logic
|
191 |
def handle_login(email, password):
|
192 |
status, user = login(email, password)
|
193 |
if status == "Login successful!":
|
194 |
-
|
|
|
195 |
else:
|
196 |
-
return gr.update(), gr.update(), gr.update(), status
|
197 |
|
198 |
-
# Signup Button Logic
|
199 |
def handle_signup(name, email, phone, password):
|
200 |
return signup(name, email, phone, password)
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
content = filter_menu(preferences)
|
205 |
return content
|
206 |
|
207 |
login_button.click(
|
208 |
-
handle_login, [login_email, login_password], [login_page, menu_page, footer, login_output]
|
209 |
)
|
210 |
signup_button.click(lambda: (gr.update(visible=False), gr.update(visible=True)), None, [login_page, signup_page])
|
211 |
submit_signup.click(handle_signup, [signup_name, signup_email, signup_phone, signup_password], signup_output)
|
212 |
-
|
213 |
|
214 |
app.launch()
|
|
|
45 |
email = email.strip()
|
46 |
password = password.strip()
|
47 |
|
|
|
|
|
|
|
|
|
48 |
# Query Salesforce for user details
|
49 |
query = f"SELECT Name, Password__c FROM Customer_Login__c WHERE Email__c = '{email}'"
|
50 |
result = sf.query(query)
|
51 |
|
|
|
|
|
|
|
52 |
if len(result['records']) == 0:
|
|
|
53 |
return "Invalid email or password.", None
|
54 |
|
55 |
user = result['records'][0]
|
56 |
stored_password = user['Password__c']
|
57 |
|
|
|
|
|
|
|
58 |
# Verify the entered password with the stored hash
|
59 |
if verify_password(password, stored_password):
|
|
|
60 |
return "Login successful!", user['Name']
|
61 |
else:
|
|
|
62 |
return "Invalid email or password.", None
|
63 |
except Exception as e:
|
|
|
64 |
return f"Error during login: {str(e)}", None
|
65 |
|
66 |
+
# Function to load menu data
|
67 |
def load_menu_from_salesforce():
|
68 |
try:
|
69 |
query = "SELECT Name, Price__c, Description__c, Image1__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c"
|
70 |
result = sf.query(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
return result['records']
|
72 |
except Exception as e:
|
|
|
73 |
return []
|
74 |
|
75 |
+
# Function to filter menu items
|
76 |
+
def filter_menu(preference):
|
77 |
menu_data = load_menu_from_salesforce()
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
filtered_data = {}
|
|
|
80 |
for item in menu_data:
|
|
|
81 |
if "Section__c" not in item or "Veg_NonVeg__c" not in item:
|
82 |
continue
|
83 |
|
|
|
84 |
if item["Section__c"] not in filtered_data:
|
85 |
filtered_data[item["Section__c"]] = []
|
86 |
|
87 |
+
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"]):
|
|
|
|
|
|
|
|
|
|
|
88 |
filtered_data[item["Section__c"]].append(item)
|
89 |
|
|
|
90 |
html_content = '<div style="padding: 20px; max-width: 1200px; margin: auto;">'
|
91 |
for section, items in filtered_data.items():
|
92 |
if items:
|
|
|
113 |
|
114 |
# Gradio App
|
115 |
with gr.Blocks() as app:
|
|
|
116 |
with gr.Row():
|
117 |
gr.HTML("<h1 style='text-align: center;'>Welcome to Biryani Hub</h1>")
|
118 |
|
|
|
119 |
with gr.Row(visible=True) as login_page:
|
120 |
with gr.Column():
|
121 |
login_email = gr.Textbox(label="Email")
|
|
|
124 |
signup_button = gr.Button("Go to Signup")
|
125 |
login_output = gr.Textbox(label="Status")
|
126 |
|
|
|
127 |
with gr.Row(visible=False) as signup_page:
|
128 |
with gr.Column():
|
129 |
signup_name = gr.Textbox(label="Name")
|
|
|
134 |
login_redirect = gr.Button("Go to Login")
|
135 |
signup_output = gr.Textbox(label="Status")
|
136 |
|
|
|
137 |
with gr.Row(visible=False) as menu_page:
|
138 |
+
preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
|
|
|
|
|
139 |
menu_output = gr.HTML()
|
140 |
|
|
|
141 |
with gr.Row(visible=False) as footer:
|
142 |
gr.HTML("<footer style='text-align: center;'>Thank you! Welcome again!</footer>")
|
143 |
|
|
|
144 |
def handle_login(email, password):
|
145 |
status, user = login(email, password)
|
146 |
if status == "Login successful!":
|
147 |
+
content = filter_menu("All") # Default to "All" on login
|
148 |
+
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(value=content), status
|
149 |
else:
|
150 |
+
return gr.update(), gr.update(), gr.update(), gr.update(), status
|
151 |
|
|
|
152 |
def handle_signup(name, email, phone, password):
|
153 |
return signup(name, email, phone, password)
|
154 |
|
155 |
+
def handle_menu(preference):
|
156 |
+
content = filter_menu(preference)
|
|
|
157 |
return content
|
158 |
|
159 |
login_button.click(
|
160 |
+
handle_login, [login_email, login_password], [login_page, menu_page, footer, menu_output, login_output]
|
161 |
)
|
162 |
signup_button.click(lambda: (gr.update(visible=False), gr.update(visible=True)), None, [login_page, signup_page])
|
163 |
submit_signup.click(handle_signup, [signup_name, signup_email, signup_phone, signup_password], signup_output)
|
164 |
+
preference.change(handle_menu, [preference], menu_output)
|
165 |
|
166 |
app.launch()
|