vancauwe commited on
Commit
d0ad561
Β·
unverified Β·
2 Parent(s): ea38e18 fc85e7c

Merge pull request #9 from sdsc-ordes/feat-bird-image-body-selection

Browse files
app/assets/config/config_checkbox_physical.json ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Common":
3
+ {
4
+ "Blackened/burnt skin": {
5
+ "Description": "Burnt/ blackened/ charred skin or feathers"},
6
+ "Blood": {
7
+ "Description": "Visible blood"},
8
+ "Foreign body": {
9
+ "Description": "Objects in feathers"},
10
+ "Fracture": {
11
+ "Description": "Obvious bone fracture"},
12
+ "Injury": {
13
+ "Description": "Visible skin injury"},
14
+ "Parasites": {
15
+ "Description": "Maggots, fleas, lice, louseflies"},
16
+ "Swelling": {
17
+ "Description": "Marked swelling without injury"},
18
+ "Warty or tumor-like growth, crusts": {
19
+ "Description": "Unusual growth, crusty tumor-like growth"}
20
+ },
21
+ "Beak":
22
+ {
23
+ "Adhesion": {
24
+ "Description": "Material (food, saliva) around/ in the beak"
25
+ },
26
+ "Deformation": {
27
+ "Description": "Unusual beak growth"
28
+ }
29
+ },
30
+ "Body":
31
+ {
32
+ "Emaciation": {
33
+ "Description": "Breast muscles are not well developed"},
34
+ "Fluffed up": {
35
+ "Description": "Plumage is fluffed up"},
36
+ "Stained feathers": {
37
+ "Description": "Feces, dirt, dried blood"}
38
+ },
39
+ "Feathers/Wings/Tail":
40
+ {
41
+ "Fluffed up": {
42
+ "Description": "Plumage is fluffed up"},
43
+ "Feather abnormalities": {
44
+ "Description": "Discoloration, broken/ missing feathers"},
45
+ "Stained feathers": {
46
+ "Description": "Feces, dirt, dried blood"},
47
+ "Abnormal wing posture": {
48
+ "Description": "Wing is not used/ hangs on the side"},
49
+ "Missing limb": {
50
+ "Description": "Missing limb"}
51
+ },
52
+ "Head incl. eyes":
53
+ {
54
+ "Ear changes": {
55
+ "Description": "Swollen, crusts, plugged, discharge"},
56
+ "Eye changes": {
57
+ "Description": "Red, swollen, discharge, crusts, eyes shut"},
58
+ "Tilted head": {
59
+ "Description": "Wry neck, unusual neck posture, torticollis"}
60
+ },
61
+ "Legs":
62
+ {
63
+ "Missing limb": {
64
+ "Description": "Missing limb"},
65
+ "Deformation": {
66
+ "Description": "Abnormal form of limbs, toes, legs"}
67
+ }
68
+ }
app/assets/{dropdowns/dropdown_config.json β†’ config/config_dropdown_conditions.json} RENAMED
File without changes
app/assets/{dropdowns/followup_config.json β†’ config/config_followup.json} RENAMED
File without changes
app/assets/fonts/LiberationSans-Regular.ttf ADDED
Binary file (134 kB). View file
 
app/assets/images/bird.png ADDED
app/assets/images/bird_boxed.png ADDED
app/{causes.py β†’ circumstances.py} RENAMED
@@ -1,16 +1,10 @@
1
  import gradio as gr
2
  import os
 
3
 
4
  PATH = os.getcwd()
5
  CAUSE_COL_WIDTH = "50px"
6
 
7
- def set_visible(choice):
8
- if choice=="Yes":
9
- visible = True
10
- else:
11
- visible=False
12
- return visible
13
-
14
  def show_causes(choice):
15
  visible = set_visible(choice)
16
  button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_causes(visible)
@@ -23,7 +17,6 @@ def create_causes(visible):
23
 
24
 
