aliabd HF Staff commited on
Commit
1a17281
·
1 Parent(s): d60e3a4

Upload with huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +5 -5
  2. app.py +46 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Blocks Update
3
  emoji: 🔥
4
- colorFrom: pink
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 3.3.1
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: blocks_update
4
  emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 3.3.1
9
+
10
  app_file: app.py
11
  pinned: false
12
  ---
 
 
app.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()