Spaces:
Build error
Build error
| 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() | |