Spaces:
Sleeping
Sleeping
File size: 1,256 Bytes
cdeb7b2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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()
|