katospiegel commited on
Commit
c7fe985
·
1 Parent(s): 4f4fff8

Enha: Added logic to dynamically render sections

Browse files
.gitignore CHANGED
@@ -1,3 +1,5 @@
 
 
1
  # Byte-compiled / optimized / DLL files
2
  __pycache__/
3
  *.py[cod]
 
1
+ .DS_Store
2
+
3
  # Byte-compiled / optimized / DLL files
4
  __pycache__/
5
  *.py[cod]
app/assets/destruction.png ADDED
app/assets/indirect.png ADDED
app/assets/natural.png ADDED
app/assets/van.png CHANGED
app/main.py CHANGED
@@ -1,54 +1,72 @@
1
  import gradio as gr
 
2
 
 
 
3
 
 
 
4
 
5
- # def Dropdown_update(category):
6
- # print(category)
7
-
8
- # options_a = ["C","D","E"]
9
- # options_b = ["C","D","E"]
10
- # options_c = ["C","D","E"]
11
-
12
- # if category == "category_a":
13
- # return gr.Dropdown.update(choices=options_a)
14
- # elif category == "category_b":
15
- # return gr.Dropdown.update(choices=options_b)
16
- # elif category == "category_c":
17
- # return gr.Dropdown.update(choices=options_c)
18
 
 
 
 
 
19
 
20
- def truck_dropdown():
21
- return gr.Dropdown(choices=["A", "B", "C", "D"], label="Dropdown1", interactive=True)
 
22
 
23
- def truckb_dropdown():
24
- return gr.Dropdown(choices=["F", "W", "Z", "X"], label="Dropdown2", interactive=True)
25
 
 
 
26
 
27
- def show_tab():
28
- with gr.Tab("Dead/Wounded Information"):
 
 
 
 
29
 
30
  with gr.Row():
31
- with gr.Column(scale=1):
32
- img1 = gr.Image(value='./assets/van.png', show_download_button=False, show_label=False)
33
- butt1 = gr.Button("Violently hit by a drunk driver")
34
-
35
- with gr.Column(scale=1):
36
  img1 = gr.Image(value='./assets/van.png', show_download_button=False, show_label=False)
37
- butt2 = gr.Button("Violently hit by two drunk drivers")
38
 
 
 
 
39
 
40
  with gr.Row():
41
- with gr.Column(scale=1):
42
- img3 = gr.Image(value='./assets/van.png', show_download_button=False, show_label=False)
 
43
 
44
- with gr.Column(scale=1):
45
- img4 = gr.Image(value='./assets/van.png', show_download_button=False, show_label=False)
 
 
46
 
47
  with gr.Row():
48
- dropdown = gr.Dropdown(choices=["A","B"], label="Dropdown", interactive=True)
 
 
 
 
49
 
50
- butt1.click(truck_dropdown, outputs=dropdown)
51
- butt2.click(truckb_dropdown, outputs=dropdown)
52
 
53
 
54
 
@@ -62,12 +80,33 @@ with gr.Blocks() as demo:
62
  with gr.Column(scale=1):
63
  camera = gr.Image()
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- with gr.Column(scale=1):
67
- radio_dead = gr.Radio(choices=["Wounded", "Dead"], label="State of the animal")
68
-
69
- radio_dead.change(show_tab())
70
-
71
  with gr.Column(scale=1):
72
  subbutt = gr.Button("Submit")
73
  output_message = gr.Markdown("Thank you, you didn't save this one but you could save the next")
 
1
  import gradio as gr
2
+ from functools import partial
3
 
4
+ def truck_dropdown():
5
+ return gr.Dropdown(choices=["Road vehicle", "Train", "Aircraft", "Boat", "Other", "Unknown"], label="Collision with a means of transport", interactive=True)
6
 
7
+ def truckb_dropdown():
8
+ return gr.Dropdown(choices=["Hunting", "Trap", "Poisoning", "Removal or direct capture", "Fishing", "Other", "Unkown"], label="Destruction / Deliberatly removed", interactive=True)
9
 
10
+ def show_section_dead(visible):
11
+ with gr.Column(visible=visible) as section_dead:
12
+ gr.Markdown("# Dead")
13
+ gr.Markdown("Please describe the cause of death")
14
+ with gr.Row():
15
+ with gr.Column(scale=1, min_width="100px"):
16
+ img1 = gr.Image(value='./assets/van.png', show_download_button=False, show_label=False)
17
+ butt1 = gr.Button("Collision with a means of transport", visible=visible)
18
+
19
+ with gr.Column(scale=1, min_width="100px"):
20
+ img1 = gr.Image(value='./assets/destruction.png', show_download_button=False, show_label=False)
21
+ butt2 = gr.Button("Destruction / Deliberatly removed", visible=visible)
22
+
23
 
