feat: checkbox change for different bodyparts
Browse files- app/assets/config/config_checkbox_physical.json +16 -16
- app/{causes.py β circumstances.py} +1 -8
- app/{dropdowns_conditions.py β circumstances_dropdowns.py} +1 -1
- app/dead.py +1 -1
- app/followup_events.py +1 -2
- app/main.py +53 -23
- app/main_test.py +68 -0
- app/{boxes_define.py β physical_boxes_define.py} +0 -0
- app/{boxes_map.py β physical_boxes_map.py} +1 -1
- app/{checkbox_physical.py β physical_checkbox.py} +54 -12
- app/{select_bird.py β physical_select_animal.py} +20 -17
- app/{config_utils.py β utils_config.py} +0 -0
- app/utils_visible.py +6 -0
- app/wounded.py +15 -3
app/assets/config/config_checkbox_physical.json
CHANGED
@@ -18,15 +18,6 @@
|
|
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": {
|
@@ -45,13 +36,6 @@
|
|
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": {
|
@@ -64,5 +48,21 @@
|
|
64 |
"Description": "Wing is not used/ hangs on the side"},
|
65 |
"Missing limb": {
|
66 |
"Description": "Missing limb"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
}
|
68 |
}
|
|
|
18 |
"Warty or tumor-like growth, crusts": {
|
19 |
"Description": "Unusual growth, crusty tumor-like growth"}
|
20 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
"Beak":
|
22 |
{
|
23 |
"Adhesion": {
|
|
|
36 |
"Stained feathers": {
|
37 |
"Description": "Feces, dirt, dried blood"}
|
38 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
"Feathers/Wings/Tail":
|
40 |
{
|
41 |
"Fluffed up": {
|
|
|
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/{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_conditions.py β circumstances_dropdowns.py}
RENAMED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
|
4 |
|
5 |
#--------------------------------------------------------- LEVEL 1 DROPDOWNS
|
|
|
1 |
import gradio as gr
|
2 |
+
from utils_config import get_custom_config_dropdowns
|
3 |
|
4 |
|
5 |
#--------------------------------------------------------- LEVEL 1 DROPDOWNS
|
app/dead.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
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
|
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")
|
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
|
6 |
-
from
|
|
|
7 |
from maps import get_location
|
8 |
from style import *
|
9 |
from theme import theme, css
|
10 |
-
from select_bird import find_bounding_box
|
11 |
|
12 |
with gr.Blocks(theme=theme, css=css) as demo:
|
13 |
# ---------------------------------------------------------
|
@@ -52,32 +52,51 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
52 |
|
53 |
# ---------------------------------------------------------
|
54 |
# Initiate sections
|
55 |
-
section_dead,
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
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 |
|
76 |
-
butt_wounded.click(partial_show_section_wounded,
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
81 |
butt_wounded.click(partial_hide_section_dead, inputs=None, outputs=[section_dead,
|
82 |
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
83 |
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead
|
@@ -93,15 +112,14 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
93 |
dropdown_dead.select(on_select, None, [dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
|
94 |
|
95 |
# ---------------------------------------------------------
|
96 |
-
# Radio Wounded
|
97 |
radio_cause_wounded.change(fn=show_causes,
|
98 |
inputs=[radio_cause_wounded],
|
99 |
outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
100 |
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded]
|
101 |
)
|
102 |
-
|
103 |
-
#
|
104 |
-
# Dropdowns Wounded
|
105 |
button_collision_wounded.click(dropdown_collision,
|
106 |
outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
|
107 |
button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
|
@@ -110,6 +128,18 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
110 |
|
111 |
dropdown_wounded.select(on_select, None, [dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
# ---------------------------------------------------------
|
114 |
#Submit Button
|
115 |
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/{boxes_define.py β physical_boxes_define.py}
RENAMED
File without changes
|
app/{boxes_map.py β physical_boxes_map.py}
RENAMED
@@ -1,6 +1,6 @@
|
|
1 |
from PIL import Image, ImageDraw, ImageFont
|
2 |
|
3 |
-
from
|
4 |
|
5 |
# Function to draw the bounding boxes on the image
|
6 |
def draw_bounding_boxes(image_path, gdf):
|
|
|
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):
|
app/{checkbox_physical.py β physical_checkbox.py}
RENAMED
@@ -1,7 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
from
|
4 |
|
|
|
|
|
|
|
|
|
5 |
|
6 |
#---------------------------------------------------------
|
7 |
def get_options_description(value):
|
@@ -19,18 +23,56 @@ def get_options_description(value):
|
|
19 |
if "Description"==description_tag:
|
20 |
descriptions.append(description)
|
21 |
return options, descriptions
|
|
|
22 |
#---------------------------------------------------------
|
23 |
-
def
|
24 |
options, descriptions = get_options_description(body_part)
|
25 |
descriptions_info = "".join([f"\t{option}: {description}\n" for option, description in zip(options, descriptions)])
|
26 |
checkbox = gr.CheckboxGroup(options,
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
text = gr.Textbox(descriptions_info,
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
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/{select_bird.py β physical_select_animal.py}
RENAMED
@@ -2,9 +2,10 @@ import gradio as gr
|
|
2 |
# from gradio_image_prompter import ImagePrompter
|
3 |
from typing import List
|
4 |
from shapely.geometry import Point
|
5 |
-
from
|
|
|
|
|
6 |
|
7 |
-
from boxes_define import gdf
|
8 |
|
9 |
# Function to find the matching bounding box for a given point and return the image with boxes
|
10 |
def find_bounding_box(evt: gr.SelectData, img, section: str):
|
@@ -13,27 +14,29 @@ def find_bounding_box(evt: gr.SelectData, img, section: str):
|
|
13 |
match = gdf[gdf.contains(point)]
|
14 |
if not match.empty:
|
15 |
matched_box = match.iloc[0]['name']
|
16 |
-
|
17 |
else:
|
18 |
-
matched_box =
|
19 |
-
|
20 |
-
return
|
21 |
|
22 |
-
|
23 |
-
#templates
|
24 |
-
checkbox = gr.CheckboxGroup([], label="", visible=False)
|
25 |
-
text = gr.Textbox("", label = "", interactive=False, visible=False)
|
26 |
-
return checkbox, text
|
27 |
|
28 |
# Gradio app
|
29 |
-
def create_bird_anatomy(section: str):
|
30 |
# Draw bounding boxes on the image
|
31 |
img_with_boxes = gr.Image(value='assets/images/bird_boxed.png',
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
return img_with_boxes
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
|
39 |
|
|
|
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):
|
|
|
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 |
|
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,7 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
|
|
3 |
from followup_events import create_followup_section
|
4 |
-
from select_bird import create_bird_anatomy
|
5 |
|
6 |
def show_section_wounded(visible):
|
7 |
with gr.Column(visible=visible, elem_id="wounded") as wounded_section:
|
@@ -16,7 +17,18 @@ def show_section_wounded(visible):
|
|
16 |
|
17 |
gr.Markdown("## Are there physical changes on the bird?" , label="description")
|
18 |
radio_physical = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
create_followup_section()
|
20 |
|
21 |
# Change variables and names
|
22 |
-
return wounded_section, radio_cause, radio_behaviour, radio_physical,
|
|
|
|
|
|
|
|
|
|
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):
|
8 |
with gr.Column(visible=visible, elem_id="wounded") as wounded_section:
|
|
|
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
|