import bcrypt import gradio as gr from simple_salesforce import Salesforce # Salesforce Connection sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q') # Function to Hash Password def hash_password(password): return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8') # Function to Verify Password def verify_password(plain_password, hashed_password): return bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8')) # Signup function def signup(name, email, phone, password): try: email = email.strip() # Check if the email already exists in Salesforce query = f"SELECT Id FROM Customer_Login__c WHERE Email__c = '{email}'" result = sf.query(query) if len(result['records']) > 0: return "Email already exists! Please use a different email." # Hash the password hashed_password = hash_password(password) # Create the new user record sf.Customer_Login__c.create({ 'Name': name.strip(), 'Email__c': email, 'Phone_Number__c': phone.strip(), 'Password__c': hashed_password }) return "Signup successful! You can now login." except Exception as e: return f"Error during signup: {str(e)}" # Login function def login(email, password): try: email = email.strip() password = password.strip() # Query Salesforce for user details query = f"SELECT Name, Password__c FROM Customer_Login__c WHERE Email__c = '{email}'" result = sf.query(query) if len(result['records']) == 0: return "Invalid email or password.", None user = result['records'][0] if verify_password(password, user['Password__c']): return "Login successful!", user['Name'] else: return "Invalid email or password.", None except Exception as e: return f"Error during login: {str(e)}", None # Function to load menu items from Salesforce def load_menu_from_salesforce(): try: query = "SELECT Name, Price__c, Description__c, Image1__c, Veg_NonVeg__c, Section__c FROM Menu_Item__c" result = sf.query(query) return result['records'] except Exception as e: raise ValueError(f"Error loading menu data from Salesforce: {e}") # Function to filter menu items based on preference def filter_menu(preferences): menu_data = load_menu_from_salesforce() filtered_data = {} for item in menu_data: if item["Section__c"] not in filtered_data: filtered_data[item["Section__c"]] = [] if "Veg" in preferences and item["Veg_NonVeg__c"] in ["Veg", "Both"]: filtered_data[item["Section__c"]].append(item) elif "Non-Veg" in preferences and item["Veg_NonVeg__c"] in ["Non-Veg", "Both"]: filtered_data[item["Section__c"]].append(item) html_content = '
No items match your filter.
" # Gradio App with gr.Blocks() as app: login_status = gr.State(value=False) # Header with gr.Row(): gr.HTML("