24
+ with gr.Row():
25
+ with gr.Column(scale=1, min_width="100px"):
26
+ img3 = gr.Image(value='./assets/indirect.png', show_download_button=False, show_label=False)
27
+ butt3 = gr.Button("Indirect destruction", visible=visible)
28
 
29
+ with gr.Column(scale=1, min_width="100px"):
30
+ img4 = gr.Image(value='./assets/natural.png', show_download_button=False, show_label=False)
31
+ butt4 = gr.Button("Natural cause", visible=visible)
32
 
 
 
33
 
34
+ with gr.Row():
35
+ dropdown = gr.Dropdown(choices=[], label="Dropdown", interactive=True, visible=visible)
36
 
37
+ return section_dead, butt1, butt2, butt3, butt4, dropdown
38
+
39
+ def show_section_wounded(visible):
40
+ #with gr.Tab("Wounded Information"):
41
+ with gr.Column(visible=visible) as wounded_section:
42
+ gr.Markdown("# Please describe the cause of wound")
43
 
44
  with gr.Row():
45
+ with gr.Column(scale=1, min_width="100px"):
 
 
 
 
46
  img1 = gr.Image(value='./assets/van.png', show_download_button=False, show_label=False)
47
+ butt1 = gr.Button("Collision with a means of transport")
48
 
49
+ with gr.Column(scale=1, min_width="100px"):
50
+ img1 = gr.Image(value='./assets/destruction.png', show_download_button=False, show_label=False)
51
+ butt2 = gr.Button("Destruction / Deliberatly removed")
52
 
53
  with gr.Row():
54
+ with gr.Column(scale=1, min_width="100px"):
55
+ img3 = gr.Image(value='./assets/indirect.png', show_download_button=False, show_label=False)
56
+ butt3 = gr.Button("Indirect destruction")
57
 
58
+ with gr.Column(scale=1, min_width="100px"):
59
+ img4 = gr.Image(value='./assets/natural.png', show_download_button=False, show_label=False)
60
+ butt4 = gr.Button("Natural cause")
61
+
62
 
63
  with gr.Row():
64
+ dropdown = gr.Dropdown(choices=[], label="Dropdown", interactive=True)
65
+
66
+ # Change variables and names
67
+ return wounded_section
68
+
69
 
 
 
70
 
71
 
72
 
 
80
  with gr.Column(scale=1):
81
  camera = gr.Image()
82
 
83
+ with gr.Row() as block_form:
84
+ with gr.Column(scale=1):
85
+ butt_dead = gr.Button("Dead")
86
+
87
+ with gr.Column(scale=1):
88
+ butt_wounded = gr.Button("Wounded")
89
+
90
+ # Initiate sections
91
+ section_dead, butt1, butt2, butt3, butt4, dropdown = show_section_dead(False)
92
+ section_wounded = show_section_wounded(False)
93
+
94
+ # Dead Button Logic
95
+ partial_show_section_dead = partial(show_section_dead, True)
96
+ partial_hide_section_wounded = partial(show_section_wounded, False)
97
+ butt_dead.click(partial_show_section_dead, inputs=None, outputs=[section_dead, butt1, butt2, butt3, butt4, dropdown])
98
+ butt_dead.click(partial_hide_section_wounded, inputs=None, outputs=section_wounded)
99
+
100
+ # Wounded Button Logic
101
+ partial_show_section_wounded = partial(show_section_wounded, True)
102
+ partial_hide_section_dead = partial(show_section_dead, False)
103
+ butt_wounded.click(partial_show_section_wounded, inputs=None, outputs=section_wounded)
104
+ butt_wounded.click(partial_hide_section_dead, inputs=None, outputs=[section_dead, butt1, butt2, butt3, butt4, dropdown])
105
+
106
+ butt1.click(truck_dropdown, outputs=dropdown)
107
+ butt2.click(truckb_dropdown, outputs=dropdown)
108
+ # section_dead.
109
 
 
 
 
 
 
110
  with gr.Column(scale=1):
111
  subbutt = gr.Button("Submit")
112
  output_message = gr.Markdown("Thank you, you didn't save this one but you could save the next")