vancauwe commited on
Commit
0de94b5
·
1 Parent(s): 923fa20

feat: follow up events collect inputs

Browse files
Files changed (4) hide show
  1. app/dead.py +11 -3
  2. app/followup_events.py +41 -12
  3. app/main_multianimal.py +43 -9
  4. app/wounded.py +10 -4
app/dead.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  from circumstances import create_causes
3
- from followup_events import create_followup_section
4
  from utils_json import add_data_to_individual
5
 
6
  def show_section_dead(visible):
@@ -14,6 +14,14 @@ def show_section_dead(visible):
14
 
15
  button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_causes(visible)
16
 
17
- create_followup_section()
 
 
 
 
 
18
 
19
- return section_dead, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2
 
 
 
 
1
  import gradio as gr
2
  from circumstances import create_causes
3
+ from followup_events import create_followup_dropdowns, create_followup_open
4
  from utils_json import add_data_to_individual
5
 
6
  def show_section_dead(visible):
 
14
 
15
  button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_causes(visible)
16
 
17
+ gr.Markdown("## Follow-Up Events", label="Title")
18
+ gr.Markdown("Please tell us what you did with the animal.", label="description")
19
+ with gr.Row():
20
+ fe_collection_dropdown, fe_recepient_dropdown, fe_radio_dropdown, fe_answer_dropdown = create_followup_dropdowns(visible, "dead")
21
+ with gr.Row():
22
+ fe_name_recipient, fe_collection_ref = create_followup_open(visible, "dead")
23
 
24
+
25
+ return section_dead, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, \
26
+ dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, \
27
+ fe_collection_dropdown, fe_recepient_dropdown, fe_radio_dropdown, fe_answer_dropdown, fe_name_recipient, fe_collection_ref
app/followup_events.py CHANGED
@@ -1,17 +1,46 @@
1
  import gradio as gr
2
  from utils_config import get_custom_config_dropdowns
 
3
 
4
- def create_followup_section():
5
  followup_config = get_custom_config_dropdowns("config_followup.json")
6
  followup_config = followup_config["Event follow-up"]
7
- gr.Markdown("Please tell us what you did with the animal.", label="description")
8
- with gr.Row():
9
- for key, val in followup_config.items():
10
- followup_label = key
11
- if "Options" in val.keys():
12
- gr.Dropdown(choices=val["Options"], label=followup_label, visible=True, elem_id="followup")
13
- with gr.Row():
14
- for key, val in followup_config.items():
15
- followup_label = key
16
- if "Open" in val.keys():
17
- gr.Textbox(label=followup_label, visible=True, elem_id="followup")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from utils_config import get_custom_config_dropdowns
3
+ from utils_json import add_data_to_individual
4
 
5
+ def create_followup_dropdowns(visible, elem_id):
6
  followup_config = get_custom_config_dropdowns("config_followup.json")
7
  followup_config = followup_config["Event follow-up"]
