adf0d17497
publish / version_or_publish (push) Has been cancelled
storybook-build / changes (push) Has been cancelled
storybook-build / :storybook-build (push) Has been cancelled
Sync Gradio Skills to Hugging Face / sync-skills (push) Has been cancelled
functional / changes (push) Has been cancelled
functional / build-frontend (push) Has been cancelled
functional / functional-test-SSR=false (push) Has been cancelled
functional / functional-reload (push) Has been cancelled
js / changes (push) Has been cancelled
js / js-test (push) Has been cancelled
docs-build / changes (push) Has been cancelled
docs-build / docs-build (push) Has been cancelled
docs-build / website-build (push) Has been cancelled
functional / functional-test-SSR=true (push) Has been cancelled
hygiene / hygiene-test (push) Has been cancelled
python / changes (push) Has been cancelled
python / build (push) Has been cancelled
python / test-ubuntu-latest-flaky (push) Has been cancelled
python / test-ubuntu-latest-not-flaky (push) Has been cancelled
python / test-windows-latest-flaky (push) Has been cancelled
python / test-windows-latest-not-flaky (push) Has been cancelled
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
import gradio as gr
|
|
|
|
|
|
def validate_input(age, location):
|
|
return [
|
|
gr.validate(not age or age > 3, "Age must be at least 3"),
|
|
gr.validate("london" not in location.lower(), "Location must not be in London"),
|
|
]
|
|
|
|
|
|
def process_text(age, location):
|
|
return f"Processed: {age} -- {location.upper()}"
|
|
|
|
|
|
with gr.Blocks() as demo:
|
|
gr.Markdown("# Validator Parameter Test Demo")
|
|
|
|
with gr.Row():
|
|
with gr.Column():
|
|
age = gr.Number(
|
|
label="Enter age",
|
|
placeholder="Enter age",
|
|
)
|
|
location = gr.Textbox(
|
|
max_lines=3,
|
|
label="Enter location",
|
|
placeholder="Enter location",
|
|
)
|
|
|
|
validate_btn = gr.Button("Process with Validation", variant="primary")
|
|
|
|
output_with_validation = gr.Textbox(
|
|
label="Output (with validation)", interactive=False
|
|
)
|
|
|
|
validate_btn.click(
|
|
fn=process_text,
|
|
validator=validate_input,
|
|
inputs=[age, location],
|
|
outputs=output_with_validation,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch()
|