mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-21 01:01:05 +08:00
9b42ba8f10
* changes * changes * revert changes * changes * add changeset * notebooks script * changes * changes --------- Co-authored-by: Ali Abid <aliabid94@gmail.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import gradio as gr
|
|
|
|
with gr.Blocks() as demo:
|
|
gr.Markdown(
|
|
"""
|
|
# Animal Generator
|
|
Once you select a species, the detail panel should be visible.
|
|
"""
|
|
)
|
|
|
|
species = gr.Radio(label="Animal Class", choices=["Mammal", "Fish", "Bird"])
|
|
animal = gr.Dropdown(label="Animal", choices=[])
|
|
|
|
with gr.Column(visible=False) as details_col:
|
|
weight = gr.Slider(0, 20)
|
|
details = gr.Textbox(label="Extra Details")
|
|
generate_btn = gr.Button("Generate")
|
|
output = gr.Textbox(label="Output")
|
|
|
|
species_map = {
|
|
"Mammal": ["Elephant", "Giraffe", "Hamster"],
|
|
"Fish": ["Shark", "Salmon", "Tuna"],
|
|
"Bird": ["Chicken", "Eagle", "Hawk"],
|
|
}
|
|
|
|
def filter_species(species):
|
|
return gr.Dropdown(
|
|
choices=species_map[species], value=species_map[species][1]
|
|
), gr.Column(visible=True)
|
|
|
|
species.change(filter_species, species, [animal, details_col])
|
|
|
|
def filter_weight(animal):
|
|
if animal in ("Elephant", "Shark", "Giraffe"):
|
|
return gr.Slider(maximum=100)
|
|
else:
|
|
return gr.Slider(maximum=20)
|
|
|
|
animal.change(filter_weight, animal, weight)
|
|
weight.change(lambda w: gr.Textbox(lines=int(w / 10) + 1), weight, details)
|
|
|
|
generate_btn.click(lambda x: x, details, output)
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch()
|