File size: 1,460 Bytes
1dc5e96
 
cc5f090
 
 
 
1dc5e96
df37867
 
 
 
 
 
 
ffa7a31
 
 
 
 
 
 
cc5f090
df37867
 
cc5f090
f69abf9
df37867
 
1dc5e96
df37867
 
 
 
 
 
 
 
 
 
 
 
96c8645
df37867
 
 
 
 
 
 
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
48
49
50
import os

import gradio as gr


def enable_second_task(secret):
    if secret == os.environ["SECRET_KEY"]:
        return [
            gr.Textbox.update(visible=False),
            gr.Button.update(visible=False),
            gr.Textbox.update(visible=True),
            gr.Textbox.update(visible=True),
            gr.Button.update(visible=True)                                                
        ]
    return [
        gr.Textbox.update(visible=True),
        gr.Button.update(visible=True),
        gr.Textbox.update(visible=False),
        gr.Textbox.update(visible=False),
        gr.Button.update(visible=False)                                                
    ]

def greet(name):
    return "Hello " + name + "!!"

demo = gr.Blocks()
with demo:
    secret_textbox = gr.Textbox(
        placeholder="Enter secret key", label="Secret", show_label=True
    )    
    secret_button = gr.Button("Submit")
    
    name_textbox = gr.Textbox(
        placeholder="Name", label="Name", show_label=True, visible=False
    )
    greet_textbox = gr.Textbox(
        placeholder="", label="Output", show_label=True, visible=False
    )    
    greet_button = gr.Button("Greet", visible=False)    
    
    
    secret_button.click(
        enable_second_task,
        secret_textbox,
        [secret_textbox, secret_button, name_textbox, greet_textbox, greet_button]
    )
    greet_button.click(greet, name_textbox, greet_textbox)    
    
demo.launch()