caviri commited on
Commit ·
baec762
1
Parent(s): 629cbaa
feat(JSON): individual JSON swapped by gradio state to avoid multiuser overwritting issues
Browse filesFiles changed (18)
- README.md+15-9
- app/behavior/behavior_checkbox.py+6-5
- app/circumstances/circumstances.py+4-4
- app/circumstances/circumstances_dropdowns.py+30-27
- app/dead.py+4-4
- app/display.py+4-3
- app/follow_up/followup_events.py+3-2
- app/geolocalisation/js_geolocation.pyAdded+35
- app/geolocalisation/maps.py+7-6
- app/main.py+149-87
- app/physical/physical_checkbox.py+4-3
- app/physical/physical_select_animal.py+3-3
- app/utils/utils_checkbox.py+5-5
- app/validation_submission/add_json.py+14-10
- app/validation_submission/processing.py+1
- app/validation_submission/submission.py+3-3
- app/validation_submission/validation.py+4-4
- app/wounded.py+5-5
11 unmodified lines12131415161718192021222324252627282930313233343536373839404142431 unmodified line4546474811 unmodified lines## Docker```docker build -t ordes/digiwild .``````docker run -it -p 7860:7860 ordes/digiwild:swallow``````cd /digiwild/apppython3 main.py```### How to develop on docker```docker run -it -p 7860:3333 -v $(pwd):/home/user/digiwild/```## TODO- [ ] Use in memory object instead of files to avoid writting / reading problems.- [ ] Connection to a database? Maybe an open MongoDB- [ ] GPS Compatibility- [ ] New fields suggested## Needs1 unmodified line- Uploading of pics- GPS location- Comments- Symptomps selection (Dropdown)11 unmodified lines1213141516171819202122232425262728293031323334353637383940414243444546471 unmodified line49505152535411 unmodified lines## Docker``` bashdocker build -t ordes/digiwild .`````` bashdocker run -it -p 7860:7860 ordes/digiwild`````` bashcd /digiwild/apppython3 main.py```### How to develop on docker``` bashdocker run -it -p 7860:7860 -v $(pwd):/home/user/digiwild/ ordes/digiwild```## TODO- [x] Change `wounded` to `wounded / sick`- [x] Info formatting- [ ] Use in memory object instead of files to avoid writting / reading problems.- [ ] Connection to a database? Maybe an open MongoDB- [x] GPS Compatibility- [x] New fields suggested: Number individuals, Species, Comments- [ ] Save new fields values into the JSON. Perform validation too.- [ ] Add info and placeholder information to the different components.## Needs1 unmodified line- Uploading of pics- GPS location- Comments- Symptomps selection (Dropdown)## PR Updates
3 unmodified lines45678910111210 unmodified lines23242526272829303 unmodified linesfrom utils.utils_visible import set_visiblefrom validation_submission.add_json import add_data_tmpdef on_select_behavior(behavior_checkbox):behavior_checkbox = [behavior.lower() for behavior in behavior_checkbox]add_data_tmp("wounded_dead", "behaviors_type", behavior_checkbox)def retrieve_behavior_options_description():dropdown_config = get_custom_config_dropdowns("config_checkbox_behavior.json")10 unmodified linescheckbox, text = create_checkbox("", section, label_checkbox, visible, options, descriptions)return checkbox, textdef show_behavior(choice, section: str):visible = set_visible(choice)checkbox, text = create_behavior_checkbox(section, visible)add_data_tmp("wounded_dead", "behaviors_radio", choice)return checkbox, text3 unmodified lines4567891011121310 unmodified lines24252627282930313 unmodified linesfrom utils.utils_visible import set_visiblefrom validation_submission.add_json import add_data_tmpdef on_select_behavior(behavior_checkbox, individual):behavior_checkbox = [behavior.lower() for behavior in behavior_checkbox]individual = add_data_tmp("wounded_dead", "behaviors_type", behavior_checkbox)return individualdef retrieve_behavior_options_description():dropdown_config = get_custom_config_dropdowns("config_checkbox_behavior.json")10 unmodified linescheckbox, text = create_checkbox("", section, label_checkbox, visible, options, descriptions)return checkbox, textdef show_behavior(choice, section: str, individual):visible = set_visible(choice)checkbox, text = create_behavior_checkbox(section, visible)individual = add_data_tmp("wounded_dead", "behaviors_radio", choice, individual)return checkbox, text, individual
12 unmodified lines1314151617181920212223242512 unmodified linesCAUSE_COL_WIDTH = "50px"def show_circumstances(choice):visible = set_visible(choice)add_data_tmp("wounded_dead","circumstance_radio",choice)button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_circumstances(visible)return button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2def create_circumstances(visible):button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause = create_circumstances_buttons(visible)12 unmodified lines1314151617181920212223242512 unmodified linesCAUSE_COL_WIDTH = "50px"def show_circumstances(choice, individual):visible = set_visible(choice)individual = add_data_tmp("wounded_dead","circumstance_radio",choice, individual)button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_circumstances(visible)return button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, individualdef create_circumstances(visible):button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause = create_circumstances_buttons(visible)
13 unmodified lines141516171819202122232425262728293031323334353637383940414243444524 unmodified lines7071727374757677787980818283848 unmodified lines9394959697989910010110210310410510610710810911011111213 unmodified linesdropdown_extra_level2 = gr.Dropdown(choices=[], visible=False)return dropdown_level2, openfield_level2, dropdown_extra_level2def create_dropdown_level1(label):dropdown_config = get_custom_config_dropdowns("config_dropdown_circumstances.json")options = retrieve_config_options(label, dropdown_config)dropdown = gr.Dropdown(choices=options, label=label, interactive=True, visible=True)dropdown_level2, openfield_level2, dropdown_extra_level2 = reinitialise_level2()return dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2def dropdown_collision():label = "Collision with a means of transport"add_data_tmp("wounded_dead", "circumstance", label.lower())return create_dropdown_level1(label)def dropdown_deliberate_destruction():label = "Destruction / Deliberatly removed"add_data_tmp("wounded_dead", "circumstance", label.lower())return create_dropdown_level1(label)def dropdown_indirect_destruction():label = "Indirect destruction"add_data_tmp("wounded_dead", "circumstance", label.lower())return create_dropdown_level1(label)def dropdown_natural_cause():label = "Natural cause"add_data_tmp("wounded_dead", "circumstance", label.lower())return create_dropdown_level1(label)#--------------------------------------------------------- LEVEL 2 DROPDOWNS24 unmodified linesreturn options_label, options_dropdown, open_field, extras, extras_labeldef on_select(evt: gr.SelectData): # SelectData is a subclass of EventDataoptions_label, options_dropdown, open_field, extras, extras_label = get_options(evt.value)add_data_tmp("wounded_dead","circumstance_type",{"type": (evt.value).lower(),"option_dropdown_label" : options_label.lower() if options_label is not None else 'NA',"open_field_label" : open_field.lower() if open_field is not None else 'NA',"extra_label": extras_label.lower() if extras_label is not None else 'NA'})if options_dropdown is not None:dropdown_level2 = gr.Dropdown(choices=options_dropdown, label=evt.value, interactive=True, visible=True)else:8 unmodified linesdropdown_extra_level2 = gr.Dropdown(choices=extras, label=extras_label, interactive=True, visible=True)else:dropdown_extra_level2 = gr.Dropdown(choices=[], visible=False)return dropdown_level2, openfield_level2, dropdown_extra_level2def on_select_dropdown_level2(evt: gr.SelectData):add_data_tmp("wounded_dead","circumstance_option_dropdown",evt.value.lower())def on_select_dropdown_extra_level2(evt: gr.SelectData):add_data_tmp("wounded_dead","circumstance_extra",evt.value.lower())def on_change_openfield_level2(openfield_level2_dead):print("Saving open field")add_data_tmp("wounded_dead","circumstance_open_field",str(openfield_level2_dead).lower())13 unmodified lines141516171819202122232425262728293031323334353637383940414243444524 unmodified lines7071727374757677787980818283848 unmodified lines9394959697989910010110210310410510610710810911011111211311411513 unmodified linesdropdown_extra_level2 = gr.Dropdown(choices=[], visible=False)return dropdown_level2, openfield_level2, dropdown_extra_level2def create_dropdown_level1(label, individual):dropdown_config = get_custom_config_dropdowns("config_dropdown_circumstances.json")options = retrieve_config_options(label, dropdown_config)dropdown = gr.Dropdown(choices=options, label=label, interactive=True, visible=True)dropdown_level2, openfield_level2, dropdown_extra_level2 = reinitialise_level2()return dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, individualdef dropdown_collision(individual):label = "Collision with a means of transport"individual = add_data_tmp("wounded_dead", "circumstance", label.lower(), individual)return create_dropdown_level1(label, individual)def dropdown_deliberate_destruction(individual):label = "Destruction / Deliberatly removed"individual = add_data_tmp("wounded_dead", "circumstance", label.lower(), individual)return create_dropdown_level1(label, individual)def dropdown_indirect_destruction(individual):label = "Indirect destruction"individual = add_data_tmp("wounded_dead", "circumstance", label.lower(), individual)return create_dropdown_level1(label, individual)def dropdown_natural_cause(individual):label = "Natural cause"individual = add_data_tmp("wounded_dead", "circumstance", label.lower(), individual)return create_dropdown_level1(label, individual)#--------------------------------------------------------- LEVEL 2 DROPDOWNS24 unmodified linesreturn options_label, options_dropdown, open_field, extras, extras_labeldef on_select(evt: gr.SelectData, individual): # SelectData is a subclass of EventDataoptions_label, options_dropdown, open_field, extras, extras_label = get_options(evt.value)individual = add_data_tmp("wounded_dead","circumstance_type",{"type": (evt.value).lower(),"option_dropdown_label" : options_label.lower() if options_label is not None else 'NA',"open_field_label" : open_field.lower() if open_field is not None else 'NA',"extra_label": extras_label.lower() if extras_label is not None else 'NA'}, individual)if options_dropdown is not None:dropdown_level2 = gr.Dropdown(choices=options_dropdown, label=evt.value, interactive=True, visible=True)else:8 unmodified linesdropdown_extra_level2 = gr.Dropdown(choices=extras, label=extras_label, interactive=True, visible=True)else:dropdown_extra_level2 = gr.Dropdown(choices=[], visible=False)return dropdown_level2, openfield_level2, dropdown_extra_level2, individualdef on_select_dropdown_level2(evt: gr.SelectData, individual):individual = add_data_tmp("wounded_dead","circumstance_option_dropdown",evt.value.lower(), individual)return individualdef on_select_dropdown_extra_level2(evt: gr.SelectData, individual):individual = add_data_tmp("wounded_dead","circumstance_extra",evt.value.lower(), individual)return individualdef on_change_openfield_level2(openfield_level2_dead, individual):print("Saving open field")individual = add_data_tmp("wounded_dead","circumstance_open_field",str(openfield_level2_dead).lower(), individual)return individual
4 unmodified lines56789101112131417 unmodified lines323334353637384 unmodified linesfrom follow_up.followup_events import create_followup_dropdowns, create_followup_openfrom validation_submission.add_json import add_data_to_individualdef show_section_dead(visible):if visible==True:add_data_to_individual("wounded_state", "No")add_data_to_individual("dead_state", "Yes")with gr.Column(visible=visible, elem_id="dead") as section_dead:gr.Markdown("# Dead Animal")17 unmodified linesfe_name_recipient, fe_collection_ref = create_followup_open(visible, "dead")return section_dead, radio_cause, radio_physical,\button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, \dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, \physical_boxes, \4 unmodified lines56789101112131417 unmodified lines323334353637384 unmodified linesfrom follow_up.followup_events import create_followup_dropdowns, create_followup_openfrom validation_submission.add_json import add_data_to_individualdef show_section_dead(visible, individual):if visible==True:individual = add_data_to_individual("wounded_state", "No", individual)individual = add_data_to_individual("dead_state", "Yes", individual)with gr.Column(visible=visible, elem_id="dead") as section_dead:gr.Markdown("# Dead Animal")17 unmodified linesfe_name_recipient, fe_collection_ref = create_followup_open(visible, "dead")return section_dead, individual, radio_cause, radio_physical,\button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, \dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, \physical_boxes, \
10 unmodified lines11121314151617181920212223242510 unmodified linesHEADERS = ["Identifier", "Location", "Wounded", "Dead"]def save_display_individual(gallery, df, error_box):individual, error_box = validate_save_individual(error_box)if individual:all_animals = get_json_all_individuals()gallery_animals = process_animals_for_gallery(all_animals)gallery = make_gallery(gallery_animals)df_animals = process_animals_for_df(all_animals)df = make_df(df_animals)return gallery, df, error_box# ----------------------------------# GALLERY10 unmodified lines1112131415161718192021222324252610 unmodified linesHEADERS = ["Identifier", "Location", "Wounded", "Dead"]def save_display_individual(gallery, df, error_box, data):#print(data)individual, error_box, data = validate_save_individual(data, error_box)if individual:all_animals = get_json_all_individuals()gallery_animals = process_animals_for_gallery(all_animals)gallery = make_gallery(gallery_animals)df_animals = process_animals_for_df(all_animals)df = make_df(df_animals)return gallery, df, error_box, data# ----------------------------------# GALLERY
38 unmodified lines394041424344454638 unmodified linesvisible=visible, elem_id=elem_id, interactive=True)return fe_answer_dropdowndef save_fe(value, key):add_data_tmp("wounded_dead", "followup " + key.lower(), value.lower())38 unmodified lines39404142434445464738 unmodified linesvisible=visible, elem_id=elem_id, interactive=True)return fe_answer_dropdowndef save_fe(value, key, individual):individual = add_data_tmp("wounded_dead", "followup " + key.lower(), value.lower())return individual
1234567891011121314151617181920212223242526272829303132333435# JavaScript code to get location and update hidden_inputjs_geocode = """ function() { var textbox = document.querySelector('#textbox_id textarea'); console.log(textbox) if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( function(position) { var data = { 'latitude': position.coords.latitude, 'longitude': position.coords.longitude, 'accuracy': position.coords.accuracy }; console.log("Geolocation data:", data); textbox.value = JSON.stringify(data); textbox.dispatchEvent(new Event('input', { bubbles: true })); }, function(error) { var data = {'error': error.message}; console.log("Geolocation error:", data); textbox.value = JSON.stringify(data); textbox.dispatchEvent(new Event('input', { bubbles: true })); } ); } else { var data = {'error': 'Geolocation is not supported by this browser.'}; console.log("Geolocation unsupported:", data); textbox.value = JSON.stringify(data); textbox.dispatchEvent(new Event('input', { bubbles: true })); } }"""
def display_location(location_json): return location_json14 unmodified lines15161718192021222324257 unmodified lines33343536373839404142434445464748495014 unmodified linesprint("Pydantic Error for Geolocalisation")return geolocalisationdef save_geolocalisation_to_json(geolocalisation):geo_dict = geolocalisation.dict()add_data_to_individual("geolocalisation", geo_dict)def get_location(address):try:# calling the Nominatim toolloc = Nominatim(user_agent="GetLoc")7 unmodified lines# Save valuesgeolocalisation = create_geolocalisation_object(lat, lon, address)save_geolocalisation_to_json(geolocalisation)#display location processingvalue = "Latitude = " + str(lat) + "\n" + "Longitude = " + str(lon)identified_location= gr.Textbox(visible=True, interactive=False,label="Identified GPS Location",value=value)return identified_locationexcept:error = "Please try another less precise location."identified_location= gr.Textbox(visible=True, interactive=False,label="Identified GPS Location",value=error)return identified_location14 unmodified lines1516171819202122232425267 unmodified lines34353637383940414243444546474849505114 unmodified linesprint("Pydantic Error for Geolocalisation")return geolocalisationdef save_geolocalisation_to_json(geolocalisation, individual):geo_dict = geolocalisation.dict()individual = add_data_to_individual("geolocalisation", geo_dict, individual)return individualdef get_location(address, individual):try:# calling the Nominatim toolloc = Nominatim(user_agent="GetLoc")7 unmodified lines# Save valuesgeolocalisation = create_geolocalisation_object(lat, lon, address)individual = save_geolocalisation_to_json(geolocalisation, individual)#display location processingvalue = "Latitude = " + str(lat) + "\n" + "Longitude = " + str(lon)identified_location= gr.Textbox(visible=True, interactive=False,label="Identified GPS Location",value=value)return identified_location, individualexcept:error = "Please try another less precise location."identified_location= gr.Textbox(visible=True, interactive=False,label="Identified GPS Location",value=error)return identified_location, individual
17 unmodified lines181920212223242521 unmodified lines47484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031 unmodified line1051061071081091101112 unmodified lines1141151161171181191201212 unmodified lines12412512612712812913013113210 unmodified lines1431441451461471481491501511521531541551561571581591601611621631641651661671682 unmodified lines1711721731741751761771781791801811821831841851861871881891901911921931941951961974 unmodified lines2022032042052062072082092102112122 unmodified lines21521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028142 unmodified lines32432532632732832933033117 unmodified linesfrom styling.style import *from styling.theme import css# with gr.Blocks(theme=theme, css=css) as demo:with gr.Blocks(theme='shivi/calm_seafoam') as demo:create_json_all_individuals()# ---------------------------------------------------------# Intro Text21 unmodified lines# ---------------------------------------------------------# Camerawith 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 processingidentified_location= gr.Textbox(visible=False, interactive=False,label="Identified GPS Location")with gr.Row():#to submit itsubmit_location = gr.Button("Get GPS Coordinates",visible=True, interactive=True, scale=3)submit_location.click(get_location, inputs=[location], outputs=[identified_location])#to clear itclear_location = gr.ClearButton(components=[location, identified_location],visible=True, interactive=True, scale=1)clear_location.click()# TODO: Introduce text_box for Species# TODO: Introduce text_box for comments# ---------------------------------------------------------# ---------------------------------------------------------# Dead and Wounded Buttonsgr.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 sectionssection_dead, radio_circumstance_dead, radio_physical_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, \physical_boxes_dead, \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, \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_circumstance_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, \1 unmodified linecheckbox_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, \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)# ---------------------------------------------------------# ---------------------------------------------------------2 unmodified linespartial_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,radio_circumstance_dead, radio_physical_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, \2 unmodified linesfe_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_circumstance_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,10 unmodified linespartial_hide_section_dead = partial(show_section_dead, False)butt_wounded.click(partial_show_section_wounded,inputs=None,outputs=[section_wounded,radio_circumstance_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_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, \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,radio_circumstance_dead, radio_physical_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, \physical_boxes_dead, \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, \fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \fe_name_recipient_dead, fe_collection_ref_dead \])# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------2 unmodified lines# ---------------------------------------------------------# Radio Circumstance Deadradio_circumstance_dead.change(fn=show_circumstances,inputs=[radio_circumstance_dead],outputs=[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])# Dropdowns Deadbutton_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.change(on_change_openfield_level2, inputs=[openfield_level2_dead])dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2)# ---------------------------------------------------------# Radio Physical Deadradio_physical_dead.change(fn=show_physical,inputs=[radio_physical_dead, gr.Text("dead", visible=False)],outputs=[physical_boxes_dead])# Checkbox Physical Deadphysical_boxes_dead.select(find_bounding_box,4 unmodified linescheckbox_head_dead, text_head_dead,checkbox_legs_dead, text_legs_dead])checkbox_beak_dead.select(on_select_body_part, inputs=[checkbox_beak_dead, gr.Text("beak", visible=False)])checkbox_body_dead.select(on_select_body_part, inputs=[checkbox_body_dead, gr.Text("body", visible=False)])checkbox_feathers_dead.select(on_select_body_part, inputs=[checkbox_feathers_dead, gr.Text("feathers", visible=False)])checkbox_head_dead.select(on_select_body_part, inputs=[checkbox_head_dead, gr.Text("head", visible=False)])checkbox_legs_dead.select(on_select_body_part, inputs=[checkbox_legs_dead, gr.Text("legs", visible=False)])# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------2 unmodified lines# ---------------------------------------------------------# Radio Circumstance Woundedradio_circumstance_wounded.change(fn=show_circumstances,inputs=[radio_circumstance_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 Circumstance Woundedbutton_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.change(on_change_openfield_level2, inputs=[openfield_level2_wounded])dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2)# ---------------------------------------------------------# Radio Behavior Woundedradio_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 Woundedradio_physical_wounded.change(fn=show_physical,inputs=[radio_physical_wounded, gr.Text("wounded", visible=False)],outputs=[physical_boxes_wounded])# Checkbox Physical Woundedphysical_boxes_wounded.select(find_bounding_box,inputs=[physical_boxes_wounded, gr.Textbox(value="wounded", visible=False)],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])checkbox_beak_wounded.select(on_select_body_part, inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False)])checkbox_body_wounded.select(on_select_body_part, inputs=[checkbox_body_wounded, gr.Text("body", visible=False)])checkbox_feathers_wounded.select(on_select_body_part, inputs=[checkbox_feathers_wounded, gr.Text("feathers", visible=False)])checkbox_head_wounded.select(on_select_body_part, inputs=[checkbox_head_wounded, gr.Text("head", visible=False)])checkbox_legs_wounded.select(on_select_body_part, inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False)])# ---------------------------------------------------------# Follow Up Events Woundedfe_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 Deadfe_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)])# ---------------------------------------------------------# Error Box42 unmodified linesbutton_clear.click(reset_json)button_df.click(save_display_individual,inputs=[gallery, df, error_box],outputs=[gallery, df, error_box])button_close.click(lambda: Modal(visible=False), None, modal)17 unmodified lines1819202122232425262728293021 unmodified lines5253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531 unmodified line1551561571581591601612 unmodified lines1641651661671681691701711722 unmodified lines17517617717817918018118218318418510 unmodified lines1961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272 unmodified lines2302312322332342352362372382392402412422432442452462472482492502512522532542552562574 unmodified lines2622632642652662672682692702712722 unmodified lines27527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234342 unmodified lines38638738838939039139239317 unmodified linesfrom styling.style import *from styling.theme import cssfrom geolocalisation.js_geolocation import js_geocode, display_location# with gr.Blocks(theme=theme, css=css) as demo:with gr.Blocks(theme='shivi/calm_seafoam') as demo:individual = gr.State({})#with gr.Blocks() as demo:create_json_all_individuals()# ---------------------------------------------------------# Intro Text21 unmodified lines# ---------------------------------------------------------# Camerawith gr.Row():def save_image(camera, individual):individual = add_data_to_individual("image", camera.tolist(), individual)return individualcamera = gr.Image(elem_id="image")camera.input(save_image, inputs=[camera, individual], outputs=[individual])# ---------------------------------------------------------# Location#with gr.Row():with gr.Column(scale=1):gr.Markdown("### Location")gr.Markdown("#### Location (Using address)")location = gr.Textbox(visible=True, interactive=True, label="Location of Sighting")#display location processingidentified_location= gr.Textbox(visible=False, interactive=False,label="Identified GPS Location")with gr.Row():#to submit itsubmit_location = gr.Button("Get Coordinates using address",visible=True, interactive=True, scale=3)submit_location.click(get_location, inputs=[location, individual], outputs=[identified_location, individual])#to clear itclear_location = gr.ClearButton(components=[location, identified_location],visible=True, interactive=True, scale=1)clear_location.click()# Geolocationgr.Markdown("#### Location (Using GPS)")location_data = gr.JSON(label="Identified GPS Location")hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required)")btn_gpslocation.click(None, [], [], js=js_geocode)hidden_input.change(display_location, inputs=hidden_input, outputs=location_data)# Introducing text_box for Speciesgr.Markdown("### General details")with gr.Row():specie = gr.Textbox(label="Species (if known)",placeholder="e.g. European Robin, Common Blackbird",info="Enter the species name if you can identify it. If unsure, provide your best guess or general description (e.g. 'small brown bird')",visible=True,interactive=True)# Number of individualswith gr.Row():num_individuals = gr.Number(label="Number of Individuals",value=1, # Default valueminimum=1,precision=0, # Only whole numbersinfo="Enter the number of animals observed",#placeholder="Enter number...",visible=True,interactive=True)# Introducing text_box for commentswith gr.Row():comments = gr.TextArea(label="Additional Comments",placeholder="Enter any additional observations or notes about the sighting...",info="Optional: Add any relevant details about the animal(s) or circumstances",lines=3,max_lines=5,visible=True,interactive=True)# ---------------------------------------------------------# ---------------------------------------------------------# Dead and Wounded Buttonsgr.Markdown("## The State of the Animal", label="Title")gr.Markdown("Please tell us if the animal was wounded / sick or dead.", label="description")with gr.Row() as block_form:with gr.Column(scale=1):butt_wounded = gr.Button("Wounded / Sick", elem_id="wounded")with gr.Column(scale=1):butt_dead = gr.Button("Dead", elem_id="dead")# ---------------------------------------------------------# Initiate sectionssection_dead, individual, radio_circumstance_dead, radio_physical_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, \physical_boxes_dead, \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, \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, individual)section_wounded, individual, radio_circumstance_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, \1 unmodified linecheckbox_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, \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, individual)# ---------------------------------------------------------# ---------------------------------------------------------2 unmodified linespartial_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=[individual],outputs=[section_dead,individual,radio_circumstance_dead, radio_physical_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, \2 unmodified linesfe_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=[individual],outputs=[section_wounded,individual,radio_circumstance_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,10 unmodified linespartial_hide_section_dead = partial(show_section_dead, False)butt_wounded.click(partial_show_section_wounded,inputs=[individual],outputs=[section_wounded,individual,radio_circumstance_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_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, \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=[individual],outputs=[section_dead,individual,radio_circumstance_dead, radio_physical_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, \physical_boxes_dead, \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, \fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \fe_name_recipient_dead, fe_collection_ref_dead \])# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------2 unmodified lines# ---------------------------------------------------------# Radio Circumstance Deadradio_circumstance_dead.change(fn=show_circumstances,inputs=[radio_circumstance_dead, individual],outputs=[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, individual])# Dropdowns Deadbutton_collision_dead.click(dropdown_collision,inputs=[individual],outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])button_deliberate_destruction_dead.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])button_indirect_destruction_dead.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])button_natural_cause_dead.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])dropdown_dead.select(on_select, inputs=[individual], outputs=[dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])dropdown_level2_dead.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual] )openfield_level2_dead.change(on_change_openfield_level2, inputs=[openfield_level2_dead, individual], outputs=[individual])dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])# ---------------------------------------------------------# Radio Physical Deadradio_physical_dead.change(fn=show_physical,inputs=[radio_physical_dead, gr.Text("dead", visible=False), individual],outputs=[physical_boxes_dead, individual])# Checkbox Physical Deadphysical_boxes_dead.select(find_bounding_box,4 unmodified linescheckbox_head_dead, text_head_dead,checkbox_legs_dead, text_legs_dead])checkbox_beak_dead.select(on_select_body_part, inputs=[checkbox_beak_dead, gr.Text("beak", visible=False), individual], outputs=[individual])checkbox_body_dead.select(on_select_body_part, inputs=[checkbox_body_dead, gr.Text("body", visible=False), individual], outputs=[individual])checkbox_feathers_dead.select(on_select_body_part, inputs=[checkbox_feathers_dead, gr.Text("feathers", visible=False), individual], outputs=[individual])checkbox_head_dead.select(on_select_body_part, inputs=[checkbox_head_dead, gr.Text("head", visible=False), individual], outputs=[individual])checkbox_legs_dead.select(on_select_body_part, inputs=[checkbox_legs_dead, gr.Text("legs", visible=False), individual], outputs=[individual])# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------2 unmodified lines# ---------------------------------------------------------# Radio Circumstance Woundedradio_circumstance_wounded.change(fn=show_circumstances,inputs=[radio_circumstance_wounded, individual],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, individual])# Dropdowns Circumstance Woundedbutton_collision_wounded.click(dropdown_collision,inputs=[individual],outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])button_indirect_destruction_wounded.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])button_natural_cause_wounded.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])dropdown_wounded.select(on_select, inputs=[individual], outputs=[dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])dropdown_level2_wounded.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])openfield_level2_wounded.change(on_change_openfield_level2, inputs=[openfield_level2_wounded, individual])dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])# ---------------------------------------------------------# Radio Behavior Woundedradio_behavior_wounded.change(fn=show_behavior,inputs=[radio_behavior_wounded, gr.Text("wounded / sick", visible=False), individual],outputs=[behavior_checkbox, behavior_text, individual])behavior_checkbox.select(on_select_behavior,inputs=[behavior_checkbox, individual],outputs=[individual])# ---------------------------------------------------------# Radio Physical Woundedradio_physical_wounded.change(fn=show_physical,inputs=[radio_physical_wounded, gr.Text("wounded / sick", visible=False), individual],outputs=[physical_boxes_wounded, individual])# Checkbox Physical Woundedphysical_boxes_wounded.select(find_bounding_box,inputs=[physical_boxes_wounded, gr.Textbox(value="wounded / sick", visible=False)],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])checkbox_beak_wounded.select(on_select_body_part, inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False), individual], outputs=[individual])checkbox_body_wounded.select(on_select_body_part, inputs=[checkbox_body_wounded, gr.Text("body", visible=False), individual], outputs=[individual])checkbox_feathers_wounded.select(on_select_body_part, inputs=[checkbox_feathers_wounded, gr.Text("feathers", visible=False), individual], outputs=[individual])checkbox_head_wounded.select(on_select_body_part, inputs=[checkbox_head_wounded, gr.Text("head", visible=False), individual], outputs=[individual])checkbox_legs_wounded.select(on_select_body_part, inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False), individual], outputs=[individual])# ---------------------------------------------------------# Follow Up Events Woundedfe_collection_dropdown_wounded.select(save_fe, inputs=[fe_collection_dropdown_wounded, gr.Textbox("animal collected", visible=False), individual], outputs=[individual])fe_recepient_dropdown_wounded.select(save_fe, inputs=[fe_recepient_dropdown_wounded, gr.Textbox("recipient", visible=False), individual],outputs=[individual])fe_radio_dropdown_wounded.select(save_fe, inputs=[fe_radio_dropdown_wounded, gr.Textbox("radiography", visible=False), individual],outputs=[individual])fe_answer_dropdown_wounded.select(save_fe, inputs=[fe_answer_dropdown_wounded, gr.Textbox("given answer", visible=False), individual],outputs=[individual])fe_name_recipient_wounded.input(save_fe, inputs=[fe_name_recipient_wounded, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])fe_collection_ref_wounded.input(save_fe, inputs=[fe_collection_ref_wounded, gr.Textbox("collection reference", visible=False), individual],outputs=[individual])# ---------------------------------------------------------# Follow Up Events Deadfe_collection_dropdown_dead.select(save_fe, inputs=[fe_collection_dropdown_dead, gr.Textbox("animal collected", visible=False), individual],outputs=[individual])fe_recepient_dropdown_dead.select(save_fe, inputs=[fe_recepient_dropdown_dead, gr.Textbox("recipient", visible=False), individual],outputs=[individual])fe_radio_dropdown_dead.select(save_fe, inputs=[fe_radio_dropdown_dead, gr.Textbox("radiography", visible=False), individual],outputs=[individual])fe_answer_dropdown_dead.select(save_fe, inputs=[fe_answer_dropdown_dead, gr.Textbox("given answer", visible=False), individual],outputs=[individual])fe_name_recipient_dead.input(save_fe, inputs=[fe_name_recipient_dead, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])fe_collection_ref_dead.input(save_fe, inputs=[fe_collection_ref_dead, gr.Textbox("collection reference", visible=False), individual], outputs=[individual])# ---------------------------------------------------------# Error Box42 unmodified linesbutton_clear.click(reset_json)button_df.click(save_display_individual,inputs=[gallery, df, error_box, individual],outputs=[gallery, df, error_box, individual])button_close.click(lambda: Modal(visible=False), None, modal)
70 unmodified lines7172737475767778798070 unmodified lines#---------------------------------------------------------def on_select_body_part(body_part_checkbox, body_part):add_data_tmp("wounded_dead", "physical_type_"+body_part.lower(), body_part.lower())body_part_checkbox = [body_part_check.lower() for body_part_check in body_part_checkbox]add_data_tmp("wounded_dead", "physical_anomaly_"+body_part.lower(), body_part_checkbox)#---------------------------------------------------------70 unmodified lines717273747576777879808170 unmodified lines#---------------------------------------------------------def on_select_body_part(body_part_checkbox, body_part, individual):individual = add_data_tmp("wounded_dead", "physical_type_"+body_part.lower(), body_part.lower(), individual)body_part_checkbox = [body_part_check.lower() for body_part_check in body_part_checkbox]individual = add_data_tmp("wounded_dead", "physical_anomaly_"+body_part.lower(), body_part_checkbox, individual)return individual#---------------------------------------------------------
36 unmodified lines373839404142434445464736 unmodified linesvisible=visible)return img_with_boxesdef show_physical(choice, section: str):visible = set_visible(choice)physical_boxes = create_bird_anatomy(visible, section)add_data_tmp("wounded_dead", "physical_radio", choice)return physical_boxes36 unmodified lines373839404142434445464736 unmodified linesvisible=visible)return img_with_boxesdef show_physical(choice, section: str, individual):visible = set_visible(choice)physical_boxes = create_bird_anatomy(visible, section)individual = add_data_tmp("wounded_dead", "physical_radio", choice, individual)return physical_boxes, individual
1 unmodified line234567891011121314151617181 unmodified line#---------------------------------------------------------def create_checkbox(value, section, label_checkbox, visible, options, descriptions):descriptions_info = "".join([f"\t{option}: {description}\n" for option, description in zip(options, descriptions)])checkbox = gr.CheckboxGroup(options,label=label_checkbox + f" {value}:",visible=visible,interactive=True,elem_id=section)text = gr.Textbox(descriptions_info,label = "Info",visible=visible,interactive=False,lines=13,max_lines=15,elem_id=section)return checkbox, text1 unmodified line234567891011121314151617181 unmodified line#---------------------------------------------------------def create_checkbox(value, section, label_checkbox, visible, options, descriptions):descriptions_info = "<br><br>".join([f"* **{option}**: {description}" for option, description in zip(options, descriptions)])checkbox = gr.CheckboxGroup(options,label=label_checkbox + f" {value}:",visible=visible,interactive=True,elem_id=section)text = gr.Markdown(descriptions_info,label = "Info",visible=visible,#interactive=False,#lines=13,#max_lines=15,elem_id=section)return checkbox, text
123456789101112131415from validation_submission.create_json import create_json_one_individual, create_tmpimport jsondef add_data_to_individual(key, value):with open("data/one_individual.json", 'r') as openfile:one_individual = json.load(openfile)one_individual[key] = valuecreate_json_one_individual(one_individual)def add_data_tmp(tmp_name, key, value):with open(f"app/assets/tmp_json/tmp_{tmp_name}.json", 'r') as openfile:tmp = json.load(openfile)tmp[key] = valuecreate_tmp(tmp_name, tmp)12345678910111213141516171819from validation_submission.create_json import create_json_one_individual, create_tmpimport jsondef add_data_to_individual(key, value, individual):# with open("data/one_individual.json", 'r') as openfile:# one_individual = json.load(openfile)# one_individual[key] = value# create_json_one_individual(one_individual)individual[key] = valuereturn individualdef add_data_tmp(tmp_name, key, value, individual):# with open(f"app/assets/tmp_json/tmp_{tmp_name}.json", 'r') as openfile:# tmp = json.load(openfile)# tmp[key] = value# create_tmp(tmp_name, tmp)individual[key] = valuereturn individual
123456#### PROCESS FUNCTIONSdef process_circumstance(data):fields_to_check = ["option_dropdown", "open_field", "extra"]if data["circumstance_radio"] == "Yes":for field in fields_to_check:1234567#### PROCESS FUNCTIONSdef process_circumstance(data):fields_to_check = ["option_dropdown", "open_field", "extra"]if data["circumstance_radio"] == "Yes":for field in fields_to_check:
1 unmodified line234567891011121 unmodified linefrom validation_submission.get_json import get_json_all_individualsfrom validation_submission.validation import validate_individualdef validate_save_individual(error_box):individual, error_box = validate_individual(error_box)if individual:save_to_all_individuals(individual.model_dump())return individual, error_boxdef save_to_all_individuals(one_individual):all_individuals = get_json_all_individuals()1 unmodified line234567891011121 unmodified linefrom validation_submission.get_json import get_json_all_individualsfrom validation_submission.validation import validate_individualdef validate_save_individual(data, error_box):individual, error_box = validate_individual(data, error_box)if individual:save_to_all_individuals(individual.model_dump())return individual, error_box, datadef save_to_all_individuals(one_individual):all_individuals = get_json_all_individuals()
9 unmodified lines1011121314151617181920212223242513 unmodified lines394041424344459 unmodified linesfrom classes import Report, Wounded, Dead, ImageBase64from validation_submission.processing import process_circumstance, process_behaviors, process_physical, process_followupdef get_fields(data_dict, keyword):extract = {}for key, val in data_dict.items():if keyword in key:extract[key] = valreturn extractdef validate_individual(error_box):error_box = reset_error_box(error_box)data = get_json_one_individual()data["identifier"] = str(uuid.uuid4())if "image" in data.keys():img = ImageBase64.to_base64(data["image"])13 unmodified linesdata["wounded_state"] = "No"data["dead_state"] = "No"if (data["wounded_state"] == "Yes") or (data["dead_state"] == "Yes"):data_wounded_dead = get_json_tmp("wounded_dead")circumstance, error_circumstance = validate_circumstance(data_wounded_dead)physical, error_physical = validate_physical(data_wounded_dead)followup, error_followup = validate_follow_up(data_wounded_dead)9 unmodified lines1011121314151617181920212223242513 unmodified lines394041424344459 unmodified linesfrom classes import Report, Wounded, Dead, ImageBase64from validation_submission.processing import process_circumstance, process_behaviors, process_physical, process_followupdef get_fields(data_dict, keyword):extract = {}for key, val in data_dict.items():if keyword in key:extract[key] = valreturn extractdef validate_individual(data, error_box):error_box = reset_error_box(error_box)#data = get_json_one_individual() # TODO: This should changedata["identifier"] = str(uuid.uuid4())if "image" in data.keys():img = ImageBase64.to_base64(data["image"])13 unmodified linesdata["wounded_state"] = "No"data["dead_state"] = "No"if (data["wounded_state"] == "Yes") or (data["dead_state"] == "Yes"):data_wounded_dead = data #get_json_tmp("wounded_dead")circumstance, error_circumstance = validate_circumstance(data_wounded_dead)physical, error_physical = validate_physical(data_wounded_dead)followup, error_followup = validate_follow_up(data_wounded_dead)
5 unmodified lines678910111213141516171821 unmodified lines404142434445465 unmodified linesfrom follow_up.followup_events import create_followup_dropdowns, create_followup_openfrom validation_submission.add_json import add_data_to_individualdef show_section_wounded(visible):if visible==True:add_data_to_individual("wounded_state", "Yes")add_data_to_individual("dead_state", "No")with gr.Column(visible=visible, elem_id="wounded") as wounded_section:gr.Markdown("# Wounded Animal")gr.Markdown("## Do you know what conditions caused this?", label="description")radio_cause = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)21 unmodified lines# Change variables and namesreturn wounded_section, radio_cause, radio_behaviour, radio_physical, \button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, \dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, \behavior_checkbox, behavior_text, \5 unmodified lines678910111213141516171821 unmodified lines404142434445465 unmodified linesfrom follow_up.followup_events import create_followup_dropdowns, create_followup_openfrom validation_submission.add_json import add_data_to_individualdef show_section_wounded(visible, individual):if visible==True:individual = add_data_to_individual("wounded_state", "Yes", individual)individual = add_data_to_individual("dead_state", "No", individual)with gr.Column(visible=visible, elem_id="wounded") as wounded_section:gr.Markdown("# Wounded / Sick Animal")gr.Markdown("## Do you know what conditions caused this?", label="description")radio_cause = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)21 unmodified lines# Change variables and namesreturn wounded_section, individual, radio_cause, radio_behaviour, radio_physical, \button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, \dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, \behavior_checkbox, behavior_text, \
README.md+15-9
app/behavior/behavior_checkbox.py+6-5
app/circumstances/circumstances.py+4-4
app/circumstances/circumstances_dropdowns.py+30-27
app/dead.py+4-4
app/display.py+4-3
app/follow_up/followup_events.py+3-2
app/geolocalisation/js_geolocation.pyAdded+35
app/geolocalisation/maps.py+7-6
app/main.py+149-87
app/physical/physical_checkbox.py+4-3
app/physical/physical_select_animal.py+3-3
app/utils/utils_checkbox.py+5-5
app/validation_submission/add_json.py+14-10
app/validation_submission/processing.py+1
app/validation_submission/submission.py+3-3
app/validation_submission/validation.py+4-4
app/wounded.py+5-5