8
+ fe_collection_dropdown = create_fe_collection_dropdown(followup_config, visible, elem_id)
9
+ fe_recipient_dropdown = create_fe_recipient_dropdown(followup_config, visible, elem_id)
10
+ fe_radio_dropdown = create_fe_radio_dropdown(followup_config, visible, elem_id)
11
+ fe_answer_dropdown = create_fe_answer_dropdown(followup_config, visible, elem_id)
12
+ return fe_collection_dropdown, fe_recipient_dropdown, fe_radio_dropdown, fe_answer_dropdown
13
+
14
+ def create_followup_open(visible, elem_id):
15
+ fe_name_recipient = gr.Textbox(label="Name of recipient / museum", visible=visible,
16
+ elem_id=elem_id, interactive=True)
17
+ fe_collection_ref = gr.Textbox(label="Collection reference", visible=visible,
18
+ elem_id=elem_id, interactive=True)
19
+ return fe_name_recipient, fe_collection_ref
20
+
21
+
22
+ def create_fe_collection_dropdown(followup_config, visible, elem_id):
23
+ fe_collection_dropdown = gr.Dropdown(choices=followup_config["Animal collected"]["Options"], label="Animal collected",
24
+ visible=visible, elem_id=elem_id, interactive=True)
25
+ return fe_collection_dropdown
26
+
27
+ def create_fe_recipient_dropdown(followup_config, visible, elem_id):
28
+ fe_recipient_dropdown = gr.Dropdown(choices=followup_config["Recipient"]["Options"], label="Recipient",
29
+ visible=visible, elem_id=elem_id, interactive=True)
30
+ return fe_recipient_dropdown
31
+
32
+ def create_fe_radio_dropdown(followup_config, visible, elem_id):
33
+ fe_radio_dropdown = gr.Dropdown(choices=followup_config["Radiography"]["Options"], label="Radiography",
34
+ visible=visible, elem_id=elem_id, interactive=True)
35
+ return fe_radio_dropdown
36
+
37
+ def create_fe_answer_dropdown(followup_config, visible, elem_id):
38
+ fe_answer_dropdown = gr.Dropdown(choices=followup_config["Given answer"]["Options"], label="Given answer",
39
+ visible=visible, elem_id=elem_id, interactive=True)
40
+ return fe_answer_dropdown
41
+
42
+ def save_fe(value, key):
43
+ add_data_to_individual(key, value)
44
+
45
+
46
+
app/main_multianimal.py CHANGED
@@ -12,6 +12,7 @@ from circumstances_dropdowns import *
12
  from physical_select_animal import show_physical, find_bounding_box
13
  from physical_checkbox import on_select_body_part, hide_physical
14
  from behavior_checkbox import show_behavior, on_select_behavior
 
15
  from style import *
16
  from theme import theme, css
17
 
@@ -77,15 +78,19 @@ with gr.Blocks(theme=theme, css=css) as demo:
77
  # Initiate sections
78
  section_dead, \
79
  button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
80
- dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead \
 
 
81
  = show_section_dead(False)
82
  section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
83
  button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
84
  dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
85
  behavior_checkbox, behavior_text, \
86
  physical_boxes_wounded, \
87
- checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
88
- = show_section_wounded(False)
 
 
89
 
90
  # ---------------------------------------------------------
91
  # ---------------------------------------------------------
@@ -97,7 +102,9 @@ with gr.Blocks(theme=theme, css=css) as demo:
97
  inputs=None,
98
  outputs=[section_dead,
99
  button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
100
- dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead
 
 
101
  ])
102
  butt_dead.click(partial_hide_section_wounded,
103
  inputs=None,
@@ -107,7 +114,9 @@ with gr.Blocks(theme=theme, css=css) as demo:
107
  dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
108
  behavior_checkbox, behavior_text,
109
  physical_boxes_wounded,
110
- checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
 
 
111
  ])
112
  # ---------------------------------------------------------
113
  # Wounded Button Logic
@@ -122,11 +131,15 @@ with gr.Blocks(theme=theme, css=css) as demo:
122
  dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
123
  behavior_checkbox, behavior_text,
124
  physical_boxes_wounded,
125
- checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
 
 
126
  ])
127
  butt_wounded.click(partial_hide_section_dead, inputs=None, outputs=[section_dead,
128
  button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
129
- dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead
 
 
130
  ])
131
  # ---------------------------------------------------------
132
  # Dropdowns Dead
@@ -186,6 +199,24 @@ with gr.Blocks(theme=theme, css=css) as demo:
186
  checkbox_feathers.select(on_select_body_part, inputs=[checkbox_feathers, gr.Text("feathers", visible=False)])
187
  checkbox_head.select(on_select_body_part, inputs=[checkbox_head, gr.Text("head", visible=False)])
188
  checkbox_legs.select(on_select_body_part, inputs=[checkbox_legs, gr.Text("legs", visible=False)])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
 
190
  # ---------------------------------------------------------
191
  # Add One Individual's Data to the Dataframe
@@ -198,14 +229,17 @@ with gr.Blocks(theme=theme, css=css) as demo:
198
  location, identified_location,
