Spaces:
Sleeping
Sleeping
on1onmangoes
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
# Define a function for the main application
|
4 |
+
def greet(name):
|
5 |
+
return f"Hello {name}!"
|
6 |
+
|
7 |
+
# Define a function for the authentication
|
8 |
+
def login(username, password):
|
9 |
+
if username == "your_username" and password == "your_password":
|
10 |
+
return True
|
11 |
+
else:
|
12 |
+
return False
|
13 |
+
|
14 |
+
# Create the Gradio Blocks interface
|
15 |
+
with gr.Blocks() as app:
|
16 |
+
gr.Markdown("### Login")
|
17 |
+
|
18 |
+
with gr.Row():
|
19 |
+
username_input = gr.Textbox(label="Username", placeholder="Enter your username")
|
20 |
+
password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
|
21 |
+
|
22 |
+
login_button = gr.Button("Login")
|
23 |
+
output_text = gr.Textbox(label="Output", interactive=False)
|
24 |
+
|
25 |
+
# Function to handle login and display greeting
|
26 |
+
def handle_login(username, password):
|
27 |
+
if login(username, password):
|
28 |
+
# Clear the password field and display the greeting
|
29 |
+
password_input.clear()
|
30 |
+
return greet(username)
|
31 |
+
else:
|
32 |
+
return "Invalid credentials! Please try again."
|
33 |
+
|
34 |
+
# Bind the button click to the handle_login function
|
35 |
+
login_button.click(handle_login, inputs=[username_input, password_input], outputs=output_text)
|
36 |
+
|
37 |
+
# Launch the app
|
38 |
+
app.launch()
|