feat: checkboxes for body part
Browse files- app/assets/config/config_checkbox_physical.json +68 -0
- app/assets/{dropdowns/dropdown_config.json → config/config_dropdown_conditions.json} +0 -0
- app/assets/{dropdowns/followup_config.json → config/config_followup.json} +0 -0
- app/checkbox_physical.py +33 -0
- app/{dropdowns.py → dropdowns_conditions.py} +4 -4
- app/followup_events.py +1 -1
- app/main.py +28 -84
- app/select_bird.py +7 -3
- app/wounded.py +2 -2
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 |
+
"Head incl. eyes":
|
22 |
+
{
|
23 |
+
"Ear changes": {
|
24 |
+
"Description": "Swollen, crusts, plugged, discharge"},
|
25 |
+
"Eye changes": {
|
26 |
+
"Description": "Red, swollen, discharge, crusts, eyes shut"},
|
27 |
+
"Tilted head": {
|
28 |
+
"Description": "Wry neck, unusual neck posture, torticollis"}
|
29 |
+
},
|
30 |
+
"Beak":
|
31 |
+
{
|
32 |
+
"Adhesion": {
|
33 |
+
"Description": "Material (food, saliva) around/ in the beak"
|
34 |
+
},
|
35 |
+
"Deformation": {
|
36 |
+
"Description": "Unusual beak growth"
|
37 |
+
}
|
38 |
+
},
|
39 |
+
"Body":
|
40 |
+
{
|
41 |
+
"Emaciation": {
|
42 |
+
"Description": "Breast muscles are not well developed"},
|
43 |
+
"Fluffed up": {
|
44 |
+
"Description": "Plumage is fluffed up"},
|
45 |
+
"Stained feathers": {
|
46 |
+
"Description": "Feces, dirt, dried blood"}
|
47 |
+
},
|
48 |
+
"Legs":
|
49 |
+
{
|
50 |
+
"Missing limb": {
|
51 |
+
"Description": "Missing limb"},
|
52 |
+
"Deformation": {
|
53 |
+
"Description": "Abnormal form of limbs, toes, legs"}
|
54 |
+
},
|
55 |
+
"Feathers/Wings/Tail":
|
56 |
+
{
|
57 |
+
"Fluffed up": {
|
58 |
+
"Description": "Plumage is fluffed up"},
|
59 |
+
"Feather abnormalities": {
|
60 |
+
"Description": "Discoloration, broken/ missing feathers"},
|
61 |
+
"Stained feathers": {
|
62 |
+
"Description": "Feces, dirt, dried blood"},
|
63 |
+
"Abnormal wing posture": {
|
64 |
+
"Description": "Wing is not used/ hangs on the side"},
|
65 |
+
"Missing limb": {
|
66 |
+
"Description": "Missing limb"}
|
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/checkbox_physical.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from config_utils import get_custom_config_dropdowns
|
3 |
+
from dropdowns_conditions import retrieve_config_options
|
4 |
+
|
5 |
+
|
6 |
+
#---------------------------------------------------------
|
7 |
+
def get_options_description(value):
|
8 |
+
dropdown_config = get_custom_config_dropdowns("/assets/config/config_checkbox_physical.json")
|
9 |
+
# get options
|
10 |
+
options = retrieve_config_options(value, dropdown_config)
|
11 |
+
common = retrieve_config_options("Common", dropdown_config)
|
12 |
+
options.extend(common)
|
13 |
+
# get descriptions
|
14 |
+
descriptions = []
|
15 |
+
for key, sub_dict in dropdown_config.items():
|
16 |
+
if key==value or key=="Common":
|
17 |
+
for _, option_dict in sub_dict.items():
|
18 |
+
for description_tag, description in option_dict.items():
|
19 |
+
if "Description"==description_tag:
|
20 |
+
descriptions.append(description)
|
21 |
+
return options, descriptions
|
22 |
+
#---------------------------------------------------------
|
23 |
+
def checkbox(body_part):
|
24 |
+
options, decriptions = get_options_description(body_part)
|
25 |
+
descriptions = "".join([f"\t{option}: {description}\n" for option, description in zip(options, decriptions)])
|
26 |
+
checkbox = gr.CheckboxGroup(options,
|
27 |
+
label=f"Physical changes observed on {body_part}:",
|
28 |
+
visible=True)
|
29 |
+
text = gr.Textbox(descriptions,
|
30 |
+
label = "Info",
|
31 |
+
interactive=False,
|
32 |
+
visible=True)
|
33 |
+
return checkbox, text
|
app/{dropdowns.py → dropdowns_conditions.py}
RENAMED
@@ -3,8 +3,7 @@ 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,7 +15,8 @@ def reinitialise_level2():
|
|
16 |
return dropdown_level2, openfield_level2, dropdown_extra_level2
|
17 |
|
18 |
def create_dropdown_level1(label):
|
19 |
-
|
|
|
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
|
@@ -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/
|
49 |
for _, sub_dict in dropdown_config.items():
|
50 |
nested_dict = sub_dict.get(value)
|
51 |
if nested_dict is not None:
|
|
|
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)
|
21 |
dropdown_level2, openfield_level2, dropdown_extra_level2 = reinitialise_level2()
|
22 |
return dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2
|
|
|
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/followup_events.py
CHANGED
@@ -2,7 +2,7 @@ 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/
|
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")
|
|
|
2 |
from config_utils 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("## Follow-Up Events", label="Title")
|
8 |
gr.Markdown("Please tell us what you did with the animal.", label="description")
|
app/main.py
CHANGED
@@ -2,7 +2,7 @@ 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
|
6 |
from maps import get_location
|
7 |
from style import *
|
8 |
from theme import theme, css
|
@@ -38,71 +38,6 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
38 |
#to submit it
|
39 |
submit_location = gr.Button("Get GPS Coordinates", visible=True, interactive=True, scale=3)
|
40 |
submit_location.click(get_location, inputs=[location], outputs=[identified_location])
|
41 |
-
|
42 |
-
# ---------------------------------------------------------
|
43 |
-
# ---------------------------------------------------------
|
44 |
-
# ---------------------------------------------------------
|
45 |
-
|
46 |
-
import random
|
47 |
-
import numpy as np
|
48 |
-
|
49 |
-
section_labels = [
|
50 |
-
"apple",
|
51 |
-
"banana",
|
52 |
-
"carrot",
|
53 |
-
"donut",
|
54 |
-
"eggplant",
|
55 |
-
"fish",
|
56 |
-
"grapes",
|
57 |
-
"hamburger",
|
58 |
-
"ice cream",
|
59 |
-
"juice",
|
60 |
-
]
|
61 |
-
|
62 |
-
with gr.Row():
|
63 |
-
num_boxes = gr.Slider(0, 5, 2, step=1, label="Number of boxes")
|
64 |
-
num_segments = gr.Slider(0, 5, 1, step=1, label="Number of segments")
|
65 |
-
|
66 |
-
with gr.Row():
|
67 |
-
img_input = gr.Image()
|
68 |
-
img_output = gr.AnnotatedImage(
|
69 |
-
color_map={"banana": "#a89a00", "carrot": "#ffae00"}
|
70 |
-
)
|
71 |
-
|
72 |
-
section_btn = gr.Button("Identify Sections")
|
73 |
-
selected_section = gr.Textbox(label="Selected Section")
|
74 |
-
|
75 |
-
def section(img, num_boxes, num_segments):
|
76 |
-
sections = []
|
77 |
-
for a in range(num_boxes):
|
78 |
-
x = random.randint(0, img.shape[1])
|
79 |
-
y = random.randint(0, img.shape[0])
|
80 |
-
w = random.randint(0, img.shape[1] - x)
|
81 |
-
h = random.randint(0, img.shape[0] - y)
|
82 |
-
sections.append(((x, y, x + w, y + h), section_labels[a]))
|
83 |
-
for b in range(num_segments):
|
84 |
-
x = random.randint(0, img.shape[1])
|
85 |
-
y = random.randint(0, img.shape[0])
|
86 |
-
r = random.randint(0, min(x, y, img.shape[1] - x, img.shape[0] - y))
|
87 |
-
mask = np.zeros(img.shape[:2])
|
88 |
-
for i in range(img.shape[0]):
|
89 |
-
for j in range(img.shape[1]):
|
90 |
-
dist_square = (i - y) ** 2 + (j - x) ** 2
|
91 |
-
if dist_square < r**2:
|
92 |
-
mask[i, j] = round((r**2 - dist_square) / r**2 * 4) / 4
|
93 |
-
sections.append((mask, section_labels[b + num_boxes]))
|
94 |
-
return (img, sections)
|
95 |
-
|
96 |
-
section_btn.click(section, [img_input, num_boxes, num_segments], img_output)
|
97 |
-
|
98 |
-
def select_section(evt: gr.SelectData):
|
99 |
-
return section_labels[evt.index]
|
100 |
-
|
101 |
-
img_output.select(select_section, None, selected_section)
|
102 |
-
|
103 |
-
# ---------------------------------------------------------
|
104 |
-
# ---------------------------------------------------------
|
105 |
-
# ---------------------------------------------------------
|
106 |
|
107 |
# ---------------------------------------------------------
|
108 |
# Dead and Wounded Buttons
|
@@ -117,35 +52,44 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
117 |
# ---------------------------------------------------------
|
118 |
# Initiate sections
|
119 |
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)
|
120 |
-
section_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, img_with_boxes,
|
121 |
|
122 |
# ---------------------------------------------------------
|
123 |
# Dead Button Logic
|
124 |
partial_show_section_dead = partial(show_section_dead, True)
|
125 |
partial_hide_section_wounded = partial(show_section_wounded, False)
|
126 |
-
butt_dead.click(partial_show_section_dead,
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
134 |
# ---------------------------------------------------------
|
135 |
# Wounded Button Logic
|
136 |
partial_show_section_wounded = partial(show_section_wounded, True)
|
137 |
partial_hide_section_dead = partial(show_section_dead, False)
|
138 |
-
butt_wounded.click(partial_show_section_wounded,
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
146 |
img_with_boxes.select(find_bounding_box,
|
147 |
inputs=[img_with_boxes],
|
148 |
-
outputs=[
|
149 |
# ---------------------------------------------------------
|
150 |
# Dropdowns Dead
|
151 |
button_collision_dead.click(dropdown_collision,
|
|
|
2 |
from functools import partial
|
3 |
from dead import show_section_dead
|
4 |
from wounded import show_section_wounded
|
5 |
+
from dropdowns_conditions import *
|
6 |
from maps import get_location
|
7 |
from style import *
|
8 |
from theme import theme, css
|
|
|
38 |
#to submit it
|
39 |
submit_location = gr.Button("Get GPS Coordinates", visible=True, interactive=True, scale=3)
|
40 |
submit_location.click(get_location, inputs=[location], outputs=[identified_location])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
# ---------------------------------------------------------
|
43 |
# Dead and Wounded Buttons
|
|
|
52 |
# ---------------------------------------------------------
|
53 |
# Initiate sections
|
54 |
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)
|
55 |
+
section_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, img_with_boxes, physical_checkbox, physical_text= show_section_wounded(False)
|
56 |
|
57 |
# ---------------------------------------------------------
|
58 |
# Dead Button Logic
|
59 |
partial_show_section_dead = partial(show_section_dead, True)
|
60 |
partial_hide_section_wounded = partial(show_section_wounded, False)
|
61 |
+
butt_dead.click(partial_show_section_dead,
|
62 |
+
inputs=None,
|
63 |
+
outputs=[section_dead,
|
64 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
65 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead
|
66 |
+
])
|
67 |
+
butt_dead.click(partial_hide_section_wounded,
|
68 |
+
inputs=None,
|
69 |
+
outputs=[section_wounded,
|
70 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
71 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded
|
72 |
+
])
|
73 |
# ---------------------------------------------------------
|
74 |
# Wounded Button Logic
|
75 |
partial_show_section_wounded = partial(show_section_wounded, True)
|
76 |
partial_hide_section_dead = partial(show_section_dead, False)
|
77 |
+
butt_wounded.click(partial_show_section_wounded,
|
78 |
+
inputs=None,
|
79 |
+
outputs=[section_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 |
+
])
|
83 |
+
butt_wounded.click(partial_hide_section_dead,
|
84 |
+
inputs=None,
|
85 |
+
outputs=[section_dead,
|
86 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
87 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead
|
88 |
+
])
|
89 |
+
|
90 |
img_with_boxes.select(find_bounding_box,
|
91 |
inputs=[img_with_boxes],
|
92 |
+
outputs=[physical_checkbox, physical_text])
|
93 |
# ---------------------------------------------------------
|
94 |
# Dropdowns Dead
|
95 |
button_collision_dead.click(dropdown_collision,
|
app/select_bird.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
# from gradio_image_prompter import ImagePrompter
|
3 |
from typing import List
|
4 |
from shapely.geometry import Point
|
|
|
5 |
|
6 |
from boxes_define import gdf
|
7 |
|
@@ -12,9 +13,10 @@ def find_bounding_box(evt: gr.SelectData, img):
|
|
12 |
match = gdf[gdf.contains(point)]
|
13 |
if not match.empty:
|
14 |
matched_box = match.iloc[0]['name']
|
|
|
15 |
else:
|
16 |
matched_box = "No bounding box found"
|
17 |
-
return
|
18 |
|
19 |
# Gradio app
|
20 |
def create_bird_anatomy():
|
@@ -22,8 +24,10 @@ def create_bird_anatomy():
|
|
22 |
img_with_boxes = gr.Image(value='assets/images/bird_boxed.png',
|
23 |
show_label=False,
|
24 |
height="600px")
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
|
28 |
|
29 |
|
|
|
2 |
# from gradio_image_prompter import ImagePrompter
|
3 |
from typing import List
|
4 |
from shapely.geometry import Point
|
5 |
+
from checkbox_physical import *
|
6 |
|
7 |
from boxes_define import gdf
|
8 |
|
|
|
13 |
match = gdf[gdf.contains(point)]
|
14 |
if not match.empty:
|
15 |
matched_box = match.iloc[0]['name']
|
16 |
+
physical_checkbox, physical_text = checkbox(matched_box)
|
17 |
else:
|
18 |
matched_box = "No bounding box found"
|
19 |
+
return physical_checkbox, physical_text
|
20 |
|
21 |
# Gradio app
|
22 |
def create_bird_anatomy():
|
|
|
24 |
img_with_boxes = gr.Image(value='assets/images/bird_boxed.png',
|
25 |
show_label=False,
|
26 |
height="600px")
|
27 |
+
#templates
|
28 |
+
checkbox = gr.CheckboxGroup([], label="")
|
29 |
+
text = gr.Textbox("", label = "", interactive=False,)
|
30 |
+
return img_with_boxes, checkbox, text
|
31 |
|
32 |
|
33 |
|
app/wounded.py
CHANGED
@@ -11,9 +11,9 @@ def show_section_wounded(visible):
|
|
11 |
image_row, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause = create_top_section(visible)
|
12 |
dropdown_row, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_dropdown(visible)
|
13 |
|
14 |
-
img_with_boxes,
|
15 |
|
16 |
create_followup_section()
|
17 |
|
18 |
# Change variables and names
|
19 |
-
return wounded_section, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, img_with_boxes,
|
|
|
11 |
image_row, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause = create_top_section(visible)
|
12 |
dropdown_row, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_dropdown(visible)
|
13 |
|
14 |
+
img_with_boxes, physical_checkbox, physical_text = create_bird_anatomy()
|
15 |
|
16 |
create_followup_section()
|
17 |
|
18 |
# Change variables and names
|
19 |
+
return wounded_section, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, img_with_boxes, physical_checkbox, physical_text
|