Commit 1: Add 50 file(s)
Browse files- README.md +1 -1
- demos/blocks_essay/run.ipynb +1 -1
- demos/blocks_essay/run.py +2 -3
README.md
CHANGED
@@ -5,7 +5,7 @@ emoji: 💩
|
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
-
sdk_version: 5.16.
|
9 |
app_file: run.py
|
10 |
pinned: false
|
11 |
---
|
|
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
+
sdk_version: 5.16.1
|
9 |
app_file: run.py
|
10 |
pinned: false
|
11 |
---
|
demos/blocks_essay/run.ipynb
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_essay"]}, {"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", "countries_cities_dict = {\n", " \"USA\": [\"New York\", \"Los Angeles\", \"Chicago\"],\n", " \"Canada\": [\"Toronto\", \"Montreal\", \"Vancouver\"],\n", " \"Pakistan\": [\"Karachi\", \"Lahore\", \"Islamabad\"],\n", "}\n", "\n", "def change_textbox(choice
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_essay"]}, {"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", "countries_cities_dict = {\n", " \"USA\": [\"New York\", \"Los Angeles\", \"Chicago\"],\n", " \"Canada\": [\"Toronto\", \"Montreal\", \"Vancouver\"],\n", " \"Pakistan\": [\"Karachi\", \"Lahore\", \"Islamabad\"],\n", "}\n", "\n", "def change_textbox(choice):\n", " if choice == \"short\":\n", " return gr.Textbox(lines=2, visible=True), gr.Button(interactive=True)\n", " elif choice == \"long\":\n", " return gr.Textbox(lines=8, visible=True, value=\"Lorem ipsum dolor sit amet\"), gr.Button(interactive=True)\n", " else:\n", " return gr.Textbox(visible=False), gr.Button(interactive=False)\n", "\n", "with gr.Blocks() as demo:\n", " radio = gr.Radio(\n", " [\"short\", \"long\", \"none\"], label=\"What kind of essay would you like to write?\"\n", " )\n", " text = gr.Textbox(lines=2, interactive=True, show_copy_button=True)\n", "\n", " with gr.Row():\n", " num = gr.Number(minimum=0, maximum=100, label=\"input\")\n", " out = gr.Number(label=\"output\")\n", " minimum_slider = gr.Slider(0, 100, 0, label=\"min\")\n", " maximum_slider = gr.Slider(0, 100, 100, label=\"max\")\n", " submit_btn = gr.Button(\"Submit\", variant=\"primary\")\n", "\n", " with gr.Row():\n", " country = gr.Dropdown(list(countries_cities_dict.keys()), label=\"Country\")\n", " cities = gr.Dropdown([], label=\"Cities\")\n", " @country.change(inputs=country, outputs=cities)\n", " def update_cities(country):\n", " cities = list(countries_cities_dict[country])\n", " return gr.Dropdown(choices=cities, value=cities[0], interactive=True)\n", "\n", " def reset_bounds(minimum, maximum):\n", " return gr.Number(minimum=minimum, maximum=maximum)\n", "\n", " radio.change(fn=change_textbox, inputs=radio, outputs=[text, submit_btn])\n", " gr.on(\n", " [minimum_slider.change, maximum_slider.change],\n", " reset_bounds,\n", " [minimum_slider, maximum_slider],\n", " outputs=num,\n", " )\n", " num.submit(lambda x: x, num, out)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/blocks_essay/run.py
CHANGED
@@ -6,7 +6,7 @@ countries_cities_dict = {
|
|
6 |
"Pakistan": ["Karachi", "Lahore", "Islamabad"],
|
7 |
}
|
8 |
|
9 |
-
def change_textbox(choice
|
10 |
if choice == "short":
|
11 |
return gr.Textbox(lines=2, visible=True), gr.Button(interactive=True)
|
12 |
elif choice == "long":
|
@@ -30,7 +30,6 @@ with gr.Blocks() as demo:
|
|
30 |
with gr.Row():
|
31 |
country = gr.Dropdown(list(countries_cities_dict.keys()), label="Country")
|
32 |
cities = gr.Dropdown([], label="Cities")
|
33 |
-
|
34 |
@country.change(inputs=country, outputs=cities)
|
35 |
def update_cities(country):
|
36 |
cities = list(countries_cities_dict[country])
|
@@ -39,7 +38,7 @@ with gr.Blocks() as demo:
|
|
39 |
def reset_bounds(minimum, maximum):
|
40 |
return gr.Number(minimum=minimum, maximum=maximum)
|
41 |
|
42 |
-
radio.change(fn=change_textbox, inputs=radio, outputs=[text, submit_btn]
|
43 |
gr.on(
|
44 |
[minimum_slider.change, maximum_slider.change],
|
45 |
reset_bounds,
|
|
|
6 |
"Pakistan": ["Karachi", "Lahore", "Islamabad"],
|
7 |
}
|
8 |
|
9 |
+
def change_textbox(choice):
|
10 |
if choice == "short":
|
11 |
return gr.Textbox(lines=2, visible=True), gr.Button(interactive=True)
|
12 |
elif choice == "long":
|
|
|
30 |
with gr.Row():
|
31 |
country = gr.Dropdown(list(countries_cities_dict.keys()), label="Country")
|
32 |
cities = gr.Dropdown([], label="Cities")
|
|
|
33 |
@country.change(inputs=country, outputs=cities)
|
34 |
def update_cities(country):
|
35 |
cities = list(countries_cities_dict[country])
|
|
|
38 |
def reset_bounds(minimum, maximum):
|
39 |
return gr.Number(minimum=minimum, maximum=maximum)
|
40 |
|
41 |
+
radio.change(fn=change_textbox, inputs=radio, outputs=[text, submit_btn])
|
42 |
gr.on(
|
43 |
[minimum_slider.change, maximum_slider.change],
|
44 |
reset_bounds,
|