feat: tabbed simple and advanced modes
Browse files- app/main.py +4 -400
- app/mode_advanced.py +414 -0
- app/mode_simple.py +391 -0
- requirements.txt +1 -2
app/main.py
CHANGED
|
@@ -1,409 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from gradio_modal import Modal
|
| 3 |
-
|
| 4 |
-
from validation_submission.utils_individual import add_data_to_individual
|
| 5 |
-
from validation_submission.submission import validate_save_individual
|
| 6 |
-
from validation_submission.validation import reset_error_box
|
| 7 |
-
from geolocalisation.maps import get_location
|
| 8 |
-
from functools import partial
|
| 9 |
-
from dead import show_section_dead
|
| 10 |
-
from wounded import show_section_wounded
|
| 11 |
-
from circumstances.circumstances import show_circumstances
|
| 12 |
-
from circumstances.circumstances_dropdowns import *
|
| 13 |
-
from physical.physical_select_animal import show_physical, find_bounding_box
|
| 14 |
-
from physical.physical_checkbox import on_select_body_part, hide_physical
|
| 15 |
-
from behavior.behavior_checkbox import show_behavior, on_select_behavior
|
| 16 |
-
from follow_up.followup_events import save_fe
|
| 17 |
-
from styling.style import *
|
| 18 |
-
from credits import credits_text
|
| 19 |
-
|
| 20 |
-
from geolocalisation.js_geolocation import js_geocode, display_location
|
| 21 |
-
from validation_submission.utils_individual import generate_random_md5
|
| 22 |
-
|
| 23 |
from datasets import disable_caching
|
| 24 |
disable_caching()
|
| 25 |
|
| 26 |
-
dataset_id = "SDSC/digiwild-dataset"
|
| 27 |
-
data_files = "data/train-00000-of-00001.parquet"
|
| 28 |
-
|
| 29 |
-
from dotenv import load_dotenv
|
| 30 |
-
import os
|
| 31 |
-
load_dotenv()
|
| 32 |
-
PATH = os.getcwd() + "/"
|
| 33 |
-
PATH_ASSETS = os.getenv('PATH_ASSETS')
|
| 34 |
-
PATH_ICONS = PATH + PATH_ASSETS + "icons/"
|
| 35 |
-
|
| 36 |
-
with gr.Blocks(theme='shivi/calm_seafoam') as demo:
|
| 37 |
-
individual = gr.State({})
|
| 38 |
-
individual.value = add_data_to_individual("image_md5", generate_random_md5(), individual.value)
|
| 39 |
-
|
| 40 |
-
# ---------------------------------------------------------
|
| 41 |
-
# Header Text
|
| 42 |
-
with gr.Row():
|
| 43 |
-
gr.Image(PATH_ICONS+"swallow.png", scale =0.1,
|
| 44 |
-
interactive=False,
|
| 45 |
-
show_fullscreen_button = False, show_share_button=False,
|
| 46 |
-
show_download_button=False, show_label=False)
|
| 47 |
-
with gr.Column(scale=1):
|
| 48 |
-
title = gr.Markdown("# Welcome to Digiwild", label="Title")
|
| 49 |
-
description = gr.Markdown("Please record your wildlife observations here !", label="description")
|
| 50 |
-
|
| 51 |
-
# ---------------------------------------------------------
|
| 52 |
-
# Camera
|
| 53 |
-
with gr.Row():
|
| 54 |
-
def save_image(camera, individual):
|
| 55 |
-
individual = add_data_to_individual("image", camera.tolist(), individual)
|
| 56 |
-
return individual
|
| 57 |
-
camera = gr.Image(elem_id="image")
|
| 58 |
-
camera.input(save_image, inputs=[camera, individual], outputs=[individual])
|
| 59 |
-
|
| 60 |
-
# ---------------------------------------------------------
|
| 61 |
-
# General Details
|
| 62 |
-
with gr.Column(scale=1):
|
| 63 |
-
gr.Button("General Details", icon=PATH_ICONS+"bird.png", variant="primary")
|
| 64 |
-
|
| 65 |
-
with gr.Row():
|
| 66 |
-
specie = gr.Textbox(
|
| 67 |
-
label="Species (if known)",
|
| 68 |
-
placeholder="e.g. European Robin, Common Blackbird",
|
| 69 |
-
info="Enter the species name if you can identify it. If unsure, provide your best guess or general description (e.g. 'small brown bird')",
|
| 70 |
-
visible=True,
|
| 71 |
-
interactive=True
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
# Number of individuals
|
| 75 |
-
with gr.Row():
|
| 76 |
-
num_individuals = gr.Number(
|
| 77 |
-
label="Number of Individuals",
|
| 78 |
-
value=1, # Default value
|
| 79 |
-
minimum=1,
|
| 80 |
-
precision=0, # Only whole numbers
|
| 81 |
-
info="Enter the number of animals observed",
|
| 82 |
-
#placeholder="Enter number...",
|
| 83 |
-
visible=True,
|
| 84 |
-
interactive=True
|
| 85 |
-
)
|
| 86 |
-
|
| 87 |
-
# Introducing text_box for comments
|
| 88 |
-
with gr.Row():
|
| 89 |
-
comments = gr.TextArea(
|
| 90 |
-
label="Additional Comments",
|
| 91 |
-
placeholder="Enter any additional observations or notes about the sighting...",
|
| 92 |
-
info="Optional: Add any relevant details about the animal(s) or circumstances",
|
| 93 |
-
lines=3,
|
| 94 |
-
max_lines=5,
|
| 95 |
-
visible=True,
|
| 96 |
-
interactive=True
|
| 97 |
-
)
|
| 98 |
-
|
| 99 |
-
# ---------------------------------------------------------
|
| 100 |
-
# Location
|
| 101 |
-
gr.Button("Location", icon=PATH_ICONS+"pin.png", variant="primary")
|
| 102 |
-
with gr.Row():
|
| 103 |
-
with gr.Column(scale=1):
|
| 104 |
-
gr.Markdown("#### Location (Using address)")
|
| 105 |
-
location = gr.Textbox(visible=True, interactive=True, label="Location of Sighting")
|
| 106 |
-
#display location processing
|
| 107 |
-
identified_location= gr.Textbox(visible=False, interactive=False,
|
| 108 |
-
label="Identified GPS Location")
|
| 109 |
-
with gr.Row():
|
| 110 |
-
#to submit it
|
| 111 |
-
submit_location = gr.Button("Get Coordinates using address",
|
| 112 |
-
visible=True, interactive=True, scale=3)
|
| 113 |
-
submit_location.click(get_location, inputs=[location, individual], outputs=[identified_location, individual])
|
| 114 |
-
#to clear it
|
| 115 |
-
clear_location = gr.ClearButton(components=[location, identified_location],
|
| 116 |
-
visible=True, interactive=True, scale=1
|
| 117 |
-
)
|
| 118 |
-
clear_location.click()
|
| 119 |
-
|
| 120 |
-
with gr.Column(scale=1):
|
| 121 |
-
# Geolocation
|
| 122 |
-
gr.Markdown("#### Location (Using GPS)")
|
| 123 |
-
location_data = gr.JSON(label="Identified GPS Location")
|
| 124 |
-
hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 125 |
-
btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required)")
|
| 126 |
-
btn_gpslocation.click(None, [], [], js=js_geocode)
|
| 127 |
-
hidden_input.change(display_location, inputs=hidden_input, outputs=location_data)
|
| 128 |
-
|
| 129 |
-
# ---------------------------------------------------------
|
| 130 |
-
# Dead and Wounded Buttons
|
| 131 |
-
gr.Button("State of the Animal", variant="primary")
|
| 132 |
-
with gr.Row():
|
| 133 |
-
gr.Image(PATH_ICONS+"medical-app.png", scale =0.1,
|
| 134 |
-
interactive=False,
|
| 135 |
-
show_fullscreen_button = False, show_share_button=False,
|
| 136 |
-
show_download_button=False, show_label=False)
|
| 137 |
-
with gr.Column():
|
| 138 |
-
gr.Markdown("## The State of the Animal", label="Title")
|
| 139 |
-
gr.Markdown("Please tell us if the animal was wounded / sick or dead.", label="description")
|
| 140 |
-
gr.Markdown("Please fill out as many fields as you can, based on what you can see.", label="description")
|
| 141 |
-
gr.Markdown("### Do not touch the animal unless absolutely necessary.", label="description")
|
| 142 |
-
with gr.Row() as block_form:
|
| 143 |
-
with gr.Column(scale=1):
|
| 144 |
-
butt_wounded = gr.Button("Wounded / Sick", elem_id="wounded", variant="primary")
|
| 145 |
-
with gr.Column(scale=1):
|
| 146 |
-
butt_dead = gr.Button("Dead", elem_id="dead", variant="primary")
|
| 147 |
-
|
| 148 |
-
# ---------------------------------------------------------
|
| 149 |
-
# Initiate sections
|
| 150 |
-
section_dead, individual, radio_circumstance_dead, radio_physical_dead,\
|
| 151 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
| 152 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 153 |
-
physical_boxes_dead, \
|
| 154 |
-
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
| 155 |
-
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 156 |
-
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 157 |
-
= show_section_dead(False, individual)
|
| 158 |
-
|
| 159 |
-
section_wounded, individual, radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
| 160 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
| 161 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
| 162 |
-
behavior_checkbox, behavior_text, \
|
| 163 |
-
physical_boxes_wounded, \
|
| 164 |
-
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
| 165 |
-
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 166 |
-
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 167 |
-
= show_section_wounded(False, individual)
|
| 168 |
-
|
| 169 |
-
# ---------------------------------------------------------
|
| 170 |
-
# ---------------------------------------------------------
|
| 171 |
-
# ---------------------------------------------------------
|
| 172 |
-
# Dead Button Logic
|
| 173 |
-
partial_show_section_dead = partial(show_section_dead, True)
|
| 174 |
-
partial_hide_section_wounded = partial(show_section_wounded, False)
|
| 175 |
-
butt_dead.click(partial_show_section_dead,
|
| 176 |
-
inputs=[individual],
|
| 177 |
-
outputs=[section_dead,
|
| 178 |
-
individual,
|
| 179 |
-
radio_circumstance_dead, radio_physical_dead,
|
| 180 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 181 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 182 |
-
physical_boxes_dead, \
|
| 183 |
-
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
| 184 |
-
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 185 |
-
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 186 |
-
])
|
| 187 |
-
|
| 188 |
-
butt_dead.click(partial_hide_section_wounded,
|
| 189 |
-
inputs=[individual],
|
| 190 |
-
outputs=[section_wounded,
|
| 191 |
-
individual,
|
| 192 |
-
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 193 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 194 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 195 |
-
behavior_checkbox, behavior_text,
|
| 196 |
-
physical_boxes_wounded, \
|
| 197 |
-
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
| 198 |
-
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 199 |
-
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 200 |
-
])
|
| 201 |
-
|
| 202 |
-
# ---------------------------------------------------------
|
| 203 |
-
# Wounded Button Logic
|
| 204 |
-
partial_show_section_wounded = partial(show_section_wounded, True)
|
| 205 |
-
partial_hide_section_dead = partial(show_section_dead, False)
|
| 206 |
-
|
| 207 |
-
butt_wounded.click(partial_show_section_wounded,
|
| 208 |
-
inputs=[individual],
|
| 209 |
-
outputs=[section_wounded,
|
| 210 |
-
individual,
|
| 211 |
-
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 212 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 213 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 214 |
-
behavior_checkbox, behavior_text,
|
| 215 |
-
physical_boxes_wounded, \
|
| 216 |
-
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
| 217 |
-
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 218 |
-
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 219 |
-
])
|
| 220 |
-
|
| 221 |
-
butt_wounded.click(partial_hide_section_dead,
|
| 222 |
-
inputs=[individual],
|
| 223 |
-
outputs=[section_dead,
|
| 224 |
-
individual,
|
| 225 |
-
radio_circumstance_dead, radio_physical_dead,
|
| 226 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 227 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 228 |
-
physical_boxes_dead, \
|
| 229 |
-
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
| 230 |
-
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 231 |
-
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 232 |
-
])
|
| 233 |
-
|
| 234 |
-
# ---------------------------------------------------------
|
| 235 |
-
# ---------------------------------------------------------
|
| 236 |
-
# ---------------------------------------------------------
|
| 237 |
-
# ---------------------------------------------------------
|
| 238 |
-
# DEAD
|
| 239 |
-
# ---------------------------------------------------------
|
| 240 |
-
# Radio Circumstance Dead
|
| 241 |
-
radio_circumstance_dead.change(fn=show_circumstances,
|
| 242 |
-
inputs=[radio_circumstance_dead, individual],
|
| 243 |
-
outputs=[button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 244 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual]
|
| 245 |
-
)
|
| 246 |
-
|
| 247 |
-
# Dropdowns Dead
|
| 248 |
-
button_collision_dead.click(dropdown_collision,
|
| 249 |
-
inputs=[individual],
|
| 250 |
-
outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 251 |
-
button_deliberate_destruction_dead.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 252 |
-
button_indirect_destruction_dead.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 253 |
-
button_natural_cause_dead.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 254 |
-
|
| 255 |
-
dropdown_dead.select(on_select, inputs=[individual], outputs=[dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 256 |
-
dropdown_level2_dead.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual] )
|
| 257 |
-
openfield_level2_dead.change(on_change_openfield_level2, inputs=[openfield_level2_dead, individual], outputs=[individual])
|
| 258 |
-
dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])
|
| 259 |
-
# ---------------------------------------------------------
|
| 260 |
-
# Radio Physical Dead
|
| 261 |
-
radio_physical_dead.change(fn=show_physical,
|
| 262 |
-
inputs=[radio_physical_dead, gr.Text("dead", visible=False), individual],
|
| 263 |
-
outputs=[physical_boxes_dead, individual])
|
| 264 |
-
|
| 265 |
-
# Checkbox Physical Dead
|
| 266 |
-
physical_boxes_dead.select(find_bounding_box,
|
| 267 |
-
inputs=[physical_boxes_dead, gr.Textbox(value="dead", visible=False)],
|
| 268 |
-
outputs=[checkbox_beak_dead, text_beak_dead,
|
| 269 |
-
checkbox_body_dead, text_body_dead,
|
| 270 |
-
checkbox_feathers_dead, text_feathers_dead,
|
| 271 |
-
checkbox_head_dead, text_head_dead,
|
| 272 |
-
checkbox_legs_dead, text_legs_dead
|
| 273 |
-
])
|
| 274 |
-
checkbox_beak_dead.select(on_select_body_part, inputs=[checkbox_beak_dead, gr.Text("beak", visible=False), individual], outputs=[individual])
|
| 275 |
-
checkbox_body_dead.select(on_select_body_part, inputs=[checkbox_body_dead, gr.Text("body", visible=False), individual], outputs=[individual])
|
| 276 |
-
checkbox_feathers_dead.select(on_select_body_part, inputs=[checkbox_feathers_dead, gr.Text("feathers", visible=False), individual], outputs=[individual])
|
| 277 |
-
checkbox_head_dead.select(on_select_body_part, inputs=[checkbox_head_dead, gr.Text("head", visible=False), individual], outputs=[individual])
|
| 278 |
-
checkbox_legs_dead.select(on_select_body_part, inputs=[checkbox_legs_dead, gr.Text("legs", visible=False), individual], outputs=[individual])
|
| 279 |
-
# ---------------------------------------------------------
|
| 280 |
-
# ---------------------------------------------------------
|
| 281 |
-
# ---------------------------------------------------------
|
| 282 |
-
# ---------------------------------------------------------
|
| 283 |
-
# WOUNDED
|
| 284 |
-
# ---------------------------------------------------------
|
| 285 |
-
# Radio Circumstance Wounded
|
| 286 |
-
radio_circumstance_wounded.change(fn=show_circumstances,
|
| 287 |
-
inputs=[radio_circumstance_wounded, individual],
|
| 288 |
-
outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 289 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual]
|
| 290 |
-
)
|
| 291 |
-
|
| 292 |
-
# Dropdowns Circumstance Wounded
|
| 293 |
-
button_collision_wounded.click(dropdown_collision,
|
| 294 |
-
inputs=[individual],
|
| 295 |
-
outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 296 |
-
button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 297 |
-
button_indirect_destruction_wounded.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 298 |
-
button_natural_cause_wounded.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 299 |
-
|
| 300 |
-
dropdown_wounded.select(on_select, inputs=[individual], outputs=[dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 301 |
-
dropdown_level2_wounded.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])
|
| 302 |
-
openfield_level2_wounded.change(on_change_openfield_level2, inputs=[openfield_level2_wounded, individual])
|
| 303 |
-
dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])
|
| 304 |
-
# ---------------------------------------------------------
|
| 305 |
-
# Radio Behavior Wounded
|
| 306 |
-
radio_behavior_wounded.change(fn=show_behavior,
|
| 307 |
-
inputs=[radio_behavior_wounded, gr.Text("wounded / sick", visible=False), individual],
|
| 308 |
-
outputs=[behavior_checkbox, behavior_text, individual])
|
| 309 |
-
behavior_checkbox.select(on_select_behavior,
|
| 310 |
-
inputs=[behavior_checkbox, individual],
|
| 311 |
-
outputs=[individual])
|
| 312 |
-
# ---------------------------------------------------------
|
| 313 |
-
# Radio Physical Wounded
|
| 314 |
-
radio_physical_wounded.change(fn=show_physical,
|
| 315 |
-
inputs=[radio_physical_wounded, gr.Text("wounded / sick", visible=False), individual],
|
| 316 |
-
outputs=[physical_boxes_wounded, individual])
|
| 317 |
-
|
| 318 |
-
# Checkbox Physical Wounded
|
| 319 |
-
physical_boxes_wounded.select(find_bounding_box,
|
| 320 |
-
inputs=[physical_boxes_wounded, gr.Textbox(value="wounded / sick", visible=False)],
|
| 321 |
-
outputs=[checkbox_beak_wounded, text_beak_wounded,
|
| 322 |
-
checkbox_body_wounded, text_body_wounded,
|
| 323 |
-
checkbox_feathers_wounded, text_feathers_wounded,
|
| 324 |
-
checkbox_head_wounded, text_head_wounded,
|
| 325 |
-
checkbox_legs_wounded, text_legs_wounded
|
| 326 |
-
])
|
| 327 |
-
checkbox_beak_wounded.select(on_select_body_part, inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False), individual], outputs=[individual])
|
| 328 |
-
checkbox_body_wounded.select(on_select_body_part, inputs=[checkbox_body_wounded, gr.Text("body", visible=False), individual], outputs=[individual])
|
| 329 |
-
checkbox_feathers_wounded.select(on_select_body_part, inputs=[checkbox_feathers_wounded, gr.Text("feathers", visible=False), individual], outputs=[individual])
|
| 330 |
-
checkbox_head_wounded.select(on_select_body_part, inputs=[checkbox_head_wounded, gr.Text("head", visible=False), individual], outputs=[individual])
|
| 331 |
-
checkbox_legs_wounded.select(on_select_body_part, inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False), individual], outputs=[individual])
|
| 332 |
-
|
| 333 |
-
# ---------------------------------------------------------
|
| 334 |
-
# Follow Up Events Wounded
|
| 335 |
-
fe_collection_dropdown_wounded.select(save_fe, inputs=[fe_collection_dropdown_wounded, gr.Textbox("animal collected", visible=False), individual], outputs=[individual])
|
| 336 |
-
fe_recepient_dropdown_wounded.select(save_fe, inputs=[fe_recepient_dropdown_wounded, gr.Textbox("recipient", visible=False), individual],outputs=[individual])
|
| 337 |
-
fe_radio_dropdown_wounded.select(save_fe, inputs=[fe_radio_dropdown_wounded, gr.Textbox("radiography", visible=False), individual],outputs=[individual])
|
| 338 |
-
fe_answer_dropdown_wounded.select(save_fe, inputs=[fe_answer_dropdown_wounded, gr.Textbox("given answer", visible=False), individual],outputs=[individual])
|
| 339 |
-
fe_name_recipient_wounded.input(save_fe, inputs=[fe_name_recipient_wounded, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])
|
| 340 |
-
fe_collection_ref_wounded.input(save_fe, inputs=[fe_collection_ref_wounded, gr.Textbox("collection reference", visible=False), individual],outputs=[individual])
|
| 341 |
-
|
| 342 |
-
# ---------------------------------------------------------
|
| 343 |
-
# Follow Up Events Dead
|
| 344 |
-
fe_collection_dropdown_dead.select(save_fe, inputs=[fe_collection_dropdown_dead, gr.Textbox("animal collected", visible=False), individual],outputs=[individual])
|
| 345 |
-
fe_recepient_dropdown_dead.select(save_fe, inputs=[fe_recepient_dropdown_dead, gr.Textbox("recipient", visible=False), individual],outputs=[individual])
|
| 346 |
-
fe_radio_dropdown_dead.select(save_fe, inputs=[fe_radio_dropdown_dead, gr.Textbox("radiography", visible=False), individual],outputs=[individual])
|
| 347 |
-
fe_answer_dropdown_dead.select(save_fe, inputs=[fe_answer_dropdown_dead, gr.Textbox("given answer", visible=False), individual],outputs=[individual])
|
| 348 |
-
fe_name_recipient_dead.input(save_fe, inputs=[fe_name_recipient_dead, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])
|
| 349 |
-
fe_collection_ref_dead.input(save_fe, inputs=[fe_collection_ref_dead, gr.Textbox("collection reference", visible=False), individual], outputs=[individual])
|
| 350 |
-
|
| 351 |
-
# ---------------------------------------------------------
|
| 352 |
-
# Error Box
|
| 353 |
-
error_box = gr.Text(value=None, visible=False)
|
| 354 |
-
|
| 355 |
-
# ---------------------------------------------------------
|
| 356 |
-
# Allow clearing of all previous output
|
| 357 |
-
with gr.Row():
|
| 358 |
-
button_df = gr.Button("SUBMIT OBSERVATION", icon=PATH_ICONS+"effective.png",
|
| 359 |
-
scale = 3)
|
| 360 |
-
button_clear = gr.ClearButton(value="CLEAR",
|
| 361 |
-
scale = 1,
|
| 362 |
-
components=[
|
| 363 |
-
camera,
|
| 364 |
-
location, identified_location,
|
| 365 |
-
#dead reset
|
| 366 |
-
radio_circumstance_dead, radio_physical_dead,
|
| 367 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 368 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
|
| 369 |
-
physical_boxes_dead,
|
| 370 |
-
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead,
|
| 371 |
-
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead,
|
| 372 |
-
fe_name_recipient_dead, fe_collection_ref_dead,
|
| 373 |
-
#wounded reset
|
| 374 |
-
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 375 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 376 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 377 |
-
behavior_checkbox, behavior_text,
|
| 378 |
-
physical_boxes_wounded,
|
| 379 |
-
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded,
|
| 380 |
-
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded,
|
| 381 |
-
fe_name_recipient_wounded, fe_collection_ref_wounded,
|
| 382 |
-
error_box
|
| 383 |
-
])
|
| 384 |
-
show_creds = gr.Button("CREDITS", icon=PATH_ICONS+"copyright.png", scale=0.5)
|
| 385 |
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
button_clear.click()
|
| 389 |
-
button_clear.click(hide_physical,
|
| 390 |
-
outputs=[checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded])
|
| 391 |
-
button_clear.click(hide_physical,
|
| 392 |
-
outputs=[checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead])
|
| 393 |
-
button_clear.click(reset_error_box, inputs=[error_box], outputs=[error_box])
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
# ---------------------------------------------------------
|
| 397 |
-
# VALIDATE ANIMAL
|
| 398 |
-
button_df.click(validate_save_individual, inputs=[individual, error_box],
|
| 399 |
-
outputs=[error_box])
|
| 400 |
-
# ---------------------------------------------------------
|
| 401 |
-
#CREDITS
|
| 402 |
-
with Modal(visible=False) as modal_creds:
|
| 403 |
-
gr.Markdown(credits_text)
|
| 404 |
-
show_creds.click(lambda: Modal(visible=True), None, modal_creds)
|
| 405 |
|
| 406 |
-
|
|
|
|
| 407 |
|
| 408 |
if __name__ == "__main__":
|
| 409 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from datasets import disable_caching
|
| 3 |
disable_caching()
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
from mode_advanced import advanced
|
| 7 |
+
from mode_simple import simple
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
demo = gr.TabbedInterface([simple, advanced], ["Simple Mode" , "Advanced Reporting"],
|
| 10 |
+
theme='shivi/calm_seafoam')
|
| 11 |
|
| 12 |
if __name__ == "__main__":
|
| 13 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
app/mode_advanced.py
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_modal import Modal
|
| 3 |
+
|
| 4 |
+
from validation_submission.utils_individual import add_data_to_individual
|
| 5 |
+
from validation_submission.submission import validate_save_individual
|
| 6 |
+
from validation_submission.validation import reset_error_box
|
| 7 |
+
from geolocalisation.maps import get_location
|
| 8 |
+
from functools import partial
|
| 9 |
+
from dead import show_section_dead
|
| 10 |
+
from wounded import show_section_wounded
|
| 11 |
+
from circumstances.circumstances import show_circumstances
|
| 12 |
+
from circumstances.circumstances_dropdowns import *
|
| 13 |
+
from physical.physical_select_animal import show_physical, find_bounding_box
|
| 14 |
+
from physical.physical_checkbox import on_select_body_part, hide_physical
|
| 15 |
+
from behavior.behavior_checkbox import show_behavior, on_select_behavior
|
| 16 |
+
from follow_up.followup_events import save_fe
|
| 17 |
+
from styling.style import *
|
| 18 |
+
from credits import credits_text
|
| 19 |
+
|
| 20 |
+
from geolocalisation.js_geolocation import js_geocode, display_location
|
| 21 |
+
from validation_submission.utils_individual import generate_random_md5
|
| 22 |
+
|
| 23 |
+
from dotenv import load_dotenv
|
| 24 |
+
import os
|
| 25 |
+
load_dotenv()
|
| 26 |
+
PATH = os.getcwd() + "/"
|
| 27 |
+
PATH_ASSETS = os.getenv('PATH_ASSETS')
|
| 28 |
+
PATH_ICONS = PATH + PATH_ASSETS + "icons/"
|
| 29 |
+
|
| 30 |
+
with gr.Blocks(theme='shivi/calm_seafoam') as advanced:
|
| 31 |
+
individual = gr.State({})
|
| 32 |
+
individual.value = add_data_to_individual("image_md5", generate_random_md5(), individual.value)
|
| 33 |
+
|
| 34 |
+
# ---------------------------------------------------------
|
| 35 |
+
# Header Text
|
| 36 |
+
with gr.Row():
|
| 37 |
+
gr.Image(PATH_ICONS+"impact.png", scale =0.1,
|
| 38 |
+
interactive=False,
|
| 39 |
+
show_fullscreen_button = False, show_share_button=False,
|
| 40 |
+
show_download_button=False, show_label=False)
|
| 41 |
+
with gr.Column(scale=1):
|
| 42 |
+
title = gr.Markdown("# Welcome to Digiwild - Advanced Reporting", label="Title")
|
| 43 |
+
description = gr.Markdown("### Please record your wildlife observations here !", label="description")
|
| 44 |
+
|
| 45 |
+
# ---------------------------------------------------------
|
| 46 |
+
# Camera
|
| 47 |
+
with gr.Row():
|
| 48 |
+
def save_image(camera, individual):
|
| 49 |
+
individual = add_data_to_individual("image", camera.tolist(), individual)
|
| 50 |
+
return individual
|
| 51 |
+
camera = gr.Image(elem_id="image")
|
| 52 |
+
camera.input(save_image, inputs=[camera, individual], outputs=[individual])
|
| 53 |
+
|
| 54 |
+
# ---------------------------------------------------------
|
| 55 |
+
# General Details
|
| 56 |
+
with gr.Column(scale=1):
|
| 57 |
+
gr.Button("General Details", icon=PATH_ICONS+"chicken.png", variant="secondary")
|
| 58 |
+
|
| 59 |
+
with gr.Row():
|
| 60 |
+
specie = gr.Textbox(
|
| 61 |
+
label="Species (if known)",
|
| 62 |
+
placeholder="e.g. European Robin, Common Blackbird",
|
| 63 |
+
info="Enter the species name if you can identify it. If unsure, provide your best guess or general description (e.g. 'small brown bird')",
|
| 64 |
+
visible=True,
|
| 65 |
+
interactive=True
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
# Number of individuals
|
| 69 |
+
with gr.Row():
|
| 70 |
+
num_individuals = gr.Number(
|
| 71 |
+
label="Number of Individuals",
|
| 72 |
+
value=1, # Default value
|
| 73 |
+
minimum=1,
|
| 74 |
+
precision=0, # Only whole numbers
|
| 75 |
+
info="Enter the number of animals observed",
|
| 76 |
+
#placeholder="Enter number...",
|
| 77 |
+
visible=True,
|
| 78 |
+
interactive=True
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
# Introducing text_box for comments
|
| 82 |
+
with gr.Row():
|
| 83 |
+
comments = gr.TextArea(
|
| 84 |
+
label="Additional Comments",
|
| 85 |
+
placeholder="Enter any additional observations or notes about the sighting...",
|
| 86 |
+
info="Optional: Add any relevant details about the animal(s) or circumstances",
|
| 87 |
+
lines=3,
|
| 88 |
+
max_lines=5,
|
| 89 |
+
visible=True,
|
| 90 |
+
interactive=True
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# ---------------------------------------------------------
|
| 94 |
+
# Location
|
| 95 |
+
gr.Button("Location", icon=PATH_ICONS+"pin.png", variant="secondary")
|
| 96 |
+
with gr.Row():
|
| 97 |
+
with gr.Column(scale=1):
|
| 98 |
+
gr.Markdown("#### Location (Using address)")
|
| 99 |
+
location = gr.Textbox(visible=True, interactive=True,
|
| 100 |
+
label="Location of Sighting")
|
| 101 |
+
#display location processing
|
| 102 |
+
identified_location= gr.Textbox(visible=False, interactive=False,
|
| 103 |
+
label="Identified GPS Location")
|
| 104 |
+
with gr.Row():
|
| 105 |
+
#to submit it
|
| 106 |
+
submit_location = gr.Button("Get Coordinates using address",
|
| 107 |
+
visible=True, interactive=True, scale=3)
|
| 108 |
+
submit_location.click(get_location, inputs=[location, individual], outputs=[identified_location, individual])
|
| 109 |
+
#to clear it
|
| 110 |
+
clear_location = gr.ClearButton(components=[location, identified_location],
|
| 111 |
+
visible=True, interactive=True, scale=1
|
| 112 |
+
)
|
| 113 |
+
clear_location.click()
|
| 114 |
+
|
| 115 |
+
with gr.Column(scale=1):
|
| 116 |
+
# Geolocation
|
| 117 |
+
gr.Markdown("#### Location (Using GPS)")
|
| 118 |
+
location_data = gr.JSON(label="Identified GPS Location")
|
| 119 |
+
hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 120 |
+
btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required)")
|
| 121 |
+
btn_gpslocation.click(None, [], [], js=js_geocode)
|
| 122 |
+
hidden_input.change(display_location, inputs=hidden_input, outputs=location_data)
|
| 123 |
+
|
| 124 |
+
# ---------------------------------------------------------
|
| 125 |
+
# Dead and Wounded Buttons
|
| 126 |
+
gr.Button("State of the Animal", variant="secondary")
|
| 127 |
+
with gr.Row():
|
| 128 |
+
gr.Image(PATH_ICONS+"medical-app.png", scale =0.1,
|
| 129 |
+
interactive=False,
|
| 130 |
+
show_fullscreen_button = False, show_share_button=False,
|
| 131 |
+
show_download_button=False, show_label=False)
|
| 132 |
+
with gr.Column():
|
| 133 |
+
gr.Markdown("## The State of the Animal", label="Title")
|
| 134 |
+
gr.Markdown("Please tell us if the animal was wounded / sick or dead.", label="description")
|
| 135 |
+
gr.Markdown("Please fill out as many fields as you can, based on what you can see.", label="description")
|
| 136 |
+
gr.Markdown("### Do not touch the animal unless absolutely necessary.", label="description")
|
| 137 |
+
with gr.Row() as block_form:
|
| 138 |
+
with gr.Column(scale=1):
|
| 139 |
+
butt_wounded = gr.Button("Wounded / Sick", elem_id="wounded")
|
| 140 |
+
with gr.Column(scale=1):
|
| 141 |
+
butt_dead = gr.Button("Dead", elem_id="dead")
|
| 142 |
+
|
| 143 |
+
# ---------------------------------------------------------
|
| 144 |
+
# Initiate sections
|
| 145 |
+
section_dead, individual, radio_circumstance_dead, radio_physical_dead,\
|
| 146 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
| 147 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 148 |
+
physical_boxes_dead, \
|
| 149 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
| 150 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 151 |
+
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 152 |
+
= show_section_dead(False, individual)
|
| 153 |
+
|
| 154 |
+
section_wounded, individual, radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
| 155 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
| 156 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
| 157 |
+
behavior_checkbox, behavior_text, \
|
| 158 |
+
physical_boxes_wounded, \
|
| 159 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
| 160 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 161 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 162 |
+
= show_section_wounded(False, individual)
|
| 163 |
+
|
| 164 |
+
# ---------------------------------------------------------
|
| 165 |
+
# ---------------------------------------------------------
|
| 166 |
+
# ---------------------------------------------------------
|
| 167 |
+
# Dead Button Logic
|
| 168 |
+
partial_show_section_dead = partial(show_section_dead, True)
|
| 169 |
+
partial_hide_section_wounded = partial(show_section_wounded, False)
|
| 170 |
+
butt_dead.click(partial_show_section_dead,
|
| 171 |
+
inputs=[individual],
|
| 172 |
+
outputs=[section_dead,
|
| 173 |
+
individual,
|
| 174 |
+
radio_circumstance_dead, radio_physical_dead,
|
| 175 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 176 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 177 |
+
physical_boxes_dead, \
|
| 178 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
| 179 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 180 |
+
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 181 |
+
])
|
| 182 |
+
|
| 183 |
+
butt_dead.click(partial_hide_section_wounded,
|
| 184 |
+
inputs=[individual],
|
| 185 |
+
outputs=[section_wounded,
|
| 186 |
+
individual,
|
| 187 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 188 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 189 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 190 |
+
behavior_checkbox, behavior_text,
|
| 191 |
+
physical_boxes_wounded, \
|
| 192 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
| 193 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 194 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 195 |
+
])
|
| 196 |
+
|
| 197 |
+
# ---------------------------------------------------------
|
| 198 |
+
# Wounded Button Logic
|
| 199 |
+
partial_show_section_wounded = partial(show_section_wounded, True)
|
| 200 |
+
partial_hide_section_dead = partial(show_section_dead, False)
|
| 201 |
+
|
| 202 |
+
butt_wounded.click(partial_show_section_wounded,
|
| 203 |
+
inputs=[individual],
|
| 204 |
+
outputs=[section_wounded,
|
| 205 |
+
individual,
|
| 206 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 207 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 208 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 209 |
+
behavior_checkbox, behavior_text,
|
| 210 |
+
physical_boxes_wounded, \
|
| 211 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
| 212 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 213 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 214 |
+
])
|
| 215 |
+
|
| 216 |
+
butt_wounded.click(partial_hide_section_dead,
|
| 217 |
+
inputs=[individual],
|
| 218 |
+
outputs=[section_dead,
|
| 219 |
+
individual,
|
| 220 |
+
radio_circumstance_dead, radio_physical_dead,
|
| 221 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 222 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 223 |
+
physical_boxes_dead, \
|
| 224 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
| 225 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 226 |
+
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 227 |
+
])
|
| 228 |
+
|
| 229 |
+
# ---------------------------------------------------------
|
| 230 |
+
# ---------------------------------------------------------
|
| 231 |
+
# ---------------------------------------------------------
|
| 232 |
+
# ---------------------------------------------------------
|
| 233 |
+
# DEAD
|
| 234 |
+
# ---------------------------------------------------------
|
| 235 |
+
# Radio Circumstance Dead
|
| 236 |
+
radio_circumstance_dead.change(fn=show_circumstances,
|
| 237 |
+
inputs=[radio_circumstance_dead, individual],
|
| 238 |
+
outputs=[button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 239 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual]
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
# Dropdowns Dead
|
| 243 |
+
button_collision_dead.click(dropdown_collision,
|
| 244 |
+
inputs=[individual],
|
| 245 |
+
outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 246 |
+
button_deliberate_destruction_dead.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 247 |
+
button_indirect_destruction_dead.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 248 |
+
button_natural_cause_dead.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 249 |
+
|
| 250 |
+
dropdown_dead.select(on_select, inputs=[individual], outputs=[dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 251 |
+
dropdown_level2_dead.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual] )
|
| 252 |
+
openfield_level2_dead.change(on_change_openfield_level2, inputs=[openfield_level2_dead, individual], outputs=[individual])
|
| 253 |
+
dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])
|
| 254 |
+
# ---------------------------------------------------------
|
| 255 |
+
# Radio Physical Dead
|
| 256 |
+
radio_physical_dead.change(fn=show_physical,
|
| 257 |
+
inputs=[radio_physical_dead, gr.Text("dead", visible=False), individual],
|
| 258 |
+
outputs=[physical_boxes_dead, individual])
|
| 259 |
+
|
| 260 |
+
# Checkbox Physical Dead
|
| 261 |
+
physical_boxes_dead.select(find_bounding_box,
|
| 262 |
+
inputs=[physical_boxes_dead, gr.Textbox(value="dead", visible=False)],
|
| 263 |
+
outputs=[checkbox_beak_dead, text_beak_dead,
|
| 264 |
+
checkbox_body_dead, text_body_dead,
|
| 265 |
+
checkbox_feathers_dead, text_feathers_dead,
|
| 266 |
+
checkbox_head_dead, text_head_dead,
|
| 267 |
+
checkbox_legs_dead, text_legs_dead
|
| 268 |
+
])
|
| 269 |
+
checkbox_beak_dead.select(on_select_body_part, inputs=[checkbox_beak_dead, gr.Text("beak", visible=False), individual], outputs=[individual])
|
| 270 |
+
checkbox_body_dead.select(on_select_body_part, inputs=[checkbox_body_dead, gr.Text("body", visible=False), individual], outputs=[individual])
|
| 271 |
+
checkbox_feathers_dead.select(on_select_body_part, inputs=[checkbox_feathers_dead, gr.Text("feathers", visible=False), individual], outputs=[individual])
|
| 272 |
+
checkbox_head_dead.select(on_select_body_part, inputs=[checkbox_head_dead, gr.Text("head", visible=False), individual], outputs=[individual])
|
| 273 |
+
checkbox_legs_dead.select(on_select_body_part, inputs=[checkbox_legs_dead, gr.Text("legs", visible=False), individual], outputs=[individual])
|
| 274 |
+
# ---------------------------------------------------------
|
| 275 |
+
# ---------------------------------------------------------
|
| 276 |
+
# ---------------------------------------------------------
|
| 277 |
+
# ---------------------------------------------------------
|
| 278 |
+
# WOUNDED
|
| 279 |
+
# ---------------------------------------------------------
|
| 280 |
+
# Radio Circumstance Wounded
|
| 281 |
+
radio_circumstance_wounded.change(fn=show_circumstances,
|
| 282 |
+
inputs=[radio_circumstance_wounded, individual],
|
| 283 |
+
outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 284 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual]
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
# Dropdowns Circumstance Wounded
|
| 288 |
+
button_collision_wounded.click(dropdown_collision,
|
| 289 |
+
inputs=[individual],
|
| 290 |
+
outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 291 |
+
button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 292 |
+
button_indirect_destruction_wounded.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 293 |
+
button_natural_cause_wounded.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 294 |
+
|
| 295 |
+
dropdown_wounded.select(on_select, inputs=[individual], outputs=[dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 296 |
+
dropdown_level2_wounded.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])
|
| 297 |
+
openfield_level2_wounded.change(on_change_openfield_level2, inputs=[openfield_level2_wounded, individual])
|
| 298 |
+
dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])
|
| 299 |
+
# ---------------------------------------------------------
|
| 300 |
+
# Radio Behavior Wounded
|
| 301 |
+
radio_behavior_wounded.change(fn=show_behavior,
|
| 302 |
+
inputs=[radio_behavior_wounded, gr.Text("wounded / sick", visible=False), individual],
|
| 303 |
+
outputs=[behavior_checkbox, behavior_text, individual])
|
| 304 |
+
behavior_checkbox.select(on_select_behavior,
|
| 305 |
+
inputs=[behavior_checkbox, individual],
|
| 306 |
+
outputs=[individual])
|
| 307 |
+
# ---------------------------------------------------------
|
| 308 |
+
# Radio Physical Wounded
|
| 309 |
+
radio_physical_wounded.change(fn=show_physical,
|
| 310 |
+
inputs=[radio_physical_wounded, gr.Text("wounded / sick", visible=False), individual],
|
| 311 |
+
outputs=[physical_boxes_wounded, individual])
|
| 312 |
+
|
| 313 |
+
# Checkbox Physical Wounded
|
| 314 |
+
physical_boxes_wounded.select(find_bounding_box,
|
| 315 |
+
inputs=[physical_boxes_wounded, gr.Textbox(value="wounded / sick", visible=False)],
|
| 316 |
+
outputs=[checkbox_beak_wounded, text_beak_wounded,
|
| 317 |
+
checkbox_body_wounded, text_body_wounded,
|
| 318 |
+
checkbox_feathers_wounded, text_feathers_wounded,
|
| 319 |
+
checkbox_head_wounded, text_head_wounded,
|
| 320 |
+
checkbox_legs_wounded, text_legs_wounded
|
| 321 |
+
])
|
| 322 |
+
checkbox_beak_wounded.select(on_select_body_part, inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False), individual], outputs=[individual])
|
| 323 |
+
checkbox_body_wounded.select(on_select_body_part, inputs=[checkbox_body_wounded, gr.Text("body", visible=False), individual], outputs=[individual])
|
| 324 |
+
checkbox_feathers_wounded.select(on_select_body_part, inputs=[checkbox_feathers_wounded, gr.Text("feathers", visible=False), individual], outputs=[individual])
|
| 325 |
+
checkbox_head_wounded.select(on_select_body_part, inputs=[checkbox_head_wounded, gr.Text("head", visible=False), individual], outputs=[individual])
|
| 326 |
+
checkbox_legs_wounded.select(on_select_body_part, inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False), individual], outputs=[individual])
|
| 327 |
+
|
| 328 |
+
# ---------------------------------------------------------
|
| 329 |
+
# Follow Up Events Wounded
|
| 330 |
+
fe_collection_dropdown_wounded.select(save_fe, inputs=[fe_collection_dropdown_wounded, gr.Textbox("animal collected", visible=False), individual], outputs=[individual])
|
| 331 |
+
fe_recepient_dropdown_wounded.select(save_fe, inputs=[fe_recepient_dropdown_wounded, gr.Textbox("recipient", visible=False), individual],outputs=[individual])
|
| 332 |
+
fe_radio_dropdown_wounded.select(save_fe, inputs=[fe_radio_dropdown_wounded, gr.Textbox("radiography", visible=False), individual],outputs=[individual])
|
| 333 |
+
fe_answer_dropdown_wounded.select(save_fe, inputs=[fe_answer_dropdown_wounded, gr.Textbox("given answer", visible=False), individual],outputs=[individual])
|
| 334 |
+
fe_name_recipient_wounded.input(save_fe, inputs=[fe_name_recipient_wounded, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])
|
| 335 |
+
fe_collection_ref_wounded.input(save_fe, inputs=[fe_collection_ref_wounded, gr.Textbox("collection reference", visible=False), individual],outputs=[individual])
|
| 336 |
+
|
| 337 |
+
# ---------------------------------------------------------
|
| 338 |
+
# Follow Up Events Dead
|
| 339 |
+
fe_collection_dropdown_dead.select(save_fe, inputs=[fe_collection_dropdown_dead, gr.Textbox("animal collected", visible=False), individual],outputs=[individual])
|
| 340 |
+
fe_recepient_dropdown_dead.select(save_fe, inputs=[fe_recepient_dropdown_dead, gr.Textbox("recipient", visible=False), individual],outputs=[individual])
|
| 341 |
+
fe_radio_dropdown_dead.select(save_fe, inputs=[fe_radio_dropdown_dead, gr.Textbox("radiography", visible=False), individual],outputs=[individual])
|
| 342 |
+
fe_answer_dropdown_dead.select(save_fe, inputs=[fe_answer_dropdown_dead, gr.Textbox("given answer", visible=False), individual],outputs=[individual])
|
| 343 |
+
fe_name_recipient_dead.input(save_fe, inputs=[fe_name_recipient_dead, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])
|
| 344 |
+
fe_collection_ref_dead.input(save_fe, inputs=[fe_collection_ref_dead, gr.Textbox("collection reference", visible=False), individual], outputs=[individual])
|
| 345 |
+
|
| 346 |
+
# ---------------------------------------------------------
|
| 347 |
+
# Error Box
|
| 348 |
+
error_box = gr.Text(value=None, visible=False)
|
| 349 |
+
|
| 350 |
+
# ---------------------------------------------------------
|
| 351 |
+
# Spacer
|
| 352 |
+
with gr.Row(elem_id="centered-row"):
|
| 353 |
+
gr.Image(PATH_ICONS+"animal.png", height=80, width=80,
|
| 354 |
+
interactive=False,
|
| 355 |
+
show_fullscreen_button = False, show_share_button=False,
|
| 356 |
+
show_download_button=False, show_label=False)
|
| 357 |
+
advanced.css = """
|
| 358 |
+
#centered-row {
|
| 359 |
+
display: flex;
|
| 360 |
+
justify-content: center;
|
| 361 |
+
}
|
| 362 |
+
"""
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
# ---------------------------------------------------------
|
| 366 |
+
# Allow clearing of all previous output
|
| 367 |
+
with gr.Row():
|
| 368 |
+
button_df = gr.Button("SUBMIT OBSERVATION", icon=PATH_ICONS+"effective.png",
|
| 369 |
+
scale = 3)
|
| 370 |
+
button_clear = gr.ClearButton(value="CLEAR",
|
| 371 |
+
scale = 1,
|
| 372 |
+
components=[
|
| 373 |
+
camera,
|
| 374 |
+
location, identified_location,
|
| 375 |
+
#dead reset
|
| 376 |
+
radio_circumstance_dead, radio_physical_dead,
|
| 377 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 378 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
|
| 379 |
+
physical_boxes_dead,
|
| 380 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead,
|
| 381 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead,
|
| 382 |
+
fe_name_recipient_dead, fe_collection_ref_dead,
|
| 383 |
+
#wounded reset
|
| 384 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 385 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 386 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 387 |
+
behavior_checkbox, behavior_text,
|
| 388 |
+
physical_boxes_wounded,
|
| 389 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded,
|
| 390 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded,
|
| 391 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded,
|
| 392 |
+
error_box
|
| 393 |
+
])
|
| 394 |
+
show_creds = gr.Button("CREDITS", icon=PATH_ICONS+"copyright.png", scale=0.5)
|
| 395 |
+
|
| 396 |
+
# ---------------------------------------------------------
|
| 397 |
+
# Button Click Logic
|
| 398 |
+
button_clear.click()
|
| 399 |
+
button_clear.click(hide_physical,
|
| 400 |
+
outputs=[checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded])
|
| 401 |
+
button_clear.click(hide_physical,
|
| 402 |
+
outputs=[checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead])
|
| 403 |
+
button_clear.click(reset_error_box, inputs=[error_box], outputs=[error_box])
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
# ---------------------------------------------------------
|
| 407 |
+
# VALIDATE ANIMAL
|
| 408 |
+
button_df.click(validate_save_individual, inputs=[individual, error_box],
|
| 409 |
+
outputs=[error_box])
|
| 410 |
+
# ---------------------------------------------------------
|
| 411 |
+
#CREDITS
|
| 412 |
+
with Modal(visible=False) as modal_creds:
|
| 413 |
+
gr.Markdown(credits_text)
|
| 414 |
+
show_creds.click(lambda: Modal(visible=True), None, modal_creds)
|
app/mode_simple.py
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_modal import Modal
|
| 3 |
+
|
| 4 |
+
from validation_submission.utils_individual import add_data_to_individual
|
| 5 |
+
from validation_submission.submission import validate_save_individual
|
| 6 |
+
from validation_submission.validation import reset_error_box
|
| 7 |
+
from geolocalisation.maps import get_location
|
| 8 |
+
from functools import partial
|
| 9 |
+
from dead import show_section_dead
|
| 10 |
+
from wounded import show_section_wounded
|
| 11 |
+
from circumstances.circumstances import show_circumstances
|
| 12 |
+
from circumstances.circumstances_dropdowns import *
|
| 13 |
+
from physical.physical_select_animal import show_physical, find_bounding_box
|
| 14 |
+
from physical.physical_checkbox import on_select_body_part, hide_physical
|
| 15 |
+
from behavior.behavior_checkbox import show_behavior, on_select_behavior
|
| 16 |
+
from follow_up.followup_events import save_fe
|
| 17 |
+
from styling.style import *
|
| 18 |
+
from credits import credits_text
|
| 19 |
+
|
| 20 |
+
from geolocalisation.js_geolocation import js_geocode, display_location
|
| 21 |
+
from validation_submission.utils_individual import generate_random_md5
|
| 22 |
+
|
| 23 |
+
from dotenv import load_dotenv
|
| 24 |
+
import os
|
| 25 |
+
load_dotenv()
|
| 26 |
+
PATH = os.getcwd() + "/"
|
| 27 |
+
PATH_ASSETS = os.getenv('PATH_ASSETS')
|
| 28 |
+
PATH_ICONS = PATH + PATH_ASSETS + "icons/"
|
| 29 |
+
|
| 30 |
+
with gr.Blocks(theme='shivi/calm_seafoam') as simple:
|
| 31 |
+
individual = gr.State({})
|
| 32 |
+
individual.value = add_data_to_individual("image_md5", generate_random_md5(), individual.value)
|
| 33 |
+
|
| 34 |
+
# ---------------------------------------------------------
|
| 35 |
+
# Header Text
|
| 36 |
+
with gr.Row():
|
| 37 |
+
gr.Image(PATH_ICONS+"swallow.png", scale =0.1,
|
| 38 |
+
interactive=False,
|
| 39 |
+
show_fullscreen_button = False, show_share_button=False,
|
| 40 |
+
show_download_button=False, show_label=False)
|
| 41 |
+
with gr.Column(scale=1):
|
| 42 |
+
title = gr.Markdown("# Welcome to Digiwild", label="Title")
|
| 43 |
+
description = gr.Markdown("## Please record your wildlife observations here !", label="description")
|
| 44 |
+
|
| 45 |
+
# ---------------------------------------------------------
|
| 46 |
+
# Camera
|
| 47 |
+
with gr.Row():
|
| 48 |
+
def save_image(camera, individual):
|
| 49 |
+
individual = add_data_to_individual("image", camera.tolist(), individual)
|
| 50 |
+
return individual
|
| 51 |
+
camera = gr.Image(elem_id="image")
|
| 52 |
+
camera.input(save_image, inputs=[camera, individual], outputs=[individual])
|
| 53 |
+
|
| 54 |
+
# ---------------------------------------------------------
|
| 55 |
+
# General Details
|
| 56 |
+
with gr.Column(scale=1):
|
| 57 |
+
gr.Button("General Details", icon=PATH_ICONS+"pigeon.png", variant="primary")
|
| 58 |
+
|
| 59 |
+
with gr.Row():
|
| 60 |
+
specie = gr.Textbox(
|
| 61 |
+
label="Species (if known)",
|
| 62 |
+
placeholder="e.g. European Robin, Common Blackbird",
|
| 63 |
+
info="Enter the species name if you can identify it. If unsure, provide your best guess or general description (e.g. 'small brown bird')",
|
| 64 |
+
visible=True,
|
| 65 |
+
interactive=True
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
# Number of individuals
|
| 69 |
+
with gr.Row():
|
| 70 |
+
num_individuals = gr.Number(
|
| 71 |
+
label="Number of Individuals",
|
| 72 |
+
value=1, # Default value
|
| 73 |
+
minimum=1,
|
| 74 |
+
precision=0, # Only whole numbers
|
| 75 |
+
info="Enter the number of animals observed",
|
| 76 |
+
#placeholder="Enter number...",
|
| 77 |
+
visible=True,
|
| 78 |
+
interactive=True
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
# Introducing text_box for comments
|
| 82 |
+
with gr.Row():
|
| 83 |
+
comments = gr.TextArea(
|
| 84 |
+
label="Additional Comments",
|
| 85 |
+
placeholder="Enter any additional observations or notes about the sighting...",
|
| 86 |
+
info="Optional: Add any relevant details about the animal(s) or circumstances",
|
| 87 |
+
lines=3,
|
| 88 |
+
max_lines=5,
|
| 89 |
+
visible=True,
|
| 90 |
+
interactive=True
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
with gr.Row():
|
| 94 |
+
with gr.Column(scale=1):
|
| 95 |
+
# Geolocation
|
| 96 |
+
gr.Button("Location", icon=PATH_ICONS+"pin.png", variant="primary")
|
| 97 |
+
location_data = gr.JSON(label="Identified GPS Location")
|
| 98 |
+
hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 99 |
+
btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required)")
|
| 100 |
+
btn_gpslocation.click(None, [], [], js=js_geocode)
|
| 101 |
+
hidden_input.change(display_location, inputs=hidden_input, outputs=location_data)
|
| 102 |
+
|
| 103 |
+
# ---------------------------------------------------------
|
| 104 |
+
# Dead and Wounded Buttons
|
| 105 |
+
gr.Button("State of the Animal", variant="primary")
|
| 106 |
+
with gr.Row():
|
| 107 |
+
gr.Image(PATH_ICONS+"medical-app.png", scale =0.1,
|
| 108 |
+
interactive=False,
|
| 109 |
+
show_fullscreen_button = False, show_share_button=False,
|
| 110 |
+
show_download_button=False, show_label=False)
|
| 111 |
+
with gr.Column():
|
| 112 |
+
gr.Markdown("## The State of the Animal", label="Title")
|
| 113 |
+
gr.Markdown("Please tell us if the animal was wounded / sick or dead.", label="description")
|
| 114 |
+
gr.Markdown("Please fill out as many fields as you can, based on what you can see.", label="description")
|
| 115 |
+
gr.Markdown("### DO NOT TOUCH the animal unless absolutely necessary.", label="description")
|
| 116 |
+
with gr.Row() as block_form:
|
| 117 |
+
with gr.Column(scale=1):
|
| 118 |
+
butt_wounded = gr.Button("Wounded / Sick", elem_id="wounded")
|
| 119 |
+
with gr.Column(scale=1):
|
| 120 |
+
butt_dead = gr.Button("Dead", elem_id="dead")
|
| 121 |
+
|
| 122 |
+
# ---------------------------------------------------------
|
| 123 |
+
# Initiate sections
|
| 124 |
+
section_dead, individual, radio_circumstance_dead, radio_physical_dead,\
|
| 125 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
| 126 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 127 |
+
physical_boxes_dead, \
|
| 128 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
| 129 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 130 |
+
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 131 |
+
= show_section_dead(False, individual)
|
| 132 |
+
|
| 133 |
+
section_wounded, individual, radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
| 134 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
| 135 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
| 136 |
+
behavior_checkbox, behavior_text, \
|
| 137 |
+
physical_boxes_wounded, \
|
| 138 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
| 139 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 140 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 141 |
+
= show_section_wounded(False, individual)
|
| 142 |
+
|
| 143 |
+
# ---------------------------------------------------------
|
| 144 |
+
# ---------------------------------------------------------
|
| 145 |
+
# ---------------------------------------------------------
|
| 146 |
+
# Dead Button Logic
|
| 147 |
+
partial_show_section_dead = partial(show_section_dead, True)
|
| 148 |
+
partial_hide_section_wounded = partial(show_section_wounded, False)
|
| 149 |
+
butt_dead.click(partial_show_section_dead,
|
| 150 |
+
inputs=[individual],
|
| 151 |
+
outputs=[section_dead,
|
| 152 |
+
individual,
|
| 153 |
+
radio_circumstance_dead, radio_physical_dead,
|
| 154 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 155 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 156 |
+
physical_boxes_dead, \
|
| 157 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
| 158 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 159 |
+
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 160 |
+
])
|
| 161 |
+
|
| 162 |
+
butt_dead.click(partial_hide_section_wounded,
|
| 163 |
+
inputs=[individual],
|
| 164 |
+
outputs=[section_wounded,
|
| 165 |
+
individual,
|
| 166 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 167 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 168 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 169 |
+
behavior_checkbox, behavior_text,
|
| 170 |
+
physical_boxes_wounded, \
|
| 171 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
| 172 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 173 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 174 |
+
])
|
| 175 |
+
|
| 176 |
+
# ---------------------------------------------------------
|
| 177 |
+
# Wounded Button Logic
|
| 178 |
+
partial_show_section_wounded = partial(show_section_wounded, True)
|
| 179 |
+
partial_hide_section_dead = partial(show_section_dead, False)
|
| 180 |
+
|
| 181 |
+
butt_wounded.click(partial_show_section_wounded,
|
| 182 |
+
inputs=[individual],
|
| 183 |
+
outputs=[section_wounded,
|
| 184 |
+
individual,
|
| 185 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 186 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 187 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 188 |
+
behavior_checkbox, behavior_text,
|
| 189 |
+
physical_boxes_wounded, \
|
| 190 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
| 191 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 192 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 193 |
+
])
|
| 194 |
+
|
| 195 |
+
butt_wounded.click(partial_hide_section_dead,
|
| 196 |
+
inputs=[individual],
|
| 197 |
+
outputs=[section_dead,
|
| 198 |
+
individual,
|
| 199 |
+
radio_circumstance_dead, radio_physical_dead,
|
| 200 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 201 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 202 |
+
physical_boxes_dead, \
|
| 203 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
| 204 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 205 |
+
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 206 |
+
])
|
| 207 |
+
|
| 208 |
+
# ---------------------------------------------------------
|
| 209 |
+
# ---------------------------------------------------------
|
| 210 |
+
# ---------------------------------------------------------
|
| 211 |
+
# ---------------------------------------------------------
|
| 212 |
+
# DEAD
|
| 213 |
+
# ---------------------------------------------------------
|
| 214 |
+
# Radio Circumstance Dead
|
| 215 |
+
radio_circumstance_dead.change(fn=show_circumstances,
|
| 216 |
+
inputs=[radio_circumstance_dead, individual],
|
| 217 |
+
outputs=[button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 218 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual]
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
# Dropdowns Dead
|
| 222 |
+
button_collision_dead.click(dropdown_collision,
|
| 223 |
+
inputs=[individual],
|
| 224 |
+
outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 225 |
+
button_deliberate_destruction_dead.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 226 |
+
button_indirect_destruction_dead.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 227 |
+
button_natural_cause_dead.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 228 |
+
|
| 229 |
+
dropdown_dead.select(on_select, inputs=[individual], outputs=[dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 230 |
+
dropdown_level2_dead.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual] )
|
| 231 |
+
openfield_level2_dead.change(on_change_openfield_level2, inputs=[openfield_level2_dead, individual], outputs=[individual])
|
| 232 |
+
dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])
|
| 233 |
+
# ---------------------------------------------------------
|
| 234 |
+
# Radio Physical Dead
|
| 235 |
+
radio_physical_dead.change(fn=show_physical,
|
| 236 |
+
inputs=[radio_physical_dead, gr.Text("dead", visible=False), individual],
|
| 237 |
+
outputs=[physical_boxes_dead, individual])
|
| 238 |
+
|
| 239 |
+
# Checkbox Physical Dead
|
| 240 |
+
physical_boxes_dead.select(find_bounding_box,
|
| 241 |
+
inputs=[physical_boxes_dead, gr.Textbox(value="dead", visible=False)],
|
| 242 |
+
outputs=[checkbox_beak_dead, text_beak_dead,
|
| 243 |
+
checkbox_body_dead, text_body_dead,
|
| 244 |
+
checkbox_feathers_dead, text_feathers_dead,
|
| 245 |
+
checkbox_head_dead, text_head_dead,
|
| 246 |
+
checkbox_legs_dead, text_legs_dead
|
| 247 |
+
])
|
| 248 |
+
checkbox_beak_dead.select(on_select_body_part, inputs=[checkbox_beak_dead, gr.Text("beak", visible=False), individual], outputs=[individual])
|
| 249 |
+
checkbox_body_dead.select(on_select_body_part, inputs=[checkbox_body_dead, gr.Text("body", visible=False), individual], outputs=[individual])
|
| 250 |
+
checkbox_feathers_dead.select(on_select_body_part, inputs=[checkbox_feathers_dead, gr.Text("feathers", visible=False), individual], outputs=[individual])
|
| 251 |
+
checkbox_head_dead.select(on_select_body_part, inputs=[checkbox_head_dead, gr.Text("head", visible=False), individual], outputs=[individual])
|
| 252 |
+
checkbox_legs_dead.select(on_select_body_part, inputs=[checkbox_legs_dead, gr.Text("legs", visible=False), individual], outputs=[individual])
|
| 253 |
+
# ---------------------------------------------------------
|
| 254 |
+
# ---------------------------------------------------------
|
| 255 |
+
# ---------------------------------------------------------
|
| 256 |
+
# ---------------------------------------------------------
|
| 257 |
+
# WOUNDED
|
| 258 |
+
# ---------------------------------------------------------
|
| 259 |
+
# Radio Circumstance Wounded
|
| 260 |
+
radio_circumstance_wounded.change(fn=show_circumstances,
|
| 261 |
+
inputs=[radio_circumstance_wounded, individual],
|
| 262 |
+
outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 263 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual]
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
# Dropdowns Circumstance Wounded
|
| 267 |
+
button_collision_wounded.click(dropdown_collision,
|
| 268 |
+
inputs=[individual],
|
| 269 |
+
outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 270 |
+
button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 271 |
+
button_indirect_destruction_wounded.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 272 |
+
button_natural_cause_wounded.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 273 |
+
|
| 274 |
+
dropdown_wounded.select(on_select, inputs=[individual], outputs=[dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 275 |
+
dropdown_level2_wounded.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])
|
| 276 |
+
openfield_level2_wounded.change(on_change_openfield_level2, inputs=[openfield_level2_wounded, individual])
|
| 277 |
+
dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])
|
| 278 |
+
# ---------------------------------------------------------
|
| 279 |
+
# Radio Behavior Wounded
|
| 280 |
+
radio_behavior_wounded.change(fn=show_behavior,
|
| 281 |
+
inputs=[radio_behavior_wounded, gr.Text("wounded / sick", visible=False), individual],
|
| 282 |
+
outputs=[behavior_checkbox, behavior_text, individual])
|
| 283 |
+
behavior_checkbox.select(on_select_behavior,
|
| 284 |
+
inputs=[behavior_checkbox, individual],
|
| 285 |
+
outputs=[individual])
|
| 286 |
+
# ---------------------------------------------------------
|
| 287 |
+
# Radio Physical Wounded
|
| 288 |
+
radio_physical_wounded.change(fn=show_physical,
|
| 289 |
+
inputs=[radio_physical_wounded, gr.Text("wounded / sick", visible=False), individual],
|
| 290 |
+
outputs=[physical_boxes_wounded, individual])
|
| 291 |
+
|
| 292 |
+
# Checkbox Physical Wounded
|
| 293 |
+
physical_boxes_wounded.select(find_bounding_box,
|
| 294 |
+
inputs=[physical_boxes_wounded, gr.Textbox(value="wounded / sick", visible=False)],
|
| 295 |
+
outputs=[checkbox_beak_wounded, text_beak_wounded,
|
| 296 |
+
checkbox_body_wounded, text_body_wounded,
|
| 297 |
+
checkbox_feathers_wounded, text_feathers_wounded,
|
| 298 |
+
checkbox_head_wounded, text_head_wounded,
|
| 299 |
+
checkbox_legs_wounded, text_legs_wounded
|
| 300 |
+
])
|
| 301 |
+
checkbox_beak_wounded.select(on_select_body_part, inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False), individual], outputs=[individual])
|
| 302 |
+
checkbox_body_wounded.select(on_select_body_part, inputs=[checkbox_body_wounded, gr.Text("body", visible=False), individual], outputs=[individual])
|
| 303 |
+
checkbox_feathers_wounded.select(on_select_body_part, inputs=[checkbox_feathers_wounded, gr.Text("feathers", visible=False), individual], outputs=[individual])
|
| 304 |
+
checkbox_head_wounded.select(on_select_body_part, inputs=[checkbox_head_wounded, gr.Text("head", visible=False), individual], outputs=[individual])
|
| 305 |
+
checkbox_legs_wounded.select(on_select_body_part, inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False), individual], outputs=[individual])
|
| 306 |
+
|
| 307 |
+
# ---------------------------------------------------------
|
| 308 |
+
# Follow Up Events Wounded
|
| 309 |
+
fe_collection_dropdown_wounded.select(save_fe, inputs=[fe_collection_dropdown_wounded, gr.Textbox("animal collected", visible=False), individual], outputs=[individual])
|
| 310 |
+
fe_recepient_dropdown_wounded.select(save_fe, inputs=[fe_recepient_dropdown_wounded, gr.Textbox("recipient", visible=False), individual],outputs=[individual])
|
| 311 |
+
fe_radio_dropdown_wounded.select(save_fe, inputs=[fe_radio_dropdown_wounded, gr.Textbox("radiography", visible=False), individual],outputs=[individual])
|
| 312 |
+
fe_answer_dropdown_wounded.select(save_fe, inputs=[fe_answer_dropdown_wounded, gr.Textbox("given answer", visible=False), individual],outputs=[individual])
|
| 313 |
+
fe_name_recipient_wounded.input(save_fe, inputs=[fe_name_recipient_wounded, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])
|
| 314 |
+
fe_collection_ref_wounded.input(save_fe, inputs=[fe_collection_ref_wounded, gr.Textbox("collection reference", visible=False), individual],outputs=[individual])
|
| 315 |
+
|
| 316 |
+
# ---------------------------------------------------------
|
| 317 |
+
# Follow Up Events Dead
|
| 318 |
+
fe_collection_dropdown_dead.select(save_fe, inputs=[fe_collection_dropdown_dead, gr.Textbox("animal collected", visible=False), individual],outputs=[individual])
|
| 319 |
+
fe_recepient_dropdown_dead.select(save_fe, inputs=[fe_recepient_dropdown_dead, gr.Textbox("recipient", visible=False), individual],outputs=[individual])
|
| 320 |
+
fe_radio_dropdown_dead.select(save_fe, inputs=[fe_radio_dropdown_dead, gr.Textbox("radiography", visible=False), individual],outputs=[individual])
|
| 321 |
+
fe_answer_dropdown_dead.select(save_fe, inputs=[fe_answer_dropdown_dead, gr.Textbox("given answer", visible=False), individual],outputs=[individual])
|
| 322 |
+
fe_name_recipient_dead.input(save_fe, inputs=[fe_name_recipient_dead, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])
|
| 323 |
+
fe_collection_ref_dead.input(save_fe, inputs=[fe_collection_ref_dead, gr.Textbox("collection reference", visible=False), individual], outputs=[individual])
|
| 324 |
+
|
| 325 |
+
# ---------------------------------------------------------
|
| 326 |
+
# Error Box
|
| 327 |
+
error_box = gr.Text(value=None, visible=False)
|
| 328 |
+
|
| 329 |
+
# ---------------------------------------------------------
|
| 330 |
+
# Spacer
|
| 331 |
+
with gr.Row(elem_id="centered-row"):
|
| 332 |
+
gr.Image(PATH_ICONS+"chicken.png", height=80, width=80,
|
| 333 |
+
interactive=False,
|
| 334 |
+
show_fullscreen_button = False, show_share_button=False,
|
| 335 |
+
show_download_button=False, show_label=False)
|
| 336 |
+
simple.css = """
|
| 337 |
+
#centered-row {
|
| 338 |
+
display: flex;
|
| 339 |
+
justify-content: center;
|
| 340 |
+
}
|
| 341 |
+
"""
|
| 342 |
+
|
| 343 |
+
# ---------------------------------------------------------
|
| 344 |
+
# Allow clearing of all previous output
|
| 345 |
+
with gr.Row():
|
| 346 |
+
button_df = gr.Button("SUBMIT OBSERVATION", icon=PATH_ICONS+"effective.png",
|
| 347 |
+
scale = 3)
|
| 348 |
+
button_clear = gr.ClearButton(value="CLEAR",
|
| 349 |
+
scale = 1,
|
| 350 |
+
components=[
|
| 351 |
+
camera,
|
| 352 |
+
#dead reset
|
| 353 |
+
radio_circumstance_dead, radio_physical_dead,
|
| 354 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 355 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
|
| 356 |
+
physical_boxes_dead,
|
| 357 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead,
|
| 358 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead,
|
| 359 |
+
fe_name_recipient_dead, fe_collection_ref_dead,
|
| 360 |
+
#wounded reset
|
| 361 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 362 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 363 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 364 |
+
behavior_checkbox, behavior_text,
|
| 365 |
+
physical_boxes_wounded,
|
| 366 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded,
|
| 367 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded,
|
| 368 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded,
|
| 369 |
+
error_box
|
| 370 |
+
])
|
| 371 |
+
show_creds = gr.Button("CREDITS", icon=PATH_ICONS+"copyright.png", scale=0.5)
|
| 372 |
+
|
| 373 |
+
# ---------------------------------------------------------
|
| 374 |
+
# Button Click Logic
|
| 375 |
+
button_clear.click()
|
| 376 |
+
button_clear.click(hide_physical,
|
| 377 |
+
outputs=[checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded])
|
| 378 |
+
button_clear.click(hide_physical,
|
| 379 |
+
outputs=[checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead])
|
| 380 |
+
button_clear.click(reset_error_box, inputs=[error_box], outputs=[error_box])
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
# ---------------------------------------------------------
|
| 384 |
+
# VALIDATE ANIMAL
|
| 385 |
+
button_df.click(validate_save_individual, inputs=[individual, error_box],
|
| 386 |
+
outputs=[error_box])
|
| 387 |
+
# ---------------------------------------------------------
|
| 388 |
+
#CREDITS
|
| 389 |
+
with Modal(visible=False) as modal_creds:
|
| 390 |
+
gr.Markdown(credits_text)
|
| 391 |
+
show_creds.click(lambda: Modal(visible=True), None, modal_creds)
|
requirements.txt
CHANGED
|
@@ -5,5 +5,4 @@ geopandas
|
|
| 5 |
pillow
|
| 6 |
python-dotenv
|
| 7 |
datasets
|
| 8 |
-
huggingface_hub
|
| 9 |
-
hashlib
|
|
|
|
| 5 |
pillow
|
| 6 |
python-dotenv
|
| 7 |
datasets
|
| 8 |
+
huggingface_hub
|
|
|