File size: 1,962 Bytes
4b8eb02
56b518b
4b8eb02
536987a
9c80bb7
19a8a5d
56b518b
4fad36f
b700862
18f0e3e
b700862
19a8a5d
902417f
536987a
 
19a8a5d
536987a
 
0e46e0f
19a8a5d
61f1655
 
 
38ca9e6
2789e7c
b700862
902417f
c1fb0a2
56b518b
 
d0997e6
 
56b518b
902417f
 
 
 
56b518b
536987a
56b518b
19a8a5d
902417f
c1fb0a2
57fb682
536987a
38ca9e6
56b518b
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
40
41
42
43
44
45
46
47
import gradio as gr
import os

# Function that controls the visibility of the panels
def check_words(user_text, input_text):
    # If the entered text is "user" and "casa", show Panel 2 and hide Panel 1
    if user_text == os.getenv("USERNAME") and input_text == os.getenv("PASSWORD"):
        return gr.update(visible=True), gr.update(visible=False), gr.update(value=""), gr.update(value="")  # Show Panel 2, hide Panel 1
    else:
        return gr.update(visible=False), gr.update(visible=True), user_text, input_text  # Keep Panel 2 hidden, show Panel 1

# Function to hide Panel 2
def hide_panel():
    return gr.update(visible=False)  # Hide Panel 2

# Function to show Panel 1
def show_panel_1():
    return gr.update(visible=True)  # Show Panel 1

# Wrapper function to hide Panel 2 and show Panel 1 when btn_2 is clicked
def hide_and_show_panel():
    return hide_panel(), show_panel_1()

# Create the Gradio interface
with gr.Blocks() as demo:

    # Create the first panel (visible from the start)
    with gr.Column(visible=True) as panel_1:
        user_text = gr.Textbox(label="User name:")
        input_text = gr.Textbox(label="Password:", type="password")
    
        # First button, visible from the start
        btn_1 = gr.Button("Login")

    # Create the second panel that is initially hidden
    with gr.Column(visible=False) as panel_2:
        # This panel will be shown if the condition is met
        gr.Textbox(value="Login ok", label="Status Login:")
        # Add a second button inside Panel 2 to hide the panel and show Panel 1 again
        btn_2 = gr.Button("Logout", visible=True)
        btn_2.click(hide_and_show_panel, outputs=[panel_2, panel_1])  # Hide Panel 2 and show Panel 1

    # Configure the buttons and the panel visibility
    btn_1.click(check_words, inputs=[user_text, input_text], outputs=[panel_2, panel_1, user_text, input_text])  # Hide Panel 1 and show Panel 2

# Launch the Gradio interface
demo.launch()