Spaces:
Sleeping
Sleeping
File size: 1,866 Bytes
1a6eacf |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import gradio as gr
countries_cities_dict = {
"USA": ["New York", "Los Angeles", "Chicago"],
"Canada": ["Toronto", "Montreal", "Vancouver"],
"Pakistan": ["Karachi", "Lahore", "Islamabad"],
}
def change_textbox(choice):
if choice == "short":
return gr.Textbox(lines=2, visible=True), gr.Button(interactive=True)
elif choice == "long":
return gr.Textbox(lines=8, visible=True, value="Lorem ipsum dolor sit amet"), gr.Button(interactive=True)
else:
return gr.Textbox(visible=False), gr.Button(interactive=False)
with gr.Blocks() as demo:
radio = gr.Radio(
["short", "long", "none"], label="What kind of essay would you like to write?"
)
text = gr.Textbox(lines=2, interactive=True, show_copy_button=True)
with gr.Row():
num = gr.Number(minimum=0, maximum=100, label="input")
out = gr.Number(label="output")
minimum_slider = gr.Slider(0, 100, 0, label="min")
maximum_slider = gr.Slider(0, 100, 100, label="max")
submit_btn = gr.Button("Submit", variant="primary")
with gr.Row():
country = gr.Dropdown(list(countries_cities_dict.keys()), label="Country")
cities = gr.Dropdown([], label="Cities")
@country.change(inputs=country, outputs=cities)
def update_cities(country):
cities = list(countries_cities_dict[country])
return gr.Dropdown(choices=cities, value=cities[0], interactive=True)
def reset_bounds(minimum, maximum):
return gr.Number(minimum=minimum, maximum=maximum)
radio.change(fn=change_textbox, inputs=radio, outputs=[text, submit_btn])
gr.on(
[minimum_slider.change, maximum_slider.change],
reset_bounds,
[minimum_slider, maximum_slider],
outputs=num,
)
num.submit(lambda x: x, num, out)
if __name__ == "__main__":
demo.launch()
|