Spaces:
Build error
Build error
File size: 1,037 Bytes
25a1345 |
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 |
import gradio as gr
# Function to validate the input and enable/disable the button
def validate_input(text):
error_msg = ""
button_state = False
if len(text.strip()) < 3:
error_msg = "_Input_ must be at least 3 characters."
button_state = False
else:
button_state = True
return gr.update(value=error_msg), gr.update(interactive=button_state)
# Function that runs when the button is clicked
def on_submit(text):
return f"Processed: {text.strip()}"
with gr.Blocks() as demo:
gr.Markdown("### Input Validation Example")
inp = gr.Textbox(label="Enter something")
validation = gr.Label(value="", visible=True)
btn = gr.Button("Submit", interactive=False)
out = gr.Textbox(label="Output", interactive=False)
# When the input changes, validate it and enable/disable the button
inp.change(validate_input, inputs=inp, outputs=[validation, btn])
# When the button is clicked, process the input
btn.click(on_submit, inputs=inp, outputs=out)
demo.launch()
|