项目文件夹

文件
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:17:32 +08:00

46 行
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()