|
import gradio as gr |
|
from login import login |
|
from protected_content import protected_content |
|
|
|
def create_login_interface(): |
|
with gr.Column() as login_interface: |
|
gr.Markdown("# Login") |
|
username_input = gr.Textbox(label="Username") |
|
password_input = gr.Textbox(label="Password", type="password") |
|
login_button = gr.Button("Login") |
|
result = gr.Textbox(label="Result") |
|
return login_interface, username_input, password_input, login_button, result |
|
|
|
def create_protected_interface(): |
|
with gr.Column(visible=False) as protected_interface: |
|
gr.Markdown("# Protected Content") |
|
content = gr.Textbox(label="Content", value=protected_content()) |
|
return protected_interface |
|
|
|
|
|
with gr.Blocks() as app: |
|
login_interface, username_input, password_input, login_button, login_result = create_login_interface() |
|
protected_interface = create_protected_interface() |
|
|
|
def on_login_submit(username, password): |
|
success, message = login(username, password) |
|
if success: |
|
return { |
|
login_interface: gr.update(visible=False), |
|
protected_interface: gr.update(visible=True), |
|
login_result: gr.update(value="Login successful!") |
|
} |
|
else: |
|
return { |
|
login_result: gr.update(value=message) |
|
} |
|
|
|
login_button.click( |
|
on_login_submit, |
|
inputs=[username_input, password_input], |
|
outputs=[login_interface, protected_interface, login_result] |
|
) |