Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,27 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import bcrypt
|
| 4 |
import gradio as gr
|
| 5 |
from simple_salesforce import Salesforce
|
| 6 |
-
# Authenticate with Salesforce
|
| 7 |
-
sf = Salesforce(username='surendra@sathkrutha.com',
|
| 8 |
-
password='Lavanyanaga@123',
|
| 9 |
-
security_token='z7Wvk6mys7n8XjqbYKf3bwBh7')
|
| 10 |
-
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
# Function
|
| 17 |
-
def verify_password(plain_password, hashed_password):
|
| 18 |
-
return bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8'))
|
| 19 |
-
|
| 20 |
-
# Function for Signup
|
| 21 |
def signup(name, email, phone, password):
|
| 22 |
-
hashed_password = hash_password(password) # Hash the plain text password
|
| 23 |
try:
|
| 24 |
sf.User_Login__c.create({
|
| 25 |
'Name__c': name,
|
| 26 |
'Email__c': email,
|
| 27 |
'Phone__c': phone,
|
| 28 |
-
'Password__c':
|
| 29 |
})
|
| 30 |
return "Signup successful! You can now login."
|
| 31 |
except Exception as e:
|
| 32 |
return f"Error during signup: {str(e)}"
|
| 33 |
|
| 34 |
-
# Function
|
| 35 |
def login(email, password):
|
| 36 |
try:
|
| 37 |
-
# Query Salesforce for the user's hashed password
|
| 38 |
query = f"SELECT Name__c, Email__c, Phone__c, Password__c FROM User_Login__c WHERE Email__c = '{email}'"
|
| 39 |
result = sf.query(query)
|
| 40 |
|
|
@@ -42,21 +29,16 @@ def login(email, password):
|
|
| 42 |
return "Invalid email or password.", None, None, None
|
| 43 |
|
| 44 |
user = result['records'][0]
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
-
if verify_password(password, hashed_password):
|
| 49 |
return "Login successful!", user['Name__c'], user['Email__c'], user['Phone__c']
|
| 50 |
else:
|
| 51 |
return "Invalid email or password.", None, None, None
|
| 52 |
except Exception as e:
|
| 53 |
return f"Error during login: {str(e)}", None, None, None
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
def home_page(name, email, phone):
|
| 57 |
-
return f"Welcome, {name}! Your email is {email} and your phone number is {phone}."
|
| 58 |
-
|
| 59 |
-
# Gradio Signup Interface
|
| 60 |
def signup_page(name, email, phone, password):
|
| 61 |
response = signup(name, email, phone, password)
|
| 62 |
return response
|
|
@@ -73,7 +55,7 @@ signup_interface = gr.Interface(
|
|
| 73 |
title="Signup Page"
|
| 74 |
)
|
| 75 |
|
| 76 |
-
# Gradio Login
|
| 77 |
def login_page(email, password):
|
| 78 |
login_status, name, email, phone = login(email, password)
|
| 79 |
if login_status == "Login successful!":
|
|
@@ -96,19 +78,7 @@ login_interface = gr.Interface(
|
|
| 96 |
title="Login Page"
|
| 97 |
)
|
| 98 |
|
| 99 |
-
# Gradio
|
| 100 |
-
home_interface = gr.Interface(
|
| 101 |
-
fn=home_page,
|
| 102 |
-
inputs=[
|
| 103 |
-
gr.Textbox(label="Name"),
|
| 104 |
-
gr.Textbox(label="Email"),
|
| 105 |
-
gr.Textbox(label="Phone"),
|
| 106 |
-
],
|
| 107 |
-
outputs=gr.Textbox(label="Welcome Message"),
|
| 108 |
-
title="Home Page"
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
# Combine All Pages in Gradio
|
| 112 |
with gr.Blocks() as app:
|
| 113 |
with gr.Tab("Signup"):
|
| 114 |
signup_interface.render()
|
|
@@ -116,105 +86,4 @@ with gr.Blocks() as app:
|
|
| 116 |
with gr.Tab("Login"):
|
| 117 |
login_interface.render()
|
| 118 |
|
| 119 |
-
with gr.Tab("Home"):
|
| 120 |
-
home_interface.render()
|
| 121 |
-
|
| 122 |
-
# Launch the Gradio App
|
| 123 |
app.launch()
|
| 124 |
-
|
| 125 |
-
"""def hash_password(password):
|
| 126 |
-
# This will generate a hash that may exceed 60 characters
|
| 127 |
-
return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
|
| 128 |
-
|
| 129 |
-
def verify_password(plain_password, hashed_password):
|
| 130 |
-
return bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8'))
|
| 131 |
-
def signup(name, email, phone, password):
|
| 132 |
-
hashed_password = hash_password(password)
|
| 133 |
-
try:
|
| 134 |
-
sf.User_Login__c.create({
|
| 135 |
-
'Name__c': name,
|
| 136 |
-
'Email__c': email,
|
| 137 |
-
'Phone__c': phone,
|
| 138 |
-
'Password__c': hashed_password
|
| 139 |
-
})
|
| 140 |
-
return "Signup successful! You can now login."
|
| 141 |
-
except Exception as e:
|
| 142 |
-
return f"Error during signup: {str(e)}"
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
def login(email, password):
|
| 146 |
-
# Query Salesforce for the user's hashed password
|
| 147 |
-
query = f"SELECT Name__c, Email__c, Phone__c, Password__c FROM User_Login__c WHERE Email__c = '{email}'"
|
| 148 |
-
result = sf.query(query)
|
| 149 |
-
|
| 150 |
-
if len(result['records']) == 0:
|
| 151 |
-
return "Invalid email or password.", None, None, None
|
| 152 |
-
|
| 153 |
-
user = result['records'][0]
|
| 154 |
-
hashed_password = user['Password__c']
|
| 155 |
-
|
| 156 |
-
# Compare the entered password with the stored hash
|
| 157 |
-
if bcrypt.checkpw(password.encode('utf-8'), hashed_password.encode('utf-8')):
|
| 158 |
-
return "Login successful!", user['Name__c'], user['Email__c'], user['Phone__c']
|
| 159 |
-
else:
|
| 160 |
-
return "Invalid email or password.", None, None, None
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
import gradio as gr
|
| 164 |
-
def signup_page(name, email, phone, password):
|
| 165 |
-
response = signup(name, email, phone, password)
|
| 166 |
-
return response
|
| 167 |
-
def login_page(email, password):
|
| 168 |
-
response, user = login(email, password)
|
| 169 |
-
if user:
|
| 170 |
-
return response, user['Name__c'], user['Email__c'], user['Phone__c']
|
| 171 |
-
return response, None, None, None
|
| 172 |
-
def home_page(name, email, phone):
|
| 173 |
-
return f"Welcome, {name}! Your email: {email}, Phone: {phone}"
|
| 174 |
-
signup_interface = gr.Interface(
|
| 175 |
-
fn=signup_page,
|
| 176 |
-
inputs=[
|
| 177 |
-
gr.Textbox(label="Name"),
|
| 178 |
-
gr.Textbox(label="Email"),
|
| 179 |
-
gr.Textbox(label="Phone"),
|
| 180 |
-
gr.Textbox(label="Password", type="password"),
|
| 181 |
-
],
|
| 182 |
-
outputs=gr.Textbox(label="Signup Status"),
|
| 183 |
-
title="Signup Page"
|
| 184 |
-
)
|
| 185 |
-
login_interface = gr.Interface(
|
| 186 |
-
fn=login_page,
|
| 187 |
-
inputs=[
|
| 188 |
-
gr.Textbox(label="Email"),
|
| 189 |
-
gr.Textbox(label="Password", type="password"),
|
| 190 |
-
],
|
| 191 |
-
outputs=[
|
| 192 |
-
gr.Textbox(label="Login Status"),
|
| 193 |
-
gr.Textbox(label="Name"),
|
| 194 |
-
gr.Textbox(label="Email"),
|
| 195 |
-
gr.Textbox(label="Phone"),
|
| 196 |
-
],
|
| 197 |
-
title="Login Page"
|
| 198 |
-
)
|
| 199 |
-
home_interface = gr.Interface(
|
| 200 |
-
fn=home_page,
|
| 201 |
-
inputs=[
|
| 202 |
-
gr.Textbox(label="Name"),
|
| 203 |
-
gr.Textbox(label="Email"),
|
| 204 |
-
gr.Textbox(label="Phone"),
|
| 205 |
-
],
|
| 206 |
-
outputs=gr.Textbox(label="Welcome Message"),
|
| 207 |
-
title="Home Page"
|
| 208 |
-
)
|
| 209 |
-
with gr.Blocks() as app:
|
| 210 |
-
with gr.Tab("Signup"):
|
| 211 |
-
signup_interface.render()
|
| 212 |
-
|
| 213 |
-
with gr.Tab("Login"):
|
| 214 |
-
login_interface.render()
|
| 215 |
-
|
| 216 |
-
with gr.Tab("Home"):
|
| 217 |
-
home_interface.render()
|
| 218 |
-
|
| 219 |
-
# Launch the app
|
| 220 |
-
app.launch()"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from simple_salesforce import Salesforce
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Salesforce Connection
|
| 5 |
+
sf = Salesforce(username='your_username',
|
| 6 |
+
password='your_password',
|
| 7 |
+
security_token='your_security_token')
|
| 8 |
|
| 9 |
+
# Signup Function
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def signup(name, email, phone, password):
|
|
|
|
| 11 |
try:
|
| 12 |
sf.User_Login__c.create({
|
| 13 |
'Name__c': name,
|
| 14 |
'Email__c': email,
|
| 15 |
'Phone__c': phone,
|
| 16 |
+
'Password__c': password
|
| 17 |
})
|
| 18 |
return "Signup successful! You can now login."
|
| 19 |
except Exception as e:
|
| 20 |
return f"Error during signup: {str(e)}"
|
| 21 |
|
| 22 |
+
# Login Function
|
| 23 |
def login(email, password):
|
| 24 |
try:
|
|
|
|
| 25 |
query = f"SELECT Name__c, Email__c, Phone__c, Password__c FROM User_Login__c WHERE Email__c = '{email}'"
|
| 26 |
result = sf.query(query)
|
| 27 |
|
|
|
|
| 29 |
return "Invalid email or password.", None, None, None
|
| 30 |
|
| 31 |
user = result['records'][0]
|
| 32 |
+
stored_password = user['Password__c']
|
| 33 |
|
| 34 |
+
if password == stored_password:
|
|
|
|
| 35 |
return "Login successful!", user['Name__c'], user['Email__c'], user['Phone__c']
|
| 36 |
else:
|
| 37 |
return "Invalid email or password.", None, None, None
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error during login: {str(e)}", None, None, None
|
| 40 |
|
| 41 |
+
# Gradio Signup Page
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
def signup_page(name, email, phone, password):
|
| 43 |
response = signup(name, email, phone, password)
|
| 44 |
return response
|
|
|
|
| 55 |
title="Signup Page"
|
| 56 |
)
|
| 57 |
|
| 58 |
+
# Gradio Login Page
|
| 59 |
def login_page(email, password):
|
| 60 |
login_status, name, email, phone = login(email, password)
|
| 61 |
if login_status == "Login successful!":
|
|
|
|
| 78 |
title="Login Page"
|
| 79 |
)
|
| 80 |
|
| 81 |
+
# Gradio App
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
with gr.Blocks() as app:
|
| 83 |
with gr.Tab("Signup"):
|
| 84 |
signup_interface.render()
|
|
|
|
| 86 |
with gr.Tab("Login"):
|
| 87 |
login_interface.render()
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|