Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -861,6 +861,7 @@ def check_password(password, hashed):
|
|
861 |
return bcrypt.checkpw(password.encode(), hashed)
|
862 |
|
863 |
# User signup and login functions
|
|
|
864 |
def signup_user(email, password):
|
865 |
conn = sqlite3.connect('user_data.db')
|
866 |
c = conn.cursor()
|
@@ -873,23 +874,29 @@ def signup_user(email, password):
|
|
873 |
finally:
|
874 |
conn.close()
|
875 |
|
876 |
-
def login_user(email, password):
|
877 |
conn = sqlite3.connect('user_data.db')
|
878 |
c = conn.cursor()
|
879 |
c.execute("SELECT password FROM users WHERE email = ?", (email,))
|
880 |
result = c.fetchone()
|
881 |
conn.close()
|
882 |
if result and check_password(password, result[0]):
|
883 |
-
|
|
|
884 |
else:
|
885 |
-
return "Invalid email or password!"
|
|
|
|
|
|
|
|
|
886 |
|
887 |
-
#
|
888 |
def signup(email, password):
|
889 |
return signup_user(email, password)
|
890 |
|
891 |
-
def login(email, password):
|
892 |
-
|
|
|
893 |
|
894 |
# Initialize database
|
895 |
initialize_database()
|
@@ -899,24 +906,27 @@ initialize_database()
|
|
899 |
|
900 |
|
901 |
|
902 |
-
|
903 |
-
|
|
|
904 |
with gr.Row():
|
905 |
with gr.Column():
|
906 |
gr.Markdown("<h1>Welcome to the App</h1>")
|
|
|
907 |
with gr.Tab("Sign Up"):
|
908 |
-
signup_email = gr.Textbox(placeholder="Email", label="Email")
|
909 |
signup_password = gr.Textbox(placeholder="Password", label="Password", type="password")
|
910 |
signup_button = gr.Button("Sign Up")
|
911 |
signup_output = gr.Textbox(interactive=False, label="Output")
|
912 |
signup_button.click(signup, inputs=[signup_email, signup_password], outputs=signup_output)
|
913 |
|
914 |
with gr.Tab("Login"):
|
915 |
-
login_email = gr.Textbox(placeholder="Email", label="Email")
|
916 |
login_password = gr.Textbox(placeholder="Password", label="Password", type="password")
|
917 |
login_button = gr.Button("Login")
|
918 |
login_output = gr.Textbox(interactive=False, label="Output")
|
919 |
-
login_button.click(login, inputs=[login_email, login_password], outputs=login_output)
|
|
|
920 |
|
921 |
state = gr.State()
|
922 |
chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
|
|
|
861 |
return bcrypt.checkpw(password.encode(), hashed)
|
862 |
|
863 |
# User signup and login functions
|
864 |
+
|
865 |
def signup_user(email, password):
|
866 |
conn = sqlite3.connect('user_data.db')
|
867 |
c = conn.cursor()
|
|
|
874 |
finally:
|
875 |
conn.close()
|
876 |
|
877 |
+
def login_user(email, password, state):
|
878 |
conn = sqlite3.connect('user_data.db')
|
879 |
c = conn.cursor()
|
880 |
c.execute("SELECT password FROM users WHERE email = ?", (email,))
|
881 |
result = c.fetchone()
|
882 |
conn.close()
|
883 |
if result and check_password(password, result[0]):
|
884 |
+
state['authenticated'] = True
|
885 |
+
return "Login successful!", state
|
886 |
else:
|
887 |
+
return "Invalid email or password!", state
|
888 |
+
|
889 |
+
def logout(state):
|
890 |
+
message, state = logout_user(state)
|
891 |
+
return message, state, "Login"
|
892 |
|
893 |
+
# Define the necessary functions
|
894 |
def signup(email, password):
|
895 |
return signup_user(email, password)
|
896 |
|
897 |
+
def login(email, password, state):
|
898 |
+
message, state = login_user(email, password, state)
|
899 |
+
return message, state, "Logout" if state['authenticated'] else "Login"
|
900 |
|
901 |
# Initialize database
|
902 |
initialize_database()
|
|
|
906 |
|
907 |
|
908 |
|
909 |
+
ith gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
910 |
+
state = gr.State({'authenticated': False})
|
911 |
+
|
912 |
with gr.Row():
|
913 |
with gr.Column():
|
914 |
gr.Markdown("<h1>Welcome to the App</h1>")
|
915 |
+
|
916 |
with gr.Tab("Sign Up"):
|
917 |
+
signup_email = gr.Textbox(placeholder="Email", label="Email", type="email")
|
918 |
signup_password = gr.Textbox(placeholder="Password", label="Password", type="password")
|
919 |
signup_button = gr.Button("Sign Up")
|
920 |
signup_output = gr.Textbox(interactive=False, label="Output")
|
921 |
signup_button.click(signup, inputs=[signup_email, signup_password], outputs=signup_output)
|
922 |
|
923 |
with gr.Tab("Login"):
|
924 |
+
login_email = gr.Textbox(placeholder="Email", label="Email", type="email")
|
925 |
login_password = gr.Textbox(placeholder="Password", label="Password", type="password")
|
926 |
login_button = gr.Button("Login")
|
927 |
login_output = gr.Textbox(interactive=False, label="Output")
|
928 |
+
login_button.click(login, inputs=[login_email, login_password, state], outputs=[login_output, state, login_button])
|
929 |
+
login_button.click(logout, inputs=[state], outputs=[login_output, state, login_button], show_progress=False)
|
930 |
|
931 |
state = gr.State()
|
932 |
chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
|