25
  def create_causes_buttons(visible):
26
- print(visible)
27
  with gr.Row() as image_row:
28
  with gr.Column(scale=1, min_width=CAUSE_COL_WIDTH):
29
  button_collision = gr.Button("Collision with a means of transport",
 
1
  import gradio as gr
2
  import os
3
+ from utils_visible import set_visible
4
 
5
  PATH = os.getcwd()
6
  CAUSE_COL_WIDTH = "50px"
7
 
 
 
 
 
 
 
 
8
  def show_causes(choice):
9
  visible = set_visible(choice)
10
  button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_causes(visible)
 
17
 
18
 
19
  def create_causes_buttons(visible):
 
20
  with gr.Row() as image_row:
21
  with gr.Column(scale=1, min_width=CAUSE_COL_WIDTH):
22
  button_collision = gr.Button("Collision with a means of transport",
app/{dropdowns.py β†’ circumstances_dropdowns.py} RENAMED
@@ -1,10 +1,9 @@
1
  import gradio as gr
2
- from config_utils import get_custom_config_dropdowns
3
 
4
 
5
  #--------------------------------------------------------- LEVEL 1 DROPDOWNS
6
- def retrieve_config_options(label):
7
- dropdown_config = get_custom_config_dropdowns("/assets/dropdowns/dropdown_config.json")
8
  options = list(dropdown_config[label].keys())
9
  options = [option.title() for option in options]
10
  return options
@@ -16,8 +15,9 @@ def reinitialise_level2():
16
  return dropdown_level2, openfield_level2, dropdown_extra_level2
17
 
18
  def create_dropdown_level1(label):
19
- options = retrieve_config_options(label)
20
- dropdown = gr.Dropdown(choices=options, label=label, interactive=True)
 
21
  dropdown_level2, openfield_level2, dropdown_extra_level2 = reinitialise_level2()
22
  return dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2
23
 
@@ -45,7 +45,7 @@ def get_options(value):
45
  open_field = None
46
  extras = None
47
  extras_label = None
48
- dropdown_config = get_custom_config_dropdowns("/assets/dropdowns/dropdown_config.json")
49
  for _, sub_dict in dropdown_config.items():
50
  nested_dict = sub_dict.get(value)
51
  if nested_dict is not None:
 
1
  import gradio as gr
2
+ from utils_config import get_custom_config_dropdowns
3
 
4
 
5
  #--------------------------------------------------------- LEVEL 1 DROPDOWNS
6
+ def retrieve_config_options(label, dropdown_config):
 
7
  options = list(dropdown_config[label].keys())
8
  options = [option.title() for option in options]
9
  return options
 
15
  return dropdown_level2, openfield_level2, dropdown_extra_level2
16
 
17
  def create_dropdown_level1(label):
18
+ dropdown_config = get_custom_config_dropdowns("/assets/config/config_dropdown_conditions.json")
19
+ options = retrieve_config_options(label, dropdown_config)
20
+ dropdown = gr.Dropdown(choices=options, label=label, interactive=True, visible=True)
21
  dropdown_level2, openfield_level2, dropdown_extra_level2 = reinitialise_level2()
22
  return dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2
23
 
 
45
  open_field = None
46
  extras = None
47
  extras_label = None
48
+ dropdown_config = get_custom_config_dropdowns("/assets/config/config_dropdown_conditions.json")
49
  for _, sub_dict in dropdown_config.items():
50
  nested_dict = sub_dict.get(value)
51
  if nested_dict is not None:
app/dead.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- from causes import create_causes
3
  from followup_events import create_followup_section
4
 
5
 
 
1
  import gradio as gr
2
+ from circumstances import create_causes
3
  from followup_events import create_followup_section
4
 
5
 
app/followup_events.py CHANGED
@@ -1,10 +1,9 @@
1
  import gradio as gr
2
- from config_utils import get_custom_config_dropdowns
3
 
4
  def create_followup_section():
5
- followup_config = get_custom_config_dropdowns("/assets/dropdowns/followup_config.json")
6
  followup_config = followup_config["Event follow-up"]
7
- gr.Markdown("## Follow-Up Events", label="Title")
8
  gr.Markdown("Please tell us what you did with the animal.", label="description")
9
  with gr.Row():
10
  for key, val in followup_config.items():
 
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("/assets/config/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():
app/main.py CHANGED
@@ -2,12 +2,12 @@ import gradio as gr
2
  from functools import partial
3
  from dead import show_section_dead
4
  from wounded import show_section_wounded
5
- from causes import show_causes
6
- from dropdowns import *
 
7
  from maps import get_location
8
  from style import *
9
  from theme import theme, css
10
- from followup_events import create_followup_section
11
 
12
  with gr.Blocks(theme=theme, css=css) as demo:
13
  # ---------------------------------------------------------
@@ -52,31 +52,51 @@ with gr.Blocks(theme=theme, css=css) as demo:
52
 
53
  # ---------------------------------------------------------
54
  # Initiate sections
55
- section_dead, button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead = show_section_dead(False)
56
- section_wounded, radio_cause_wounded, radio_behaviour_wounded, radio_physical_wounded, button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded= show_section_wounded(False)
 
 
 
 
 
 
 
 
57
 
58
  # ---------------------------------------------------------
59
  # Dead Button Logic
60
  partial_show_section_dead = partial(show_section_dead, True)
61
  partial_hide_section_wounded = partial(show_section_wounded, False)
62
- butt_dead.click(partial_show_section_dead, inputs=None, outputs=[section_dead,
63
- button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
64
- dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead
65
- ])
66
- butt_dead.click(partial_hide_section_wounded, inputs=None, outputs=[section_wounded,
67
- radio_cause_wounded, radio_behaviour_wounded, radio_physical_wounded,
68
- button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
69
- dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded
70
- ])
 
 
 
 
 
 
 
71
  # ---------------------------------------------------------
72
  # Wounded Button Logic
73
  partial_show_section_wounded = partial(show_section_wounded, True)
74
  partial_hide_section_dead = partial(show_section_dead, False)
75
- butt_wounded.click(partial_show_section_wounded, inputs=None, outputs=[section_wounded,
76
- radio_cause_wounded, radio_behaviour_wounded, radio_physical_wounded,
77
- button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
78
- dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded
79
- ])
 
 
 
 
 
80
  butt_wounded.click(partial_hide_section_dead, inputs=None, outputs=[section_dead,
81
  button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
82
  dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead
@@ -92,15 +112,14 @@ with gr.Blocks(theme=theme, css=css) as demo:
92
  dropdown_dead.select(on_select, None, [dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
93
 
94
  # ---------------------------------------------------------
95
- # Radio Wounded
96
  radio_cause_wounded.change(fn=show_causes,
97
  inputs=[radio_cause_wounded],
98
  outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
99
  dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded]
100
  )
101
-
102
- # ---------------------------------------------------------
103
- # Dropdowns Wounded
104
  button_collision_wounded.click(dropdown_collision,
105
  outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
106
  button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
@@ -109,6 +128,18 @@ with gr.Blocks(theme=theme, css=css) as demo:
109
 
110
  dropdown_wounded.select(on_select, None, [dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
111
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  # ---------------------------------------------------------
113
  #Submit Button
114
  with gr.Column(scale=1):
 
2
  from functools import partial
3
  from dead import show_section_dead
4
  from wounded import show_section_wounded
5
+ from circumstances import show_causes
6
+ from circumstances_dropdowns import *
7
+ from physical_select_animal import show_physical, find_bounding_box
8
  from maps import get_location
9
  from style import *
10
  from theme import theme, css
 
11
 
12
  with gr.Blocks(theme=theme, css=css) as demo:
13
  # ---------------------------------------------------------
 
52
 
53
  # ---------------------------------------------------------
54
  # Initiate sections
55
+ section_dead, \
56
+ button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
57
+ dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead \
58
+ = show_section_dead(False)
59
+ section_wounded, radio_cause_wounded, radio_behaviour_wounded, radio_physical_wounded, \
60
+ button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
61
+ dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
62
+ physical_boxes_wounded, \
63
+ checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
64
+ = show_section_wounded(False)
65
 
66
  # ---------------------------------------------------------
67
  # Dead Button Logic
68
  partial_show_section_dead = partial(show_section_dead, True)
69
  partial_hide_section_wounded = partial(show_section_wounded, False)
70
+ butt_dead.click(partial_show_section_dead,
71
+ inputs=None,
72
+ outputs=[section_dead,
73
+ button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
74
+ dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead
75
+ ])
76
+ butt_dead.click(partial_hide_section_wounded,
77
+ inputs=None,
78
+ outputs=[section_wounded,
79
+ radio_cause_wounded, radio_behaviour_wounded, radio_physical_wounded,
80
+ button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
81
+ dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
82
+ physical_boxes_wounded,
83
+ checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
84
+
85
+ ])
86
  # ---------------------------------------------------------
87
  # Wounded Button Logic
88
  partial_show_section_wounded = partial(show_section_wounded, True)
89
  partial_hide_section_dead = partial(show_section_dead, False)
90
+
91
+ butt_wounded.click(partial_show_section_wounded,
92
+ inputs=None,
93
+ outputs=[section_wounded,
94
+ radio_cause_wounded, radio_behaviour_wounded, radio_physical_wounded,
95
+ button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
96
+ dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
97
+ physical_boxes_wounded,
98
+ checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
99
+ ])
100
  butt_wounded.click(partial_hide_section_dead, inputs=None, outputs=[section_dead,
101
  button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
102
  dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead
 
112
  dropdown_dead.select(on_select, None, [dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
113
 
114
  # ---------------------------------------------------------
115
+ # Radio Cause Wounded
116
  radio_cause_wounded.change(fn=show_causes,
117
  inputs=[radio_cause_wounded],
118
  outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
119
  dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded]
120
  )
121
+
122
+ # Dropdowns Cause Wounded
 
123
  button_collision_wounded.click(dropdown_collision,
124
  outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
125
  button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
 
128
 
129
  dropdown_wounded.select(on_select, None, [dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
130
 
131
+ # ---------------------------------------------------------
132
+ # Radio Physical Wounded
133
+ radio_physical_wounded.change(fn=show_physical,
134
+ inputs=[radio_physical_wounded, gr.Text("wounded", visible=False)],
135
+ outputs=[physical_boxes_wounded])
136
+ # ---------------------------------------------------------
137
+ # Checkbox Physical Wounded
138
+ physical_boxes_wounded.select(find_bounding_box,
139
+ inputs=[physical_boxes_wounded, gr.Textbox(value="wounded", visible=False)],
140
+ outputs=[checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
141
+ ])
142
+
143
  # ---------------------------------------------------------
144
  #Submit Button
145
  with gr.Column(scale=1):
app/main_test.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Function that processes the Textbox input and generates new CheckboxGroups
4
+ def generate_checkbox_groups(textbox_input):
5
+ try:
6
+ num_groups = int(textbox_input)
7
+ except ValueError:
8
+ return "Please enter a valid number."
9
+
10
+ # Dynamically create a list of CheckboxGroups
11
+ checkbox_groups = []
12
+ for i in range(num_groups):
13
+ checkbox_groups.append(gr.CheckboxGroup(
14
+ choices=["Option 1", "Option 2", "Option 3"],
15
+ label=f"Checkbox Group {i + 1}",
16
+ interactive=True
17
+ ))
18
+
19
+ return checkbox_groups
20
+
21
+ # Function to process the selections of the dynamically created CheckboxGroups
22
+ def process_selections(*checkbox_values):
23
+ results = []
24
+ for i, selections in enumerate(checkbox_values):
25
+ selected_options = ', '.join(selections) if selections else 'None'
26
+ results.append(f"Selected options for group {i + 1}: {selected_options}")
27
+
28
+ return "\n".join(results)
29
+
30
+ with gr.Blocks() as demo:
31
+ # Textbox for user input to specify the number of CheckboxGroups
32
+ textbox = gr.Textbox(label="Enter the number of Checkbox Groups to create")
33
+
34
+ # Button to trigger the generation of CheckboxGroups
35
+ generate_button = gr.Button("Generate Checkbox Groups")
36
+
37
+ # A placeholder for the dynamically generated CheckboxGroups
38
+ dynamic_checkbox_groups = gr.Column()
39
+
40
+ # Output Textbox to display the results
41
+ output = gr.Textbox(label="Output")
42
+
43
+ # Generate CheckboxGroups based on Textbox input
44
+ def update_dynamic_groups(textbox_value):
45
+ groups = generate_checkbox_groups(textbox_value)
46
+ dynamic_checkbox_groups.children = groups
47
+ return dynamic_checkbox_groups
48
+
49
+ generate_button.click(
50
+ fn=update_dynamic_groups,
51
+ inputs=textbox,
52
+ outputs=dynamic_checkbox_groups
53
+ )
54
+
55
+ # Button to process selections from the dynamically generated CheckboxGroups
56
+ process_button = gr.Button("Submit Selections")
57
+
58
+ # Process the selections when the second button is clicked
59
+ def process_dynamic_groups(*checkbox_groups):
60
+ return process_selections(*checkbox_groups)
61
+
62
+ process_button.click(
63
+ fn=process_dynamic_groups,
64
+ inputs=dynamic_checkbox_groups.children, # Unpack the dynamically generated groups
65
+ outputs=output
66
+ )
67
+
68
+ demo.launch(server_name="0.0.0.0")
app/physical_boxes_define.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import geopandas as gpd
2
+ from shapely.geometry import box
3
+
4
+ bounding_boxes = [
5
+ # 'Head incl. eyes',
6
+ box(250, 375, 350, 485),
7
+ # 'Beak and mouth region',
8
+ box(200, 450, 250, 485),
9
+ # 'Feathers/Wings/Tail',
10
+ box(50, 100, 725, 355),
11
+ # 'Legs',
12
+ box(325, 585, 450, 675),
13
+ # 'Body'
14
+ box(275, 510, 500, 565)
15
+ ]
16
+
17
+ # Create a GeoDataFrame from these boxes
18
+ gdf = gpd.GeoDataFrame({'geometry': bounding_boxes,
19
+ 'name': ['Head incl. eyes',
20
+ 'Beak',
21
+ 'Feathers/Wings/Tail',
22
+ 'Legs',
23
+ 'Body']})
app/physical_boxes_map.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw, ImageFont
2
+
3
+ from physical_boxes_define import gdf
4
+
5
+ # Function to draw the bounding boxes on the image
6
+ def draw_bounding_boxes(image_path, gdf):
7
+ image = Image.open(image_path+'bird.png').convert("RGB")
8
+ # Convert the image to an editable format
9
+ draw = ImageDraw.Draw(image)
10
+
11
+ # Optional: Load a font (requires a TTF file)
12
+ # try:
13
+ font = ImageFont.truetype("assets/fonts/LiberationSans-Regular.ttf",
14
+ 20)
15
+ # except IOError:
16
+ # print("default")
17
+ # font = ImageFont.load_default()
18
+
19
+ # Draw each bounding box on the image
20
+ for _, row in gdf.iterrows():
21
+ xmin, ymin, xmax, ymax = row['geometry'].bounds
22
+ draw.rectangle([xmin, ymin, xmax, ymax], outline="purple", width=2)
23
+ draw.text((xmin, ymin-22), row['name'], fill="black", font=font)
24
+
25
+ image.save(image_path+'bird_boxed.png', "PNG")
26
+
27
+ if __name__ == "__main__":
28
+ draw_bounding_boxes('assets/images/', gdf)
app/physical_checkbox.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from utils_config import get_custom_config_dropdowns
3
+ from circumstances_dropdowns import retrieve_config_options
4
+
5
+ #---------------------------------------------------------
6
+ def get_body_parts():
7
+ dropdown_config = get_custom_config_dropdowns("/assets/config/config_checkbox_physical.json")
8
+ return list(dropdown_config.keys())
9
+
10
+ #---------------------------------------------------------
11
+ def get_options_description(value):
12
+ dropdown_config = get_custom_config_dropdowns("/assets/config/config_checkbox_physical.json")
13
+ # get options
14
+ options = retrieve_config_options("Common", dropdown_config)
15
+ options_for_value = retrieve_config_options(value, dropdown_config)
16
+ options.extend(options_for_value)
17
+ # get descriptions
18
+ descriptions = []
19
+ for key, sub_dict in dropdown_config.items():
20
+ if key==value or key=="Common":
21
+ for _, option_dict in sub_dict.items():
22
+ for description_tag, description in option_dict.items():
23
+ if "Description"==description_tag:
24
+ descriptions.append(description)
25
+ return options, descriptions
26
+
27
+ #---------------------------------------------------------
28
+ def create_checkbox(body_part, section, visible):
29
+ options, descriptions = get_options_description(body_part)
30
+ descriptions_info = "".join([f"\t{option}: {description}\n" for option, description in zip(options, descriptions)])
31
+ checkbox = gr.CheckboxGroup(options,
32
+ label=f"Physical changes observed on {body_part}:",
33
+ visible=visible,
34
+ interactive=True,
35
+ elem_id=section)
36
+ text = gr.Textbox(descriptions_info,
37
+ label = "Info",
38
+ visible=visible,
39
+ interactive=False,
40
+ lines=13,
41
+ max_lines=15,
42
+ elem_id=section)
43
+ return checkbox, text
44
+
45
+ def create_checkbox_beak(section, visible):
46
+ body_part="Beak"
47
+ return create_checkbox(body_part, section, visible)
48
+
49
+ def create_checkbox_body(section, visible):
50
+ body_part="Body"
51
+ return create_checkbox(body_part, section, visible)
52
+
53
+ def create_checkbox_feathers(section, visible):
54
+ body_part="Feathers/Wings/Tail"
55
+ return create_checkbox(body_part, section, visible)
56
+
57
+ def create_checkbox_head(section, visible):
58
+ body_part="Head incl. eyes"
59
+ return create_checkbox(body_part, section, visible)
60
+
61
+ def create_checkbox_legs(section, visible):
62
+ body_part="Legs"
63
+ return create_checkbox(body_part, section, visible)
64
+
65
+ #---------------------------------------------------------
66
+ def process_body_parts(section, matched_box):
67
+ #take all except "Common"
68
+ body_parts = get_body_parts()
69
+ body_parts = body_parts[1:]
70
+ visibles = [True if matched_box==body_part else False for body_part in body_parts ]
71
+ checkbox_beak, text_beak = create_checkbox_beak(section, visibles[0])
72
+ checkbox_body, text_body = create_checkbox_body(section, visibles[1])
73
+ checkbox_feathers, text_feathers = create_checkbox_feathers(section, visibles[2])
74
+ checkbox_head, text_head = create_checkbox_head(section, visibles[3])
75
+ checkbox_legs, text_legs = create_checkbox_legs(section, visibles[4])
76
+ return checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
77
+
78
+
app/physical_select_animal.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ # from gradio_image_prompter import ImagePrompter
3
+ from typing import List
4
+ from shapely.geometry import Point
5
+ from physical_checkbox import *
6
+ from physical_boxes_define import gdf
7
+ from utils_visible import set_visible
8
+
9
+
10
+ # Function to find the matching bounding box for a given point and return the image with boxes
11
+ def find_bounding_box(evt: gr.SelectData, img, section: str):
12
+ x, y = evt.index[0], evt.index[1]
13
+ point = Point(x, y)
14
+ match = gdf[gdf.contains(point)]
15
+ if not match.empty:
16
+ matched_box = match.iloc[0]['name']
17
+ checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs = process_body_parts(section, matched_box)
18
+ else:
19
+ matched_box = None
20
+ checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs = process_body_parts(section, matched_box)
21
+ return checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
22
+
23
+
24
+
25
+ # Gradio app
26
+ def create_bird_anatomy(visible, section: str):
27
+ # Draw bounding boxes on the image
28
+ img_with_boxes = gr.Image(value='assets/images/bird_boxed.png',
29
+ show_label=False,
30
+ height="600px",
31
+ elem_id=section,
32
+ visible=visible)
33
+ return img_with_boxes
34
+
35
+ def show_physical(choice, section: str):
36
+ visible = set_visible(choice)
37
+ physical_boxes = create_bird_anatomy(visible, section)
38
+ return physical_boxes
39
+
40
+
41
+
42
+
43
+
44
+
app/theme.py CHANGED
@@ -5,6 +5,7 @@ css = """
5
  #image {background-color: #73b9ae}
6
  #dead {background-color: #333333}
7
  #wounded {background-color: #5e0724}
 
8
  #buttons-conditions {background-color: #b3b3b3}
9
  #dropdown-conditions {background-color: #b3b3b3}
10
  #followup {background-color: #38241c}
 
5
  #image {background-color: #73b9ae}
6
  #dead {background-color: #333333}
7
  #wounded {background-color: #5e0724}
8
+ #bird-boxes {background-color: #f2f3f3}
9
  #buttons-conditions {background-color: #b3b3b3}
10
  #dropdown-conditions {background-color: #b3b3b3}
11
  #followup {background-color: #38241c}
app/{config_utils.py β†’ utils_config.py} RENAMED
File without changes
app/utils_visible.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ def set_visible(choice):
2
+ if choice=="Yes":
3
+ visible = True
4
+ else:
5
+ visible=False
6
+ return visible
app/wounded.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
- from causes import create_causes
 
 
3
  from followup_events import create_followup_section
4
 
5
  def show_section_wounded(visible):
@@ -15,7 +17,18 @@ def show_section_wounded(visible):
15
 
16
  gr.Markdown("## Are there physical changes on the bird?" , label="description")
17
  radio_physical = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)
 
 
 
 
 
 
 
18
  create_followup_section()
19
 
20
  # Change variables and names
21
- return wounded_section, radio_cause, radio_behaviour, radio_physical, 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 physical_select_animal import create_bird_anatomy
4
+ from physical_checkbox import process_body_parts
5
  from followup_events import create_followup_section
6
 
7
  def show_section_wounded(visible):
 
17
 
18
  gr.Markdown("## Are there physical changes on the bird?" , label="description")
19
  radio_physical = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)
20
+ with gr.Row():
21
+ physical_boxes = create_bird_anatomy(False, "wounded")
22
+ with gr.Column():
23
+ 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")
24
+
25
+
26
+ gr.Markdown("## Follow-Up Events", label="Title")
27
  create_followup_section()
28
 
29
  # Change variables and names
30
+ return wounded_section, radio_cause, radio_behaviour, radio_physical, \
31
+ button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, \
32
+ dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, \
33
+ physical_boxes, \
34
+ checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
  gradio
2
- geopy
 
 
 
1
  gradio
2
+ geopy
3
+ geopandas
4
+ pillow