import os import gradio as gr def enable_second_task(secret): if secret == os.environ["SECRET_KEY"]: return [ gr.Textbox.update(visible=False), gr.HTML.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(value="", visible=True), gr.HTML.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: # Authentication secret_textbox = gr.Textbox( placeholder="Enter secret key", label="Secret", show_label=True, max_lines=1 ) error_message = gr.HTML( "Wrong secret key. Please retry", visible=False ) secret_button = gr.Button("Submit") # Demo logic 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) # Event handling secret_textbox.submit( enable_second_task, secret_textbox, [secret_textbox, error_message, secret_button, name_textbox, greet_textbox, greet_button] ) secret_button.click( enable_second_task, secret_textbox, [secret_textbox, error_message, secret_button, name_textbox, greet_textbox, greet_button] ) greet_button.click(greet, name_textbox, greet_textbox) demo.launch()