freddyaboulton HF Staff commited on
Commit
e08e6f8
·
verified ·
1 Parent(s): 95c370d

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +8 -8
  2. run.ipynb +1 -0
  3. run.py +45 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Validator Simple
3
- emoji: 🐠
4
- colorFrom: green
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 5.44.1
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: validator_simple
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
+ sdk_version: 5.45.0
9
+ app_file: run.py
10
  pinned: false
11
+ hf_oauth: true
12
  ---
 
 
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: validator_simple"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "\n", "def validate_input(age, location):\n", " return [\n", " gr.validate(not age or age > 3, \"Age must be at least 3\"),\n", " gr.validate(\"london\" not in location.lower(), \"Location must not be in London\"),\n", " ]\n", "\n", "\n", "def process_text(age, location):\n", " return f\"Processed: {age} -- {location.upper()}\"\n", "\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"# Validator Parameter Test Demo\")\n", "\n", " with gr.Row():\n", " with gr.Column():\n", " age = gr.Number(\n", " label=\"Enter age\",\n", " placeholder=\"Enter age\",\n", " )\n", " location = gr.Textbox(\n", " max_lines=3,\n", " label=\"Enter location\",\n", " placeholder=\"Enter location\",\n", " )\n", "\n", " validate_btn = gr.Button(\"Process with Validation\", variant=\"primary\")\n", "\n", " output_with_validation = gr.Textbox(\n", " label=\"Output (with validation)\", interactive=False\n", " )\n", "\n", " validate_btn.click(\n", " fn=process_text,\n", " validator=validate_input,\n", " inputs=[age, location],\n", " outputs=output_with_validation,\n", " )\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ def validate_input(age, location):
5
+ return [
6
+ gr.validate(not age or age > 3, "Age must be at least 3"),
7
+ gr.validate("london" not in location.lower(), "Location must not be in London"),
8
+ ]
9
+
10
+
11
+ def process_text(age, location):
12
+ return f"Processed: {age} -- {location.upper()}"
13
+
14
+
15
+ with gr.Blocks() as demo:
16
+ gr.Markdown("# Validator Parameter Test Demo")
17
+
18
+ with gr.Row():
19
+ with gr.Column():
20
+ age = gr.Number(
21
+ label="Enter age",
22
+ placeholder="Enter age",
23
+ )
24
+ location = gr.Textbox(
25
+ max_lines=3,
26
+ label="Enter location",
27
+ placeholder="Enter location",
28
+ )
29
+
30
+ validate_btn = gr.Button("Process with Validation", variant="primary")
31
+
32
+ output_with_validation = gr.Textbox(
33
+ label="Output (with validation)", interactive=False
34
+ )
35
+
36
+ validate_btn.click(
37
+ fn=process_text,
38
+ validator=validate_input,
39
+ inputs=[age, location],
40
+ outputs=output_with_validation,
41
+ )
42
+
43
+
44
+ if __name__ == "__main__":
45
+ demo.launch()