199
  button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
200
  dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
 
 
201
  radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded,
202
  button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
203
  dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
204
  behavior_checkbox, behavior_text,
205
  physical_boxes_wounded,
206
- checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
 
 
207
  ])
208
-
209
  button_clear.click()
210
  button_clear.click(hide_physical,
211
  outputs=[checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs])
 
12
  from physical_select_animal import show_physical, find_bounding_box
13
  from physical_checkbox import on_select_body_part, hide_physical
14
  from behavior_checkbox import show_behavior, on_select_behavior
15
+ from followup_events import save_fe
16
  from style import *
17
  from theme import theme, css
18
 
 
78
  # Initiate sections
79
  section_dead, \
80
  button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
81
+ dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
82
+ fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
83
+ fe_name_recipient_dead, fe_collection_ref_dead \
84
  = show_section_dead(False)
85
  section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
86
  button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
87
  dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
88
  behavior_checkbox, behavior_text, \
89
  physical_boxes_wounded, \
90
+ checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs, \
91
+ fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
92
+ fe_name_recipient_wounded, fe_collection_ref_wounded \
93
+ = show_section_wounded(False)
94
 
95
  # ---------------------------------------------------------
96
  # ---------------------------------------------------------
 
102
  inputs=None,
103
  outputs=[section_dead,
104
  button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
105
+ dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
106
+ fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
107
+ fe_name_recipient_dead, fe_collection_ref_dead \
108
  ])
109
  butt_dead.click(partial_hide_section_wounded,
110
  inputs=None,
 
114
  dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
115
  behavior_checkbox, behavior_text,
116
  physical_boxes_wounded,
117
+ checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs, \
118
+ fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
119
+ fe_name_recipient_wounded, fe_collection_ref_wounded \
120
  ])
121
  # ---------------------------------------------------------
122
  # Wounded Button Logic
 
131
  dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
132
  behavior_checkbox, behavior_text,
133
  physical_boxes_wounded,
134
+ checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs, \
135
+ fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
136
+ fe_name_recipient_wounded, fe_collection_ref_wounded \
137
  ])
138
  butt_wounded.click(partial_hide_section_dead, inputs=None, outputs=[section_dead,
139
  button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
140
+ dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
141
+ fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
142
+ fe_name_recipient_dead, fe_collection_ref_dead \
143
  ])
144
  # ---------------------------------------------------------
145
  # Dropdowns Dead
 
199
  checkbox_feathers.select(on_select_body_part, inputs=[checkbox_feathers, gr.Text("feathers", visible=False)])
200
  checkbox_head.select(on_select_body_part, inputs=[checkbox_head, gr.Text("head", visible=False)])
201
  checkbox_legs.select(on_select_body_part, inputs=[checkbox_legs, gr.Text("legs", visible=False)])
202
+
203
+ # ---------------------------------------------------------
204
+ # Follow Up Events Wounded
205
+ fe_collection_dropdown_wounded.select(save_fe, inputs=[fe_collection_dropdown_wounded, gr.Textbox("fe_collection", visible=False)])
206
+ fe_recepient_dropdown_wounded.select(save_fe, inputs=[fe_recepient_dropdown_wounded, gr.Textbox("fe_recipient", visible=False)])
207
+ fe_radio_dropdown_wounded.select(save_fe, inputs=[fe_radio_dropdown_wounded, gr.Textbox("fe_radio", visible=False)])
208
+ fe_answer_dropdown_wounded.select(save_fe, inputs=[fe_answer_dropdown_wounded, gr.Textbox("fe_answer", visible=False)])
209
+ fe_name_recipient_wounded.input(save_fe, inputs=[fe_name_recipient_wounded, gr.Textbox("fe_name_recipient", visible=False)])
210
+ fe_collection_ref_wounded.input(save_fe, inputs=[fe_collection_ref_wounded, gr.Textbox("fe_collection_ref", visible=False)])
211
+
212
+ # ---------------------------------------------------------
213
+ # Follow Up Events Dead
214
+ fe_collection_dropdown_dead.select(save_fe, inputs=[fe_collection_dropdown_dead, gr.Textbox("fe_collection", visible=False)])
215
+ fe_recepient_dropdown_dead.select(save_fe, inputs=[fe_recepient_dropdown_dead, gr.Textbox("fe_recipient", visible=False)])
216
+ fe_radio_dropdown_dead.select(save_fe, inputs=[fe_radio_dropdown_dead, gr.Textbox("fe_radio", visible=False)])
217
+ fe_answer_dropdown_dead.select(save_fe, inputs=[fe_answer_dropdown_dead, gr.Textbox("fe_answer", visible=False)])
218
+ fe_name_recipient_dead.input(save_fe, inputs=[fe_name_recipient_dead, gr.Textbox("fe_name_recipient", visible=False)])
219
+ fe_collection_ref_dead.input(save_fe, inputs=[fe_collection_ref_dead, gr.Textbox("fe_collection_ref", visible=False)])
220
 
