anferico's picture
Update app.py
1dc5e96
raw
history blame
1.46 kB
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()