File size: 19,444 Bytes
8f0e835 ec819d9 3ae828c 161d75f ec819d9 161d75f 3ae828c 8f0e835 f19bc2d a3786fb 3ae828c ee406aa a725af0 a3786fb 923fa20 8f0e835 3ae828c 8f0e835 a3786fb 8f0e835 a3786fb 8f0e835 f19bc2d 8f0e835 f19bc2d 8f0e835 ec819d9 0de94b5 ec819d9 0de94b5 ec819d9 f19bc2d ec819d9 0de94b5 ec819d9 0de94b5 ec819d9 a725af0 ec819d9 0de94b5 ec819d9 0de94b5 ec819d9 a725af0 ec819d9 f19bc2d a725af0 f19bc2d ec819d9 161d75f ec819d9 8f0e835 ec819d9 ce3810b a725af0 ce3810b ec819d9 f19bc2d ec819d9 f19bc2d ec819d9 f19bc2d 0de94b5 995b526 0de94b5 995b526 ec819d9 f19bc2d ee406aa f19bc2d a3786fb f19bc2d 0de94b5 f19bc2d 0de94b5 f19bc2d cf0242a a3786fb a725af0 923fa20 f19bc2d ee406aa f19bc2d a3786fb 3ae828c a3786fb 8f0e835 cf0242a 8f0e835 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
import gradio as gr
from gradio_modal import Modal
from validation_submission.create_json import create_json_all_individuals, create_json_one_individual, create_tmp
from validation_submission.add_json import add_data_to_individual
from gallery import save_individual_to_gallery
from geolocalisation.maps import get_location
from functools import partial
from dead import show_section_dead
from wounded import show_section_wounded
from circumstances.circumstances import show_circumstances
from circumstances.circumstances_dropdowns import *
from physical.physical_select_animal import show_physical, find_bounding_box
from physical.physical_checkbox import on_select_body_part, hide_physical
from behavior.behavior_checkbox import show_behavior, on_select_behavior
from follow_up.followup_events import save_fe
from styling.style import *
from styling.theme import theme, css
from classes import Report
with gr.Blocks(theme=theme, css=css) as demo:
create_json_all_individuals()
# ---------------------------------------------------------
# Intro Text
with gr.Row():
with gr.Column(scale=1):
title = gr.Markdown("# Welcome to Digiwild", label="Title")
description = gr.Markdown("Please record your wildlife observations here !", label="description")
with gr.Row():
show_modal = gr.Button("Add an Animal", scale=3)
submit_button = gr.Button("Submit All Animals", scale=1)
df = gr.Dataframe(headers=["Identifier", "Location", "Wounded", "Dead"], visible=False, interactive=False)
gallery = gr.Gallery(
label="Gallery of Records", elem_id="gallery",
columns=[1], rows=[1],
object_fit="contain", height="auto", interactive=False)
with Modal(visible=False) as modal:
# ---------------------------------------------------------
# Intro Text
with gr.Row():
with gr.Column(scale=1):
title = gr.Markdown("# Animal Report", label="Title")
description = gr.Markdown("Please record your observation here.", label="description")
# ---------------------------------------------------------
# Camera
with gr.Row():
def save_image(camera):
add_data_to_individual("image", camera.tolist())
camera = gr.Image(elem_id="image")
camera.input(save_image, inputs=[camera])
# ---------------------------------------------------------
# Location
#with gr.Row():
with gr.Column(scale=1):
location = gr.Textbox(visible=True, interactive=True, label="Location of Sighting")
#display location processing
identified_location= gr.Textbox(visible=False, interactive=False,
label="Identified GPS Location")
with gr.Row():
#to submit it
submit_location = gr.Button("Get GPS Coordinates",
visible=True, interactive=True, scale=3)
submit_location.click(get_location, inputs=[location], outputs=[identified_location])
#to clear it
clear_location = gr.ClearButton(components=[location, identified_location],
visible=True, interactive=True, scale=1
)
clear_location.click()
# ---------------------------------------------------------
# ---------------------------------------------------------
# Dead and Wounded Buttons
gr.Markdown("## The State of the Animal", label="Title")
gr.Markdown("Please tell us if the animal was wounded or dead.", label="description")
with gr.Row() as block_form:
with gr.Column(scale=1):
butt_wounded = gr.Button("Wounded", elem_id="wounded")
with gr.Column(scale=1):
butt_dead = gr.Button("Dead", elem_id="dead")
# ---------------------------------------------------------
# Initiate sections
section_dead, \
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
fe_name_recipient_dead, fe_collection_ref_dead \
= show_section_dead(False)
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
behavior_checkbox, behavior_text, \
physical_boxes_wounded, \
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs, \
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
fe_name_recipient_wounded, fe_collection_ref_wounded \
= show_section_wounded(False)
# ---------------------------------------------------------
# ---------------------------------------------------------
# ---------------------------------------------------------
# Dead Button Logic
partial_show_section_dead = partial(show_section_dead, True)
partial_hide_section_wounded = partial(show_section_wounded, False)
butt_dead.click(partial_show_section_dead,
inputs=None,
outputs=[section_dead,
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
fe_name_recipient_dead, fe_collection_ref_dead \
])
butt_dead.click(partial_hide_section_wounded,
inputs=None,
outputs=[section_wounded,
radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded,
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
behavior_checkbox, behavior_text,
physical_boxes_wounded,
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs, \
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
fe_name_recipient_wounded, fe_collection_ref_wounded \
])
# ---------------------------------------------------------
# Wounded Button Logic
partial_show_section_wounded = partial(show_section_wounded, True)
partial_hide_section_dead = partial(show_section_dead, False)
butt_wounded.click(partial_show_section_wounded,
inputs=None,
outputs=[section_wounded,
radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded,
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
behavior_checkbox, behavior_text,
physical_boxes_wounded,
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs, \
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
fe_name_recipient_wounded, fe_collection_ref_wounded \
])
butt_wounded.click(partial_hide_section_dead, inputs=None, outputs=[section_dead,
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
fe_name_recipient_dead, fe_collection_ref_dead \
])
def save_wounded_state():
add_data_tmp("wounded_dead", "wounded", "Yes")
butt_wounded.click(save_wounded_state())
# ---------------------------------------------------------
# Dropdowns Dead
button_collision_dead.click(dropdown_collision,
outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
button_deliberate_destruction_dead.click(dropdown_deliberate_destruction, outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
button_indirect_destruction_dead.click(dropdown_indirect_destruction, outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
button_natural_cause_dead.click(dropdown_natural_cause, outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
dropdown_dead.select(on_select, None, [dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
dropdown_level2_dead.select(on_select_dropdown_level2)
openfield_level2_dead.input(on_change_openfield_level2)
dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2)
# ---------------------------------------------------------
# Radio Cause Wounded
radio_cause_wounded.change(fn=show_circumstances,
inputs=[radio_cause_wounded],
outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded]
)
# Dropdowns Cause Wounded
button_collision_wounded.click(dropdown_collision,
outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
button_indirect_destruction_wounded.click(dropdown_indirect_destruction, outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
button_natural_cause_wounded.click(dropdown_natural_cause, outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
dropdown_wounded.select(on_select, None, [dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
dropdown_level2_wounded.select(on_select_dropdown_level2)
openfield_level2_wounded.select(on_change_openfield_level2)
dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2)
# ---------------------------------------------------------
# Radio Behavior Wounded
radio_behavior_wounded.change(fn=show_behavior,
inputs=[radio_behavior_wounded, gr.Text("wounded", visible=False)],
outputs=[behavior_checkbox, behavior_text])
behavior_checkbox.select(on_select_behavior,
inputs=[behavior_checkbox])
# ---------------------------------------------------------
# Radio Physical Wounded
radio_physical_wounded.change(fn=show_physical,
inputs=[radio_physical_wounded, gr.Text("wounded", visible=False)],
outputs=[physical_boxes_wounded])
# Checkbox Physical Wounded
physical_boxes_wounded.select(find_bounding_box,
inputs=[physical_boxes_wounded, gr.Textbox(value="wounded", visible=False)],
outputs=[checkbox_beak, text_beak,
checkbox_body, text_body,
checkbox_feathers, text_feathers,
checkbox_head, text_head,
checkbox_legs, text_legs
])
checkbox_beak.select(on_select_body_part, inputs=[checkbox_beak, gr.Text("beak", visible=False)])
checkbox_body.select(on_select_body_part, inputs=[checkbox_body, gr.Text("body", visible=False)])
checkbox_feathers.select(on_select_body_part, inputs=[checkbox_feathers, gr.Text("feathers", visible=False)])
checkbox_head.select(on_select_body_part, inputs=[checkbox_head, gr.Text("head", visible=False)])
checkbox_legs.select(on_select_body_part, inputs=[checkbox_legs, gr.Text("legs", visible=False)])
# ---------------------------------------------------------
# Follow Up Events Wounded
fe_collection_dropdown_wounded.select(save_fe, inputs=[fe_collection_dropdown_wounded, gr.Textbox("animal collected", visible=False)])
fe_recepient_dropdown_wounded.select(save_fe, inputs=[fe_recepient_dropdown_wounded, gr.Textbox("recipient", visible=False)])
fe_radio_dropdown_wounded.select(save_fe, inputs=[fe_radio_dropdown_wounded, gr.Textbox("radiography", visible=False)])
fe_answer_dropdown_wounded.select(save_fe, inputs=[fe_answer_dropdown_wounded, gr.Textbox("given answer", visible=False)])
fe_name_recipient_wounded.input(save_fe, inputs=[fe_name_recipient_wounded, gr.Textbox("recipient name", visible=False)])
fe_collection_ref_wounded.input(save_fe, inputs=[fe_collection_ref_wounded, gr.Textbox("collection reference", visible=False)])
# ---------------------------------------------------------
# Follow Up Events Dead
fe_collection_dropdown_dead.select(save_fe, inputs=[fe_collection_dropdown_dead, gr.Textbox("animal collected", visible=False)])
fe_recepient_dropdown_dead.select(save_fe, inputs=[fe_recepient_dropdown_dead, gr.Textbox("recipient", visible=False)])
fe_radio_dropdown_dead.select(save_fe, inputs=[fe_radio_dropdown_dead, gr.Textbox("radiography", visible=False)])
fe_answer_dropdown_dead.select(save_fe, inputs=[fe_answer_dropdown_dead, gr.Textbox("given answer", visible=False)])
fe_name_recipient_dead.input(save_fe, inputs=[fe_name_recipient_dead, gr.Textbox("recipient name", visible=False)])
fe_collection_ref_dead.input(save_fe, inputs=[fe_collection_ref_dead, gr.Textbox("collection reference", visible=False)])
# ---------------------------------------------------------
# Add One Individual's Data to the Dataframe
# And Allow clearing of all previous output
with gr.Row():
button_df = gr.Button("Submit Animal Report", scale = 3)
button_clear = gr.ClearButton(scale = 1,
components=[
camera,
location, identified_location,
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead,
fe_name_recipient_dead, fe_collection_ref_dead,
radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded,
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
behavior_checkbox, behavior_text,
physical_boxes_wounded,
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs,
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded,
fe_name_recipient_wounded, fe_collection_ref_wounded
])
button_clear.click()
button_clear.click(hide_physical,
outputs=[checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs])
# button_df.click(save_individual_to_df,
# inputs=[df],
# outputs=[df])
button_df.click(save_individual_to_gallery,
inputs=[gallery, df],
outputs=[gallery, df]
)
button_df.click(lambda: Modal(visible=False), None, modal)
# ---------------------------------------------------------
# Event Functions of the landing page buttons
show_modal.click(lambda: Modal(visible=True), None, modal)
show_modal.click(create_json_one_individual)
show_modal.click(create_tmp)
#submit_button.click(save_and_rest_df, inputs=[df], outputs=[df])
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=3333) |