Spaces:
Sleeping
Sleeping
Upload with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -5,8 +5,7 @@ emoji: 🔥
|
|
| 5 |
colorFrom: indigo
|
| 6 |
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
-
sdk_version: 3.
|
| 9 |
-
|
| 10 |
-
app_file: app.py
|
| 11 |
pinned: false
|
| 12 |
---
|
|
|
|
| 5 |
colorFrom: indigo
|
| 6 |
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
+
sdk_version: 3.4.1
|
| 9 |
+
app_file: run.py
|
|
|
|
| 10 |
pinned: false
|
| 11 |
---
|
run.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
with gr.Blocks() as demo:
|
| 4 |
+
gr.Markdown(
|
| 5 |
+
"""
|
| 6 |
+
# Animal Generator
|
| 7 |
+
Once you select a species, the detail panel should be visible.
|
| 8 |
+
"""
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
species = gr.Radio(label="Animal Class", choices=["Mammal", "Fish", "Bird"])
|
| 12 |
+
animal = gr.Dropdown(label="Animal", choices=[])
|
| 13 |
+
|
| 14 |
+
with gr.Column(visible=False) as details_col:
|
| 15 |
+
weight = gr.Slider(0, 20)
|
| 16 |
+
details = gr.Textbox(label="Extra Details")
|
| 17 |
+
generate_btn = gr.Button("Generate")
|
| 18 |
+
output = gr.Textbox(label="Output")
|
| 19 |
+
|
| 20 |
+
species_map = {
|
| 21 |
+
"Mammal": ["Elephant", "Giraffe", "Hamster"],
|
| 22 |
+
"Fish": ["Shark", "Salmon", "Tuna"],
|
| 23 |
+
"Bird": ["Chicken", "Eagle", "Hawk"],
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
def filter_species(species):
|
| 27 |
+
return gr.Dropdown.update(
|
| 28 |
+
choices=species_map[species], value=species_map[species][1]
|
| 29 |
+
), gr.update(visible=True)
|
| 30 |
+
|
| 31 |
+
species.change(filter_species, species, [animal, details_col])
|
| 32 |
+
|
| 33 |
+
def filter_weight(animal):
|
| 34 |
+
if animal in ("Elephant", "Shark", "Giraffe"):
|
| 35 |
+
return gr.update(maximum=100)
|
| 36 |
+
else:
|
| 37 |
+
return gr.update(maximum=20)
|
| 38 |
+
|
| 39 |
+
animal.change(filter_weight, animal, weight)
|
| 40 |
+
weight.change(lambda w: gr.update(lines=int(w / 10) + 1), weight, details)
|
| 41 |
+
|
| 42 |
+
generate_btn.click(lambda x: x, details, output)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
demo.launch()
|