Update app.py
Browse files
app.py
CHANGED
|
@@ -35,9 +35,9 @@ def validate_user(phone, password):
|
|
| 35 |
# Function to handle login
|
| 36 |
def login(phone, password):
|
| 37 |
if validate_user(phone, password):
|
| 38 |
-
return
|
| 39 |
else:
|
| 40 |
-
return "Invalid phone number or password. Please try again."
|
| 41 |
|
| 42 |
# Function to handle signup
|
| 43 |
def signup(phone, name, email, password):
|
|
@@ -48,21 +48,32 @@ def signup(phone, name, email, password):
|
|
| 48 |
file.write(f"{phone},{name},{email},{password}\n")
|
| 49 |
return "Signup successful! You can now login."
|
| 50 |
|
| 51 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
def login_interface():
|
| 53 |
-
with gr.Blocks() as
|
| 54 |
gr.Markdown("# Login")
|
| 55 |
phone = gr.Textbox(label="Phone Number")
|
| 56 |
password = gr.Textbox(label="Password", type="password")
|
| 57 |
output = gr.Textbox(label="Output")
|
| 58 |
login_button = gr.Button("Login")
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
return
|
| 63 |
|
|
|
|
| 64 |
def signup_interface():
|
| 65 |
-
with gr.Blocks() as
|
| 66 |
gr.Markdown("# Signup")
|
| 67 |
phone = gr.Textbox(label="Phone Number")
|
| 68 |
name = gr.Textbox(label="Name")
|
|
@@ -73,17 +84,19 @@ def signup_interface():
|
|
| 73 |
|
| 74 |
signup_button.click(signup, inputs=[phone, name, email, password], outputs=output)
|
| 75 |
|
| 76 |
-
return
|
| 77 |
|
| 78 |
# Main interface
|
| 79 |
with gr.Blocks() as main_interface:
|
| 80 |
gr.Markdown("# Login and Signup System")
|
| 81 |
with gr.Tabs():
|
| 82 |
with gr.Tab("Login"):
|
| 83 |
-
login_interface()
|
|
|
|
| 84 |
with gr.Tab("Signup"):
|
| 85 |
signup_interface()
|
| 86 |
|
| 87 |
if __name__ == "__main__":
|
| 88 |
main_interface.launch()
|
| 89 |
|
|
|
|
|
|
| 35 |
# Function to handle login
|
| 36 |
def login(phone, password):
|
| 37 |
if validate_user(phone, password):
|
| 38 |
+
return "Login successful! Redirecting to the main page...", gr.update(visible=True), gr.update(visible=False)
|
| 39 |
else:
|
| 40 |
+
return "Invalid phone number or password. Please try again.", gr.update(visible=False), gr.update(visible=True)
|
| 41 |
|
| 42 |
# Function to handle signup
|
| 43 |
def signup(phone, name, email, password):
|
|
|
|
| 48 |
file.write(f"{phone},{name},{email},{password}\n")
|
| 49 |
return "Signup successful! You can now login."
|
| 50 |
|
| 51 |
+
# Main Page
|
| 52 |
+
def main_page():
|
| 53 |
+
with gr.Blocks() as main:
|
| 54 |
+
gr.Markdown("# Welcome to the Main Page")
|
| 55 |
+
gr.Text("You are successfully logged in!")
|
| 56 |
+
return main
|
| 57 |
+
|
| 58 |
+
# Login Interface
|
| 59 |
def login_interface():
|
| 60 |
+
with gr.Blocks() as login_demo:
|
| 61 |
gr.Markdown("# Login")
|
| 62 |
phone = gr.Textbox(label="Phone Number")
|
| 63 |
password = gr.Textbox(label="Password", type="password")
|
| 64 |
output = gr.Textbox(label="Output")
|
| 65 |
login_button = gr.Button("Login")
|
| 66 |
|
| 67 |
+
main_content = main_page()
|
| 68 |
+
main_content.visible = False
|
| 69 |
+
|
| 70 |
+
login_button.click(login, inputs=[phone, password], outputs=[output, main_content, login_demo])
|
| 71 |
|
| 72 |
+
return login_demo, main_content
|
| 73 |
|
| 74 |
+
# Signup Interface
|
| 75 |
def signup_interface():
|
| 76 |
+
with gr.Blocks() as signup_demo:
|
| 77 |
gr.Markdown("# Signup")
|
| 78 |
phone = gr.Textbox(label="Phone Number")
|
| 79 |
name = gr.Textbox(label="Name")
|
|
|
|
| 84 |
|
| 85 |
signup_button.click(signup, inputs=[phone, name, email, password], outputs=output)
|
| 86 |
|
| 87 |
+
return signup_demo
|
| 88 |
|
| 89 |
# Main interface
|
| 90 |
with gr.Blocks() as main_interface:
|
| 91 |
gr.Markdown("# Login and Signup System")
|
| 92 |
with gr.Tabs():
|
| 93 |
with gr.Tab("Login"):
|
| 94 |
+
login_demo, main_content = login_interface()
|
| 95 |
+
main_interface.append(main_content)
|
| 96 |
with gr.Tab("Signup"):
|
| 97 |
signup_interface()
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
| 100 |
main_interface.launch()
|
| 101 |
|
| 102 |
+
|