Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils.database_handler import check_credentials, save_user
|
| 3 |
-
|
| 4 |
|
| 5 |
def app_interface():
|
| 6 |
# Login Button Actions
|
|
@@ -15,23 +15,17 @@ def app_interface():
|
|
| 15 |
return (
|
| 16 |
gr.update(visible=True), # Show error box
|
| 17 |
gr.update(visible=False), # Keep preferences page hidden
|
| 18 |
-
"Invalid email or password. Try again.", #
|
| 19 |
)
|
| 20 |
|
| 21 |
def navigate_to_signup():
|
| 22 |
return gr.update(visible=False), gr.update(visible=True)
|
| 23 |
|
| 24 |
-
# Sign-Up Button Actions
|
| 25 |
def create_account(name, phone, email, password):
|
| 26 |
-
print("Signup details received:", name, phone, email, password) # Debugging
|
| 27 |
-
|
| 28 |
-
# Save user data
|
| 29 |
if save_user(name, phone, email, password):
|
| 30 |
-
print("User saved successfully.") # Debugging
|
| 31 |
return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
|
| 32 |
else:
|
| 33 |
-
|
| 34 |
-
return "Email already exists or data saving failed.", gr.update(visible=False), gr.update(visible=True)
|
| 35 |
|
| 36 |
def navigate_to_login():
|
| 37 |
return gr.update(visible=True), gr.update(visible=False)
|
|
@@ -61,13 +55,30 @@ def app_interface():
|
|
| 61 |
# Preferences Page
|
| 62 |
with gr.Column(visible=False) as preference_section:
|
| 63 |
gr.Markdown("# Preferences Page")
|
| 64 |
-
preference_interface(preference_section)
|
| 65 |
|
| 66 |
-
# Button Actions
|
| 67 |
-
login_btn.click(
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
return app
|
| 73 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils.database_handler import check_credentials, save_user
|
| 3 |
+
|
| 4 |
|
| 5 |
def app_interface():
|
| 6 |
# Login Button Actions
|
|
|
|
| 15 |
return (
|
| 16 |
gr.update(visible=True), # Show error box
|
| 17 |
gr.update(visible=False), # Keep preferences page hidden
|
| 18 |
+
"Invalid email or password. Try again.", # Error message
|
| 19 |
)
|
| 20 |
|
| 21 |
def navigate_to_signup():
|
| 22 |
return gr.update(visible=False), gr.update(visible=True)
|
| 23 |
|
|
|
|
| 24 |
def create_account(name, phone, email, password):
|
|
|
|
|
|
|
|
|
|
| 25 |
if save_user(name, phone, email, password):
|
|
|
|
| 26 |
return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
|
| 27 |
else:
|
| 28 |
+
return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True)
|
|
|
|
| 29 |
|
| 30 |
def navigate_to_login():
|
| 31 |
return gr.update(visible=True), gr.update(visible=False)
|
|
|
|
| 55 |
# Preferences Page
|
| 56 |
with gr.Column(visible=False) as preference_section:
|
| 57 |
gr.Markdown("# Preferences Page")
|
|
|
|
| 58 |
|
| 59 |
+
# Button Actions for Login
|
| 60 |
+
login_btn.click(
|
| 61 |
+
authenticate_user,
|
| 62 |
+
inputs=[email, password],
|
| 63 |
+
outputs=[login_section, preference_section, error_box],
|
| 64 |
+
)
|
| 65 |
+
create_account_btn.click(
|
| 66 |
+
navigate_to_signup,
|
| 67 |
+
inputs=[],
|
| 68 |
+
outputs=[login_section, signup_section],
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# Button Actions for Sign-Up
|
| 72 |
+
submit_btn.click(
|
| 73 |
+
create_account,
|
| 74 |
+
inputs=[name, phone, signup_email, signup_password],
|
| 75 |
+
outputs=[success_message, signup_section, login_section],
|
| 76 |
+
)
|
| 77 |
+
back_to_login_btn.click(
|
| 78 |
+
navigate_to_login,
|
| 79 |
+
inputs=[],
|
| 80 |
+
outputs=[login_section, signup_section],
|
| 81 |
+
)
|
| 82 |
|
| 83 |
return app
|
| 84 |
|