221
  # ---------------------------------------------------------
222
  # Add One Individual's Data to the Dataframe
 
229
  location, identified_location,
230
  button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
231
  dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
232
+ fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead,
233
+ fe_name_recipient_dead, fe_collection_ref_dead,
234
  radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded,
235
  button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
236
  dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
237
  behavior_checkbox, behavior_text,
238
  physical_boxes_wounded,
239
+ checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs,
240
+ fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded,
241
+ fe_name_recipient_wounded, fe_collection_ref_wounded
242
  ])
 
243
  button_clear.click()
244
  button_clear.click(hide_physical,
245
  outputs=[checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs])
app/wounded.py CHANGED
@@ -3,7 +3,7 @@ from circumstances import create_causes
3
  from physical_select_animal import create_bird_anatomy
4
  from physical_checkbox import process_body_parts
5
  from behavior_checkbox import create_behavior_checkbox
6
- from followup_events import create_followup_section
7
  from utils_json import add_data_to_individual
8
 
9
  def show_section_wounded(visible):
@@ -30,9 +30,14 @@ def show_section_wounded(visible):
30
  with gr.Column():
31
  checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs = process_body_parts("wounded", "None")
32
 
33
-
34
  gr.Markdown("## Follow-Up Events", label="Title")
35
- create_followup_section()
 
 
 
 
 
36
 
37
  # Change variables and names
38
  return wounded_section, radio_cause, radio_behaviour, radio_physical, \
@@ -40,4 +45,5 @@ def show_section_wounded(visible):
40
  dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, \
41
  behavior_checkbox, behavior_text, \
42
  physical_boxes, \
43
- checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
 
 
3
  from physical_select_animal import create_bird_anatomy
4
  from physical_checkbox import process_body_parts
5
  from behavior_checkbox import create_behavior_checkbox
6
+ from followup_events import create_followup_dropdowns, create_followup_open
7
  from utils_json import add_data_to_individual
8
 
9
  def show_section_wounded(visible):
 
30
  with gr.Column():
31
  checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs = process_body_parts("wounded", "None")
32
 
33
+
34
  gr.Markdown("## Follow-Up Events", label="Title")
35
+ gr.Markdown("Please tell us what you did with the animal.", label="description")
36
+ with gr.Row():
37
+ fe_collection_dropdown, fe_recepient_dropdown, fe_radio_dropdown, fe_answer_dropdown = create_followup_dropdowns(visible, "wounded")
38
+ with gr.Row():
39
+ fe_name_recipient, fe_collection_ref = create_followup_open(visible, "wounded")
40
+
41
 
42
  # Change variables and names
43
  return wounded_section, radio_cause, radio_behaviour, radio_physical, \
 
45
  dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, \
46
  behavior_checkbox, behavior_text, \
47
  physical_boxes, \
48
+ checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs, \
49
+ fe_collection_dropdown, fe_recepient_dropdown, fe_radio_dropdown, fe_answer_dropdown, fe_name_recipient, fe_collection_ref