Spaces:
Sleeping
Sleeping
import gradio as gr | |
# Define a function for the main application | |
def greet(name): | |
return f"Hello {name}!" | |
# Define a function for the authentication | |
def login(username, password): | |
if username == "your_username" and password == "your_password": | |
return True | |
else: | |
return False | |
# Create the Gradio Blocks interface | |
with gr.Blocks() as app: | |
gr.Markdown("### Login") | |
with gr.Row(): | |
username_input = gr.Textbox(label="Username", placeholder="Enter your username") | |
password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password") | |
login_button = gr.Button("Login") | |
output_text = gr.Textbox(label="Output", interactive=False) | |
# Function to handle login and display greeting | |
def handle_login(username, password): | |
if login(username, password): | |
# Clear the password field and display the greeting | |
password_input.clear() | |
return greet(username) | |
else: | |
return "Invalid credentials! Please try again." | |
# Bind the button click to the handle_login function | |
login_button.click(handle_login, inputs=[username_input, password_input], outputs=output_text) | |
# Launch the app | |
app.launch() | |