Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,66 +1,60 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
# Sample in-memory database
|
| 4 |
CUSTOMERS = {
|
| 5 |
-
"
|
| 6 |
}
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
else:
|
| 14 |
return "Incorrect password. Please try again."
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
return "
|
| 21 |
-
if not (username and name and password):
|
| 22 |
-
return "All fields are required for registration."
|
| 23 |
-
CUSTOMERS[username] = {"password": password, "name": name}
|
| 24 |
-
return f"Account created successfully for {name}!"
|
| 25 |
|
| 26 |
-
# Gradio
|
| 27 |
def main():
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
-
gr.
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
<h2 style='text-align: center;'>Log In</h2>
|
| 43 |
-
</div>
|
| 44 |
-
</div>
|
| 45 |
-
</div>
|
| 46 |
-
""")
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
login_output = gr.Text(label="Login Status")
|
| 55 |
-
login_button.click(login, inputs=[login_username, login_password], outputs=login_output)
|
| 56 |
-
with gr.Column():
|
| 57 |
-
gr.Markdown("### Register")
|
| 58 |
-
register_username = gr.Textbox(label="Username", placeholder="Choose a username")
|
| 59 |
-
register_name = gr.Textbox(label="Name", placeholder="Enter your name")
|
| 60 |
-
register_password = gr.Textbox(label="Password", placeholder="Set your password", type="password")
|
| 61 |
-
register_button = gr.Button("Register")
|
| 62 |
-
register_output = gr.Text(label="Registration Status")
|
| 63 |
-
register_button.click(register, inputs=[register_username, register_name, register_password], outputs=register_output)
|
| 64 |
|
| 65 |
demo.launch()
|
| 66 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# Sample in-memory database for demonstration
|
| 4 |
CUSTOMERS = {
|
| 5 |
+
"9876543210": {"name": "John Doe", "email": "john@example.com", "password": "password123"}
|
| 6 |
}
|
| 7 |
|
| 8 |
+
def login_or_signup(phone_number, name=None, email=None, password=None):
|
| 9 |
+
"""
|
| 10 |
+
Handles login or sign-up for customers.
|
| 11 |
+
|
| 12 |
+
Args:
|
| 13 |
+
phone_number (str): Customer's phone number.
|
| 14 |
+
name (str, optional): Customer's name (required for sign-up).
|
| 15 |
+
email (str, optional): Customer's email (required for sign-up).
|
| 16 |
+
password (str, optional): Customer's password (required for both login and sign-up).
|
| 17 |
+
|
| 18 |
+
Returns:
|
| 19 |
+
str: Status message about login or sign-up.
|
| 20 |
+
"""
|
| 21 |
+
# Check if phone number exists in the database
|
| 22 |
+
if phone_number in CUSTOMERS:
|
| 23 |
+
# Customer exists, check for login
|
| 24 |
+
if CUSTOMERS[phone_number]["password"] == password:
|
| 25 |
+
return f"Welcome back, {CUSTOMERS[phone_number]['name']}!"
|
| 26 |
else:
|
| 27 |
return "Incorrect password. Please try again."
|
| 28 |
+
else:
|
| 29 |
+
# New customer, proceed with sign-up
|
| 30 |
+
if not all([name, email, password]):
|
| 31 |
+
return "Missing details for sign-up. Please provide Name, Email, and Password."
|
| 32 |
+
CUSTOMERS[phone_number] = {"name": name, "email": email, "password": password}
|
| 33 |
+
return f"Account created successfully for {name}!"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# Gradio Interface
|
| 36 |
def main():
|
| 37 |
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown("### Login or Sign-Up")
|
| 39 |
+
|
| 40 |
+
# Input fields for phone number
|
| 41 |
+
phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
|
| 42 |
+
|
| 43 |
+
# New customer details
|
| 44 |
+
name_input = gr.Textbox(label="Name (For New Customers)", placeholder="Enter your name")
|
| 45 |
+
email_input = gr.Textbox(label="Email (For New Customers)", placeholder="Enter your email")
|
| 46 |
+
password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
|
| 47 |
+
|
| 48 |
+
# Action button
|
| 49 |
+
action_button = gr.Button("Submit")
|
| 50 |
+
result_output = gr.Text(label="Status")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
# Function binding
|
| 53 |
+
action_button.click(
|
| 54 |
+
login_or_signup,
|
| 55 |
+
inputs=[phone_input, name_input, email_input, password_input],
|
| 56 |
+
outputs=result_output
|
| 57 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
demo.launch()
|
| 60 |
|