feat: remove modal and push json to HF dataset
Browse files- app/behavior/behavior_checkbox.py +3 -3
- app/circumstances/circumstances.py +2 -2
- app/circumstances/circumstances_dropdowns.py +9 -9
- app/classes.py +1 -0
- app/dead.py +1 -1
- app/display.py +0 -120
- app/follow_up/followup_events.py +2 -2
- app/geolocalisation/maps.py +1 -1
- app/main.py +312 -337
- app/physical/physical_boxes_map.py +0 -3
- app/physical/physical_checkbox.py +3 -3
- app/physical/physical_select_animal.py +0 -1
- app/validation_submission/add_json.py +0 -19
- app/validation_submission/get_json.py +0 -20
- app/validation_submission/submission.py +13 -19
- app/validation_submission/{create_json.py → utils_individual.py} +4 -22
- app/validation_submission/validation.py +4 -1
- app/wounded.py +1 -1
app/behavior/behavior_checkbox.py
CHANGED
|
@@ -2,11 +2,11 @@ import gradio as gr
|
|
| 2 |
from utils.utils_config import get_custom_config_dropdowns
|
| 3 |
from utils.utils_checkbox import create_checkbox
|
| 4 |
from utils.utils_visible import set_visible
|
| 5 |
-
from validation_submission.
|
| 6 |
|
| 7 |
def on_select_behavior(behavior_checkbox, individual):
|
| 8 |
behavior_checkbox = [behavior.lower() for behavior in behavior_checkbox]
|
| 9 |
-
individual =
|
| 10 |
return individual
|
| 11 |
|
| 12 |
def retrieve_behavior_options_description():
|
|
@@ -27,5 +27,5 @@ def create_behavior_checkbox(section: str, visible):
|
|
| 27 |
def show_behavior(choice, section: str, individual):
|
| 28 |
visible = set_visible(choice)
|
| 29 |
checkbox, text = create_behavior_checkbox(section, visible)
|
| 30 |
-
individual =
|
| 31 |
return checkbox, text, individual
|
|
|
|
| 2 |
from utils.utils_config import get_custom_config_dropdowns
|
| 3 |
from utils.utils_checkbox import create_checkbox
|
| 4 |
from utils.utils_visible import set_visible
|
| 5 |
+
from validation_submission.utils_individual import add_data_to_individual
|
| 6 |
|
| 7 |
def on_select_behavior(behavior_checkbox, individual):
|
| 8 |
behavior_checkbox = [behavior.lower() for behavior in behavior_checkbox]
|
| 9 |
+
individual = add_data_to_individual("behaviors_type", behavior_checkbox, individual)
|
| 10 |
return individual
|
| 11 |
|
| 12 |
def retrieve_behavior_options_description():
|
|
|
|
| 27 |
def show_behavior(choice, section: str, individual):
|
| 28 |
visible = set_visible(choice)
|
| 29 |
checkbox, text = create_behavior_checkbox(section, visible)
|
| 30 |
+
individual = add_data_to_individual("behaviors_radio", choice, individual)
|
| 31 |
return checkbox, text, individual
|
app/circumstances/circumstances.py
CHANGED
|
@@ -3,7 +3,7 @@ import os
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
|
| 5 |
from utils.utils_visible import set_visible
|
| 6 |
-
from validation_submission.
|
| 7 |
|
| 8 |
load_dotenv()
|
| 9 |
PATH = os.getcwd() + "/"
|
|
@@ -15,7 +15,7 @@ CAUSE_COL_WIDTH = "50px"
|
|
| 15 |
|
| 16 |
def show_circumstances(choice, individual):
|
| 17 |
visible = set_visible(choice)
|
| 18 |
-
individual =
|
| 19 |
"circumstance_radio",
|
| 20 |
choice, individual)
|
| 21 |
button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_circumstances(visible)
|
|
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
|
| 5 |
from utils.utils_visible import set_visible
|
| 6 |
+
from validation_submission.utils_individual import add_data_to_individual
|
| 7 |
|
| 8 |
load_dotenv()
|
| 9 |
PATH = os.getcwd() + "/"
|
|
|
|
| 15 |
|
| 16 |
def show_circumstances(choice, individual):
|
| 17 |
visible = set_visible(choice)
|
| 18 |
+
individual = add_data_to_individual("wounded_dead",
|
| 19 |
"circumstance_radio",
|
| 20 |
choice, individual)
|
| 21 |
button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_circumstances(visible)
|
app/circumstances/circumstances_dropdowns.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils.utils_config import get_custom_config_dropdowns
|
| 3 |
-
from validation_submission.
|
| 4 |
|
| 5 |
#--------------------------------------------------------- LEVEL 1 DROPDOWNS
|
| 6 |
def retrieve_config_options(label, dropdown_config):
|
|
@@ -23,22 +23,22 @@ def create_dropdown_level1(label, individual):
|
|
| 23 |
|
| 24 |
def dropdown_collision(individual):
|
| 25 |
label = "Collision with a means of transport"
|
| 26 |
-
individual =
|
| 27 |
return create_dropdown_level1(label, individual)
|
| 28 |
|
| 29 |
def dropdown_deliberate_destruction(individual):
|
| 30 |
label = "Destruction / Deliberatly removed"
|
| 31 |
-
individual =
|
| 32 |
return create_dropdown_level1(label, individual)
|
| 33 |
|
| 34 |
def dropdown_indirect_destruction(individual):
|
| 35 |
label = "Indirect destruction"
|
| 36 |
-
individual =
|
| 37 |
return create_dropdown_level1(label, individual)
|
| 38 |
|
| 39 |
def dropdown_natural_cause(individual):
|
| 40 |
label = "Natural cause"
|
| 41 |
-
individual =
|
| 42 |
return create_dropdown_level1(label, individual)
|
| 43 |
|
| 44 |
|
|
@@ -72,7 +72,7 @@ def get_options(value):
|
|
| 72 |
|
| 73 |
def on_select(evt: gr.SelectData, individual): # SelectData is a subclass of EventData
|
| 74 |
options_label, options_dropdown, open_field, extras, extras_label = get_options(evt.value)
|
| 75 |
-
individual =
|
| 76 |
"circumstance_type",
|
| 77 |
{"type": (evt.value).lower(),
|
| 78 |
"option_dropdown_label" : options_label.lower() if options_label is not None else 'NA',
|
|
@@ -96,20 +96,20 @@ def on_select(evt: gr.SelectData, individual): # SelectData is a subclass of Ev
|
|
| 96 |
return dropdown_level2, openfield_level2, dropdown_extra_level2, individual
|
| 97 |
|
| 98 |
def on_select_dropdown_level2(evt: gr.SelectData, individual):
|
| 99 |
-
individual =
|
| 100 |
"circumstance_option_dropdown",
|
| 101 |
evt.value.lower(), individual)
|
| 102 |
return individual
|
| 103 |
|
| 104 |
def on_select_dropdown_extra_level2(evt: gr.SelectData, individual):
|
| 105 |
-
individual =
|
| 106 |
"circumstance_extra",
|
| 107 |
evt.value.lower(), individual)
|
| 108 |
return individual
|
| 109 |
|
| 110 |
def on_change_openfield_level2(openfield_level2_dead, individual):
|
| 111 |
print("Saving open field")
|
| 112 |
-
individual =
|
| 113 |
"circumstance_open_field",
|
| 114 |
str(openfield_level2_dead).lower(), individual)
|
| 115 |
return individual
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils.utils_config import get_custom_config_dropdowns
|
| 3 |
+
from validation_submission.utils_individual import add_data_to_individual
|
| 4 |
|
| 5 |
#--------------------------------------------------------- LEVEL 1 DROPDOWNS
|
| 6 |
def retrieve_config_options(label, dropdown_config):
|
|
|
|
| 23 |
|
| 24 |
def dropdown_collision(individual):
|
| 25 |
label = "Collision with a means of transport"
|
| 26 |
+
individual = add_data_to_individual("wounded_dead", "circumstance", label.lower(), individual)
|
| 27 |
return create_dropdown_level1(label, individual)
|
| 28 |
|
| 29 |
def dropdown_deliberate_destruction(individual):
|
| 30 |
label = "Destruction / Deliberatly removed"
|
| 31 |
+
individual = add_data_to_individual("wounded_dead", "circumstance", label.lower(), individual)
|
| 32 |
return create_dropdown_level1(label, individual)
|
| 33 |
|
| 34 |
def dropdown_indirect_destruction(individual):
|
| 35 |
label = "Indirect destruction"
|
| 36 |
+
individual = add_data_to_individual("wounded_dead", "circumstance", label.lower(), individual)
|
| 37 |
return create_dropdown_level1(label, individual)
|
| 38 |
|
| 39 |
def dropdown_natural_cause(individual):
|
| 40 |
label = "Natural cause"
|
| 41 |
+
individual = add_data_to_individual("wounded_dead", "circumstance", label.lower(), individual)
|
| 42 |
return create_dropdown_level1(label, individual)
|
| 43 |
|
| 44 |
|
|
|
|
| 72 |
|
| 73 |
def on_select(evt: gr.SelectData, individual): # SelectData is a subclass of EventData
|
| 74 |
options_label, options_dropdown, open_field, extras, extras_label = get_options(evt.value)
|
| 75 |
+
individual = add_data_to_individual("wounded_dead",
|
| 76 |
"circumstance_type",
|
| 77 |
{"type": (evt.value).lower(),
|
| 78 |
"option_dropdown_label" : options_label.lower() if options_label is not None else 'NA',
|
|
|
|
| 96 |
return dropdown_level2, openfield_level2, dropdown_extra_level2, individual
|
| 97 |
|
| 98 |
def on_select_dropdown_level2(evt: gr.SelectData, individual):
|
| 99 |
+
individual = add_data_to_individual("wounded_dead",
|
| 100 |
"circumstance_option_dropdown",
|
| 101 |
evt.value.lower(), individual)
|
| 102 |
return individual
|
| 103 |
|
| 104 |
def on_select_dropdown_extra_level2(evt: gr.SelectData, individual):
|
| 105 |
+
individual = add_data_to_individual("wounded_dead",
|
| 106 |
"circumstance_extra",
|
| 107 |
evt.value.lower(), individual)
|
| 108 |
return individual
|
| 109 |
|
| 110 |
def on_change_openfield_level2(openfield_level2_dead, individual):
|
| 111 |
print("Saving open field")
|
| 112 |
+
individual = add_data_to_individual("wounded_dead",
|
| 113 |
"circumstance_open_field",
|
| 114 |
str(openfield_level2_dead).lower(), individual)
|
| 115 |
return individual
|
app/classes.py
CHANGED
|
@@ -39,6 +39,7 @@ class ImageBase64(BaseModel):
|
|
| 39 |
class Report(BaseModel):
|
| 40 |
identifier: str
|
| 41 |
image: ImageBase64
|
|
|
|
| 42 |
geolocalisation: Geolocalisation
|
| 43 |
wounded_state: str
|
| 44 |
wounded: Optional[Wounded] = None
|
|
|
|
| 39 |
class Report(BaseModel):
|
| 40 |
identifier: str
|
| 41 |
image: ImageBase64
|
| 42 |
+
image_md5: str
|
| 43 |
geolocalisation: Geolocalisation
|
| 44 |
wounded_state: str
|
| 45 |
wounded: Optional[Wounded] = None
|
app/dead.py
CHANGED
|
@@ -3,7 +3,7 @@ from circumstances.circumstances import create_circumstances
|
|
| 3 |
from physical.physical_select_animal import create_bird_anatomy
|
| 4 |
from physical.physical_checkbox import process_body_parts
|
| 5 |
from follow_up.followup_events import create_followup_dropdowns, create_followup_open
|
| 6 |
-
from validation_submission.
|
| 7 |
|
| 8 |
def show_section_dead(visible, individual):
|
| 9 |
if visible==True:
|
|
|
|
| 3 |
from physical.physical_select_animal import create_bird_anatomy
|
| 4 |
from physical.physical_checkbox import process_body_parts
|
| 5 |
from follow_up.followup_events import create_followup_dropdowns, create_followup_open
|
| 6 |
+
from validation_submission.utils_individual import add_data_to_individual
|
| 7 |
|
| 8 |
def show_section_dead(visible, individual):
|
| 9 |
if visible==True:
|
app/display.py
DELETED
|
@@ -1,120 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import pandas as pd
|
| 3 |
-
from gradio_modal import Modal
|
| 4 |
-
from PIL import Image
|
| 5 |
-
from io import BytesIO
|
| 6 |
-
import base64
|
| 7 |
-
|
| 8 |
-
from validation_submission.submission import validate_save_individual
|
| 9 |
-
from validation_submission.get_json import get_json_all_individuals
|
| 10 |
-
|
| 11 |
-
HEADERS = ["Identifier", "Location", "Wounded", "Dead"]
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
def save_display_individual(gallery, df, error_box, data):
|
| 15 |
-
individual, error_box, data = validate_save_individual(data, error_box)
|
| 16 |
-
if individual:
|
| 17 |
-
all_animals = get_json_all_individuals()
|
| 18 |
-
gallery_animals = process_animals_for_gallery(all_animals)
|
| 19 |
-
gallery = make_gallery(gallery_animals)
|
| 20 |
-
df_animals = process_animals_for_df(all_animals)
|
| 21 |
-
df = make_df(df_animals)
|
| 22 |
-
return gallery, df, error_box, data
|
| 23 |
-
|
| 24 |
-
# ----------------------------------
|
| 25 |
-
# GALLERY
|
| 26 |
-
|
| 27 |
-
def convert_image(image_base64_str):
|
| 28 |
-
im = Image.open(BytesIO(base64.b64decode(image_base64_str)))
|
| 29 |
-
return im
|
| 30 |
-
|
| 31 |
-
def set_gallery_size(len_animals):
|
| 32 |
-
if len_animals < 10:
|
| 33 |
-
num_cols=5
|
| 34 |
-
num_rows=2
|
| 35 |
-
else:
|
| 36 |
-
num_cols = len_animals/2
|
| 37 |
-
num_rows = len_animals/(num_cols)
|
| 38 |
-
return num_cols, num_rows
|
| 39 |
-
|
| 40 |
-
def process_animals_for_gallery(all_animals):
|
| 41 |
-
gallery_animals = []
|
| 42 |
-
for _, animal in all_animals.items():
|
| 43 |
-
image = convert_image(animal["image"]["image"])
|
| 44 |
-
caption = animal["identifier"]
|
| 45 |
-
animal = (image, caption)
|
| 46 |
-
gallery_animals.append(animal)
|
| 47 |
-
return gallery_animals
|
| 48 |
-
|
| 49 |
-
def make_gallery(gallery_animals):
|
| 50 |
-
num_cols, num_rows = set_gallery_size(len(gallery_animals))
|
| 51 |
-
gallery = gr.Gallery(
|
| 52 |
-
label="Gallery of Records", elem_id="gallery",
|
| 53 |
-
columns=[num_cols], rows=[num_rows],
|
| 54 |
-
value=gallery_animals,
|
| 55 |
-
object_fit="contain", height="auto", interactive=False)
|
| 56 |
-
return gallery
|
| 57 |
-
|
| 58 |
-
def keep_only_values(dict_to_filter):
|
| 59 |
-
info_text = ""
|
| 60 |
-
values_to_ignore = ["Yes", "No", "NA"]
|
| 61 |
-
if dict_to_filter:
|
| 62 |
-
for key, val in dict_to_filter.items():
|
| 63 |
-
if type(val) is dict:
|
| 64 |
-
subset_text = keep_only_values(val)
|
| 65 |
-
info_text += f"{subset_text}"
|
| 66 |
-
elif type(val) is list:
|
| 67 |
-
for item in val:
|
| 68 |
-
if type(item) is dict:
|
| 69 |
-
subset_text = keep_only_values(item)
|
| 70 |
-
info_text += f"{subset_text}"
|
| 71 |
-
elif (val is not None) and (type(val) is not bool) and (val not in values_to_ignore):
|
| 72 |
-
info_text += f" {key} : {val} |"
|
| 73 |
-
else:
|
| 74 |
-
print("Ignoring value: ", val)
|
| 75 |
-
print("Associated key: ", key)
|
| 76 |
-
else:
|
| 77 |
-
info_text = "NaN"
|
| 78 |
-
return info_text
|
| 79 |
-
|
| 80 |
-
# ----------------------------------
|
| 81 |
-
# DATAFRAME
|
| 82 |
-
|
| 83 |
-
def process_animals_for_df(all_animals):
|
| 84 |
-
df_animals = {}
|
| 85 |
-
identifiers =[]
|
| 86 |
-
geo =[]
|
| 87 |
-
wounded =[]
|
| 88 |
-
dead =[]
|
| 89 |
-
for _, animal in all_animals.items():
|
| 90 |
-
identifier_value = animal["identifier"]
|
| 91 |
-
identifiers.append(identifier_value)
|
| 92 |
-
geo_dict = animal["geolocalisation"]
|
| 93 |
-
geo_values = keep_only_values(geo_dict)
|
| 94 |
-
geo.append(geo_values)
|
| 95 |
-
wounded_dict = animal["wounded"]
|
| 96 |
-
wounded_values = keep_only_values(wounded_dict)
|
| 97 |
-
wounded.append(wounded_values)
|
| 98 |
-
dead_dict = animal["dead"]
|
| 99 |
-
dead_values = keep_only_values(dead_dict)
|
| 100 |
-
dead.append(dead_values)
|
| 101 |
-
df_animals["Identifier"] = identifiers
|
| 102 |
-
df_animals["Location"] = geo
|
| 103 |
-
df_animals["Wounded"] = wounded
|
| 104 |
-
df_animals["Dead"] = dead
|
| 105 |
-
return df_animals
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
def make_df(df_animals):
|
| 109 |
-
df = pd.DataFrame.from_dict(df_animals)
|
| 110 |
-
styled_df = df.style.set_properties(**{
|
| 111 |
-
'min-width': '25px',
|
| 112 |
-
'max-width': '50px', # Adjust width as needed
|
| 113 |
-
'white-space': 'normal', # Allows text to wrap to the next line
|
| 114 |
-
'word-wrap': 'break-word' # Breaks long words to fit within the width
|
| 115 |
-
})
|
| 116 |
-
df_gradio = gr.DataFrame(visible=True,
|
| 117 |
-
value=styled_df,
|
| 118 |
-
headers=HEADERS, interactive=False)
|
| 119 |
-
return df_gradio
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/follow_up/followup_events.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils.utils_config import get_custom_config_dropdowns
|
| 3 |
-
from validation_submission.
|
| 4 |
|
| 5 |
def create_followup_dropdowns(visible, elem_id):
|
| 6 |
followup_config = get_custom_config_dropdowns("config_followup.json")
|
|
@@ -40,7 +40,7 @@ def create_fe_answer_dropdown(followup_config, visible, elem_id):
|
|
| 40 |
return fe_answer_dropdown
|
| 41 |
|
| 42 |
def save_fe(value, key, individual):
|
| 43 |
-
individual =
|
| 44 |
return individual
|
| 45 |
|
| 46 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils.utils_config import get_custom_config_dropdowns
|
| 3 |
+
from validation_submission.utils_individual import add_data_to_individual
|
| 4 |
|
| 5 |
def create_followup_dropdowns(visible, elem_id):
|
| 6 |
followup_config = get_custom_config_dropdowns("config_followup.json")
|
|
|
|
| 40 |
return fe_answer_dropdown
|
| 41 |
|
| 42 |
def save_fe(value, key, individual):
|
| 43 |
+
individual = add_data_to_individual("wounded_dead", "followup " + key.lower(), value.lower())
|
| 44 |
return individual
|
| 45 |
|
| 46 |
|
app/geolocalisation/maps.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from geopy.geocoders import Nominatim
|
| 2 |
import gradio as gr
|
| 3 |
-
from validation_submission.
|
| 4 |
from geolocalisation.class_geolocalisation import Geolocalisation
|
| 5 |
|
| 6 |
|
|
|
|
| 1 |
from geopy.geocoders import Nominatim
|
| 2 |
import gradio as gr
|
| 3 |
+
from validation_submission.utils_individual import add_data_to_individual
|
| 4 |
from geolocalisation.class_geolocalisation import Geolocalisation
|
| 5 |
|
| 6 |
|
app/main.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from gradio_modal import Modal
|
| 3 |
|
| 4 |
-
from validation_submission.
|
| 5 |
-
from validation_submission.add_json import add_data_to_individual
|
| 6 |
from validation_submission.validation import reset_error_box
|
| 7 |
-
from display import save_display_individual
|
| 8 |
from geolocalisation.maps import get_location
|
| 9 |
from functools import partial
|
| 10 |
from dead import show_section_dead
|
|
@@ -19,6 +17,7 @@ from styling.style import *
|
|
| 19 |
from styling.theme import css
|
| 20 |
|
| 21 |
from geolocalisation.js_geolocation import js_geocode, display_location
|
|
|
|
| 22 |
|
| 23 |
from datasets import disable_caching
|
| 24 |
disable_caching()
|
|
@@ -29,147 +28,183 @@ data_files = "data/train-00000-of-00001.parquet"
|
|
| 29 |
# with gr.Blocks(theme=theme, css=css) as demo:
|
| 30 |
with gr.Blocks(theme='shivi/calm_seafoam') as demo:
|
| 31 |
individual = gr.State({})
|
|
|
|
| 32 |
|
| 33 |
-
#with gr.Blocks() as demo:
|
| 34 |
-
create_json_all_individuals()
|
| 35 |
# ---------------------------------------------------------
|
| 36 |
# Intro Text
|
| 37 |
with gr.Row():
|
| 38 |
with gr.Column(scale=1):
|
| 39 |
title = gr.Markdown("# Welcome to Digiwild", label="Title")
|
| 40 |
description = gr.Markdown("Please record your wildlife observations here !", label="description")
|
| 41 |
-
with gr.Row():
|
| 42 |
-
show_modal = gr.Button("Add an Animal", scale=3)
|
| 43 |
-
submit_button = gr.Button("Submit All Animals", scale=1)
|
| 44 |
-
df = gr.Dataframe(headers=["Identifier", "Location", "Wounded", "Dead"], visible=False, interactive=False)
|
| 45 |
-
gallery = gr.Gallery(
|
| 46 |
-
label="Gallery of Records", elem_id="gallery",
|
| 47 |
-
columns=[1], rows=[1],
|
| 48 |
-
object_fit="contain", height="auto", interactive=False)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
with gr.
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
description = gr.Markdown("Please record your observation here.", label="description")
|
| 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 |
-
with gr.
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
butt_dead = gr.Button("Dead", elem_id="dead")
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
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, \
|
| 162 |
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 163 |
-
|
| 164 |
-
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
inputs=[individual],
|
| 174 |
outputs=[section_dead,
|
| 175 |
individual,
|
|
@@ -181,229 +216,169 @@ with gr.Blocks(theme='shivi/calm_seafoam') as demo:
|
|
| 181 |
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 182 |
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 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 |
-
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, \
|
| 214 |
-
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 215 |
-
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 216 |
-
])
|
| 217 |
-
|
| 218 |
-
butt_wounded.click(partial_hide_section_dead,
|
| 219 |
-
inputs=[individual],
|
| 220 |
-
outputs=[section_dead,
|
| 221 |
-
individual,
|
| 222 |
-
radio_circumstance_dead, radio_physical_dead,
|
| 223 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 224 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 225 |
-
physical_boxes_dead, \
|
| 226 |
-
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, \
|
| 227 |
-
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 228 |
-
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 229 |
-
])
|
| 230 |
-
|
| 231 |
-
# ---------------------------------------------------------
|
| 232 |
-
# ---------------------------------------------------------
|
| 233 |
-
# ---------------------------------------------------------
|
| 234 |
-
# ---------------------------------------------------------
|
| 235 |
-
# DEAD
|
| 236 |
-
# ---------------------------------------------------------
|
| 237 |
-
# Radio Circumstance Dead
|
| 238 |
-
radio_circumstance_dead.change(fn=show_circumstances,
|
| 239 |
-
inputs=[radio_circumstance_dead, individual],
|
| 240 |
-
outputs=[button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 241 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual]
|
| 242 |
-
)
|
| 243 |
-
|
| 244 |
-
# Dropdowns Dead
|
| 245 |
-
button_collision_dead.click(dropdown_collision,
|
| 246 |
-
inputs=[individual],
|
| 247 |
-
outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 248 |
-
button_deliberate_destruction_dead.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 249 |
-
button_indirect_destruction_dead.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 250 |
-
button_natural_cause_dead.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 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 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 286 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual]
|
| 287 |
-
)
|
| 288 |
-
|
| 289 |
-
# Dropdowns Circumstance Wounded
|
| 290 |
-
button_collision_wounded.click(dropdown_collision,
|
| 291 |
-
inputs=[individual],
|
| 292 |
-
outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 293 |
-
button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 294 |
-
button_indirect_destruction_wounded.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 295 |
-
button_natural_cause_wounded.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 296 |
-
|
| 297 |
-
dropdown_wounded.select(on_select, inputs=[individual], outputs=[dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 298 |
-
dropdown_level2_wounded.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])
|
| 299 |
-
openfield_level2_wounded.change(on_change_openfield_level2, inputs=[openfield_level2_wounded, individual])
|
| 300 |
-
dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])
|
| 301 |
-
# ---------------------------------------------------------
|
| 302 |
-
# Radio Behavior Wounded
|
| 303 |
-
radio_behavior_wounded.change(fn=show_behavior,
|
| 304 |
-
inputs=[radio_behavior_wounded, gr.Text("wounded / sick", visible=False), individual],
|
| 305 |
-
outputs=[behavior_checkbox, behavior_text, individual])
|
| 306 |
-
behavior_checkbox.select(on_select_behavior,
|
| 307 |
-
inputs=[behavior_checkbox, individual],
|
| 308 |
-
outputs=[individual])
|
| 309 |
-
# ---------------------------------------------------------
|
| 310 |
-
# Radio Physical Wounded
|
| 311 |
-
radio_physical_wounded.change(fn=show_physical,
|
| 312 |
-
inputs=[radio_physical_wounded, gr.Text("wounded / sick", visible=False), individual],
|
| 313 |
-
outputs=[physical_boxes_wounded, individual])
|
| 314 |
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
])
|
| 324 |
-
checkbox_beak_wounded.select(on_select_body_part, inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False), individual], outputs=[individual])
|
| 325 |
-
checkbox_body_wounded.select(on_select_body_part, inputs=[checkbox_body_wounded, gr.Text("body", visible=False), individual], outputs=[individual])
|
| 326 |
-
checkbox_feathers_wounded.select(on_select_body_part, inputs=[checkbox_feathers_wounded, gr.Text("feathers", visible=False), individual], outputs=[individual])
|
| 327 |
-
checkbox_head_wounded.select(on_select_body_part, inputs=[checkbox_head_wounded, gr.Text("head", visible=False), individual], outputs=[individual])
|
| 328 |
-
checkbox_legs_wounded.select(on_select_body_part, inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False), individual], outputs=[individual])
|
| 329 |
-
|
| 330 |
-
# ---------------------------------------------------------
|
| 331 |
-
# Follow Up Events Wounded
|
| 332 |
-
fe_collection_dropdown_wounded.select(save_fe, inputs=[fe_collection_dropdown_wounded, gr.Textbox("animal collected", visible=False), individual], outputs=[individual])
|
| 333 |
-
fe_recepient_dropdown_wounded.select(save_fe, inputs=[fe_recepient_dropdown_wounded, gr.Textbox("recipient", visible=False), individual],outputs=[individual])
|
| 334 |
-
fe_radio_dropdown_wounded.select(save_fe, inputs=[fe_radio_dropdown_wounded, gr.Textbox("radiography", visible=False), individual],outputs=[individual])
|
| 335 |
-
fe_answer_dropdown_wounded.select(save_fe, inputs=[fe_answer_dropdown_wounded, gr.Textbox("given answer", visible=False), individual],outputs=[individual])
|
| 336 |
-
fe_name_recipient_wounded.input(save_fe, inputs=[fe_name_recipient_wounded, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])
|
| 337 |
-
fe_collection_ref_wounded.input(save_fe, inputs=[fe_collection_ref_wounded, gr.Textbox("collection reference", visible=False), individual],outputs=[individual])
|
| 338 |
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
fe_recepient_dropdown_dead.select(save_fe, inputs=[fe_recepient_dropdown_dead, gr.Textbox("recipient", visible=False), individual],outputs=[individual])
|
| 343 |
-
fe_radio_dropdown_dead.select(save_fe, inputs=[fe_radio_dropdown_dead, gr.Textbox("radiography", visible=False), individual],outputs=[individual])
|
| 344 |
-
fe_answer_dropdown_dead.select(save_fe, inputs=[fe_answer_dropdown_dead, gr.Textbox("given answer", visible=False), individual],outputs=[individual])
|
| 345 |
-
fe_name_recipient_dead.input(save_fe, inputs=[fe_name_recipient_dead, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])
|
| 346 |
-
fe_collection_ref_dead.input(save_fe, inputs=[fe_collection_ref_dead, gr.Textbox("collection reference", visible=False), individual], outputs=[individual])
|
| 347 |
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
camera,
|
| 360 |
-
location, identified_location,
|
| 361 |
-
#dead reset
|
| 362 |
-
radio_circumstance_dead, radio_physical_dead,
|
| 363 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 364 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
|
| 365 |
-
physical_boxes_dead,
|
| 366 |
-
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,
|
| 367 |
-
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead,
|
| 368 |
-
fe_name_recipient_dead, fe_collection_ref_dead,
|
| 369 |
-
#wounded reset
|
| 370 |
-
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 371 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 372 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 373 |
-
behavior_checkbox, behavior_text,
|
| 374 |
-
physical_boxes_wounded,
|
| 375 |
-
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,
|
| 376 |
-
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded,
|
| 377 |
-
fe_name_recipient_wounded, fe_collection_ref_wounded,
|
| 378 |
-
error_box
|
| 379 |
-
])
|
| 380 |
-
button_close = gr.Button("Back to Display", scale = 1)
|
| 381 |
|
| 382 |
-
|
| 383 |
-
# ---------------------------------------------------------
|
| 384 |
-
# Button Click Logic
|
| 385 |
-
button_clear.click()
|
| 386 |
-
button_clear.click(hide_physical,
|
| 387 |
-
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])
|
| 388 |
-
button_clear.click(hide_physical,
|
| 389 |
-
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])
|
| 390 |
-
|
| 391 |
-
button_clear.click(reset_error_box, inputs=[error_box], outputs=[error_box])
|
| 392 |
-
button_clear.click(reset_json)
|
| 393 |
-
|
| 394 |
-
button_df.click(save_display_individual,
|
| 395 |
-
inputs=[gallery, df, error_box, individual],
|
| 396 |
-
outputs=[gallery, df, error_box, individual]
|
| 397 |
-
)
|
| 398 |
-
button_close.click(lambda: Modal(visible=False), None, modal)
|
| 399 |
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
show_modal.click(create_json_one_individual)
|
| 404 |
-
show_modal.click(create_tmp)
|
| 405 |
-
|
| 406 |
-
#submit_button.click(save_and_rest_df, inputs=[df], outputs=[df])
|
| 407 |
|
| 408 |
|
| 409 |
if __name__ == "__main__":
|
|
|
|
| 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.validation import reset_error_box
|
|
|
|
| 6 |
from geolocalisation.maps import get_location
|
| 7 |
from functools import partial
|
| 8 |
from dead import show_section_dead
|
|
|
|
| 17 |
from styling.theme import css
|
| 18 |
|
| 19 |
from geolocalisation.js_geolocation import js_geocode, display_location
|
| 20 |
+
from validation_submission.utils_individual import generate_random_md5
|
| 21 |
|
| 22 |
from datasets import disable_caching
|
| 23 |
disable_caching()
|
|
|
|
| 28 |
# with gr.Blocks(theme=theme, css=css) as demo:
|
| 29 |
with gr.Blocks(theme='shivi/calm_seafoam') as demo:
|
| 30 |
individual = gr.State({})
|
| 31 |
+
individual.value = add_data_to_individual("image_md5", generate_random_md5(), individual.value)
|
| 32 |
|
|
|
|
|
|
|
| 33 |
# ---------------------------------------------------------
|
| 34 |
# Intro Text
|
| 35 |
with gr.Row():
|
| 36 |
with gr.Column(scale=1):
|
| 37 |
title = gr.Markdown("# Welcome to Digiwild", label="Title")
|
| 38 |
description = gr.Markdown("Please record your wildlife observations here !", label="description")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
# ---------------------------------------------------------
|
| 41 |
+
# Intro Text
|
| 42 |
+
with gr.Row():
|
| 43 |
+
with gr.Column(scale=1):
|
| 44 |
+
title = gr.Markdown("# Animal Report", label="Title")
|
| 45 |
+
description = gr.Markdown("Please record your observation here.", label="description")
|
|
|
|
| 46 |
|
| 47 |
+
# ---------------------------------------------------------
|
| 48 |
+
# Camera
|
| 49 |
+
with gr.Row():
|
| 50 |
+
def save_image(camera, individual):
|
| 51 |
+
individual = add_data_to_individual("image", camera.tolist(), individual)
|
| 52 |
+
return individual
|
| 53 |
|
| 54 |
+
camera = gr.Image(elem_id="image")
|
| 55 |
+
camera.input(save_image, inputs=[camera, individual], outputs=[individual])
|
| 56 |
+
# ---------------------------------------------------------
|
| 57 |
+
# Location
|
| 58 |
+
#with gr.Row():
|
| 59 |
+
with gr.Column(scale=1):
|
| 60 |
+
gr.Markdown("### Location")
|
| 61 |
+
gr.Markdown("#### Location (Using address)")
|
| 62 |
+
location = gr.Textbox(visible=True, interactive=True, label="Location of Sighting")
|
| 63 |
+
#display location processing
|
| 64 |
+
identified_location= gr.Textbox(visible=False, interactive=False,
|
| 65 |
+
label="Identified GPS Location")
|
| 66 |
+
with gr.Row():
|
| 67 |
+
#to submit it
|
| 68 |
+
submit_location = gr.Button("Get Coordinates using address",
|
| 69 |
+
visible=True, interactive=True, scale=3)
|
| 70 |
+
submit_location.click(get_location, inputs=[location, individual], outputs=[identified_location, individual])
|
| 71 |
+
#to clear it
|
| 72 |
+
clear_location = gr.ClearButton(components=[location, identified_location],
|
| 73 |
+
visible=True, interactive=True, scale=1
|
| 74 |
+
)
|
| 75 |
+
clear_location.click()
|
| 76 |
|
| 77 |
+
# Geolocation
|
| 78 |
+
gr.Markdown("#### Location (Using GPS)")
|
| 79 |
+
location_data = gr.JSON(label="Identified GPS Location")
|
| 80 |
+
hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 81 |
+
btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required)")
|
| 82 |
+
btn_gpslocation.click(None, [], [], js=js_geocode)
|
| 83 |
+
hidden_input.change(display_location, inputs=hidden_input, outputs=location_data)
|
| 84 |
|
| 85 |
+
|
| 86 |
+
# Introducing text_box for Species
|
| 87 |
+
gr.Markdown("### General details")
|
| 88 |
+
with gr.Row():
|
| 89 |
+
specie = gr.Textbox(
|
| 90 |
+
label="Species (if known)",
|
| 91 |
+
placeholder="e.g. European Robin, Common Blackbird",
|
| 92 |
+
info="Enter the species name if you can identify it. If unsure, provide your best guess or general description (e.g. 'small brown bird')",
|
| 93 |
+
visible=True,
|
| 94 |
+
interactive=True
|
| 95 |
+
)
|
| 96 |
|
| 97 |
+
# Number of individuals
|
| 98 |
+
with gr.Row():
|
| 99 |
+
num_individuals = gr.Number(
|
| 100 |
+
label="Number of Individuals",
|
| 101 |
+
value=1, # Default value
|
| 102 |
+
minimum=1,
|
| 103 |
+
precision=0, # Only whole numbers
|
| 104 |
+
info="Enter the number of animals observed",
|
| 105 |
+
#placeholder="Enter number...",
|
| 106 |
+
visible=True,
|
| 107 |
+
interactive=True
|
| 108 |
+
)
|
| 109 |
|
| 110 |
+
# Introducing text_box for comments
|
| 111 |
+
with gr.Row():
|
| 112 |
+
comments = gr.TextArea(
|
| 113 |
+
label="Additional Comments",
|
| 114 |
+
placeholder="Enter any additional observations or notes about the sighting...",
|
| 115 |
+
info="Optional: Add any relevant details about the animal(s) or circumstances",
|
| 116 |
+
lines=3,
|
| 117 |
+
max_lines=5,
|
| 118 |
+
visible=True,
|
| 119 |
+
interactive=True
|
| 120 |
+
)
|
| 121 |
|
| 122 |
|
| 123 |
+
# ---------------------------------------------------------
|
| 124 |
# ---------------------------------------------------------
|
| 125 |
+
# Dead and Wounded Buttons
|
| 126 |
+
gr.Markdown("## The State of the Animal", label="Title")
|
| 127 |
+
gr.Markdown("Please tell us if the animal was wounded / sick or dead.", label="description")
|
| 128 |
+
with gr.Row() as block_form:
|
| 129 |
+
with gr.Column(scale=1):
|
| 130 |
+
butt_wounded = gr.Button("Wounded / Sick", elem_id="wounded")
|
| 131 |
+
with gr.Column(scale=1):
|
| 132 |
+
butt_dead = gr.Button("Dead", elem_id="dead")
|
|
|
|
| 133 |
|
| 134 |
+
# ---------------------------------------------------------
|
| 135 |
+
# Initiate sections
|
| 136 |
+
section_dead, individual, radio_circumstance_dead, radio_physical_dead,\
|
| 137 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
| 138 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 139 |
+
physical_boxes_dead, \
|
| 140 |
+
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, \
|
| 141 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 142 |
+
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 143 |
+
= show_section_dead(False, individual)
|
| 144 |
+
|
| 145 |
+
section_wounded, individual, radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
| 146 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
| 147 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
| 148 |
+
behavior_checkbox, behavior_text, \
|
| 149 |
+
physical_boxes_wounded, \
|
| 150 |
+
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, \
|
| 151 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 152 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 153 |
+
= show_section_wounded(False, individual)
|
| 154 |
+
|
| 155 |
+
# ---------------------------------------------------------
|
| 156 |
+
# ---------------------------------------------------------
|
| 157 |
+
# ---------------------------------------------------------
|
| 158 |
+
# Dead Button Logic
|
| 159 |
+
partial_show_section_dead = partial(show_section_dead, True)
|
| 160 |
+
partial_hide_section_wounded = partial(show_section_wounded, False)
|
| 161 |
+
butt_dead.click(partial_show_section_dead,
|
| 162 |
+
inputs=[individual],
|
| 163 |
+
outputs=[section_dead,
|
| 164 |
+
individual,
|
| 165 |
+
radio_circumstance_dead, radio_physical_dead,
|
| 166 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 167 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
| 168 |
+
physical_boxes_dead, \
|
| 169 |
+
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, \
|
| 170 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 171 |
+
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 172 |
+
])
|
| 173 |
+
|
| 174 |
+
butt_dead.click(partial_hide_section_wounded,
|
| 175 |
+
inputs=[individual],
|
| 176 |
+
outputs=[section_wounded,
|
| 177 |
+
individual,
|
| 178 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 179 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 180 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 181 |
+
behavior_checkbox, behavior_text,
|
| 182 |
+
physical_boxes_wounded, \
|
| 183 |
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, \
|
| 184 |
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 185 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 186 |
+
])
|
| 187 |
|
| 188 |
+
# ---------------------------------------------------------
|
| 189 |
+
# Wounded Button Logic
|
| 190 |
+
partial_show_section_wounded = partial(show_section_wounded, True)
|
| 191 |
+
partial_hide_section_dead = partial(show_section_dead, False)
|
| 192 |
+
|
| 193 |
+
butt_wounded.click(partial_show_section_wounded,
|
| 194 |
+
inputs=[individual],
|
| 195 |
+
outputs=[section_wounded,
|
| 196 |
+
individual,
|
| 197 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 198 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 199 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 200 |
+
behavior_checkbox, behavior_text,
|
| 201 |
+
physical_boxes_wounded, \
|
| 202 |
+
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, \
|
| 203 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
| 204 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
| 205 |
+
])
|
| 206 |
+
|
| 207 |
+
butt_wounded.click(partial_hide_section_dead,
|
| 208 |
inputs=[individual],
|
| 209 |
outputs=[section_dead,
|
| 210 |
individual,
|
|
|
|
| 216 |
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
| 217 |
fe_name_recipient_dead, fe_collection_ref_dead \
|
| 218 |
])
|
| 219 |
+
|
| 220 |
+
# ---------------------------------------------------------
|
| 221 |
+
# ---------------------------------------------------------
|
| 222 |
+
# ---------------------------------------------------------
|
| 223 |
+
# ---------------------------------------------------------
|
| 224 |
+
# DEAD
|
| 225 |
+
# ---------------------------------------------------------
|
| 226 |
+
# Radio Circumstance Dead
|
| 227 |
+
radio_circumstance_dead.change(fn=show_circumstances,
|
| 228 |
+
inputs=[radio_circumstance_dead, individual],
|
| 229 |
+
outputs=[button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 230 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual]
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
# Dropdowns Dead
|
| 234 |
+
button_collision_dead.click(dropdown_collision,
|
| 235 |
+
inputs=[individual],
|
| 236 |
+
outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 237 |
+
button_deliberate_destruction_dead.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 238 |
+
button_indirect_destruction_dead.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 239 |
+
button_natural_cause_dead.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 240 |
|
| 241 |
+
dropdown_dead.select(on_select, inputs=[individual], outputs=[dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])
|
| 242 |
+
dropdown_level2_dead.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual] )
|
| 243 |
+
openfield_level2_dead.change(on_change_openfield_level2, inputs=[openfield_level2_dead, individual], outputs=[individual])
|
| 244 |
+
dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])
|
| 245 |
+
# ---------------------------------------------------------
|
| 246 |
+
# Radio Physical Dead
|
| 247 |
+
radio_physical_dead.change(fn=show_physical,
|
| 248 |
+
inputs=[radio_physical_dead, gr.Text("dead", visible=False), individual],
|
| 249 |
+
outputs=[physical_boxes_dead, individual])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
+
# Checkbox Physical Dead
|
| 252 |
+
physical_boxes_dead.select(find_bounding_box,
|
| 253 |
+
inputs=[physical_boxes_dead, gr.Textbox(value="dead", visible=False)],
|
| 254 |
+
outputs=[checkbox_beak_dead, text_beak_dead,
|
| 255 |
+
checkbox_body_dead, text_body_dead,
|
| 256 |
+
checkbox_feathers_dead, text_feathers_dead,
|
| 257 |
+
checkbox_head_dead, text_head_dead,
|
| 258 |
+
checkbox_legs_dead, text_legs_dead
|
| 259 |
+
])
|
| 260 |
+
checkbox_beak_dead.select(on_select_body_part, inputs=[checkbox_beak_dead, gr.Text("beak", visible=False), individual], outputs=[individual])
|
| 261 |
+
checkbox_body_dead.select(on_select_body_part, inputs=[checkbox_body_dead, gr.Text("body", visible=False), individual], outputs=[individual])
|
| 262 |
+
checkbox_feathers_dead.select(on_select_body_part, inputs=[checkbox_feathers_dead, gr.Text("feathers", visible=False), individual], outputs=[individual])
|
| 263 |
+
checkbox_head_dead.select(on_select_body_part, inputs=[checkbox_head_dead, gr.Text("head", visible=False), individual], outputs=[individual])
|
| 264 |
+
checkbox_legs_dead.select(on_select_body_part, inputs=[checkbox_legs_dead, gr.Text("legs", visible=False), individual], outputs=[individual])
|
| 265 |
+
# ---------------------------------------------------------
|
| 266 |
+
# ---------------------------------------------------------
|
| 267 |
+
# ---------------------------------------------------------
|
| 268 |
+
# ---------------------------------------------------------
|
| 269 |
+
# WOUNDED
|
| 270 |
+
# ---------------------------------------------------------
|
| 271 |
+
# Radio Circumstance Wounded
|
| 272 |
+
radio_circumstance_wounded.change(fn=show_circumstances,
|
| 273 |
+
inputs=[radio_circumstance_wounded, individual],
|
| 274 |
+
outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 275 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual]
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
# Dropdowns Circumstance Wounded
|
| 279 |
+
button_collision_wounded.click(dropdown_collision,
|
| 280 |
+
inputs=[individual],
|
| 281 |
+
outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 282 |
+
button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 283 |
+
button_indirect_destruction_wounded.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 284 |
+
button_natural_cause_wounded.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 285 |
+
|
| 286 |
+
dropdown_wounded.select(on_select, inputs=[individual], outputs=[dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])
|
| 287 |
+
dropdown_level2_wounded.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])
|
| 288 |
+
openfield_level2_wounded.change(on_change_openfield_level2, inputs=[openfield_level2_wounded, individual])
|
| 289 |
+
dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])
|
| 290 |
+
# ---------------------------------------------------------
|
| 291 |
+
# Radio Behavior Wounded
|
| 292 |
+
radio_behavior_wounded.change(fn=show_behavior,
|
| 293 |
+
inputs=[radio_behavior_wounded, gr.Text("wounded / sick", visible=False), individual],
|
| 294 |
+
outputs=[behavior_checkbox, behavior_text, individual])
|
| 295 |
+
behavior_checkbox.select(on_select_behavior,
|
| 296 |
+
inputs=[behavior_checkbox, individual],
|
| 297 |
+
outputs=[individual])
|
| 298 |
+
# ---------------------------------------------------------
|
| 299 |
+
# Radio Physical Wounded
|
| 300 |
+
radio_physical_wounded.change(fn=show_physical,
|
| 301 |
+
inputs=[radio_physical_wounded, gr.Text("wounded / sick", visible=False), individual],
|
| 302 |
+
outputs=[physical_boxes_wounded, individual])
|
| 303 |
|
| 304 |
+
# Checkbox Physical Wounded
|
| 305 |
+
physical_boxes_wounded.select(find_bounding_box,
|
| 306 |
+
inputs=[physical_boxes_wounded, gr.Textbox(value="wounded / sick", visible=False)],
|
| 307 |
+
outputs=[checkbox_beak_wounded, text_beak_wounded,
|
| 308 |
+
checkbox_body_wounded, text_body_wounded,
|
| 309 |
+
checkbox_feathers_wounded, text_feathers_wounded,
|
| 310 |
+
checkbox_head_wounded, text_head_wounded,
|
| 311 |
+
checkbox_legs_wounded, text_legs_wounded
|
| 312 |
+
])
|
| 313 |
+
checkbox_beak_wounded.select(on_select_body_part, inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False), individual], outputs=[individual])
|
| 314 |
+
checkbox_body_wounded.select(on_select_body_part, inputs=[checkbox_body_wounded, gr.Text("body", visible=False), individual], outputs=[individual])
|
| 315 |
+
checkbox_feathers_wounded.select(on_select_body_part, inputs=[checkbox_feathers_wounded, gr.Text("feathers", visible=False), individual], outputs=[individual])
|
| 316 |
+
checkbox_head_wounded.select(on_select_body_part, inputs=[checkbox_head_wounded, gr.Text("head", visible=False), individual], outputs=[individual])
|
| 317 |
+
checkbox_legs_wounded.select(on_select_body_part, inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False), individual], outputs=[individual])
|
| 318 |
+
|
| 319 |
+
# ---------------------------------------------------------
|
| 320 |
+
# Follow Up Events Wounded
|
| 321 |
+
fe_collection_dropdown_wounded.select(save_fe, inputs=[fe_collection_dropdown_wounded, gr.Textbox("animal collected", visible=False), individual], outputs=[individual])
|
| 322 |
+
fe_recepient_dropdown_wounded.select(save_fe, inputs=[fe_recepient_dropdown_wounded, gr.Textbox("recipient", visible=False), individual],outputs=[individual])
|
| 323 |
+
fe_radio_dropdown_wounded.select(save_fe, inputs=[fe_radio_dropdown_wounded, gr.Textbox("radiography", visible=False), individual],outputs=[individual])
|
| 324 |
+
fe_answer_dropdown_wounded.select(save_fe, inputs=[fe_answer_dropdown_wounded, gr.Textbox("given answer", visible=False), individual],outputs=[individual])
|
| 325 |
+
fe_name_recipient_wounded.input(save_fe, inputs=[fe_name_recipient_wounded, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])
|
| 326 |
+
fe_collection_ref_wounded.input(save_fe, inputs=[fe_collection_ref_wounded, gr.Textbox("collection reference", visible=False), individual],outputs=[individual])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
|
| 328 |
+
# ---------------------------------------------------------
|
| 329 |
+
# Follow Up Events Dead
|
| 330 |
+
fe_collection_dropdown_dead.select(save_fe, inputs=[fe_collection_dropdown_dead, gr.Textbox("animal collected", visible=False), individual],outputs=[individual])
|
| 331 |
+
fe_recepient_dropdown_dead.select(save_fe, inputs=[fe_recepient_dropdown_dead, gr.Textbox("recipient", visible=False), individual],outputs=[individual])
|
| 332 |
+
fe_radio_dropdown_dead.select(save_fe, inputs=[fe_radio_dropdown_dead, gr.Textbox("radiography", visible=False), individual],outputs=[individual])
|
| 333 |
+
fe_answer_dropdown_dead.select(save_fe, inputs=[fe_answer_dropdown_dead, gr.Textbox("given answer", visible=False), individual],outputs=[individual])
|
| 334 |
+
fe_name_recipient_dead.input(save_fe, inputs=[fe_name_recipient_dead, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])
|
| 335 |
+
fe_collection_ref_dead.input(save_fe, inputs=[fe_collection_ref_dead, gr.Textbox("collection reference", visible=False), individual], outputs=[individual])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
+
# ---------------------------------------------------------
|
| 338 |
+
# Error Box
|
| 339 |
+
error_box = gr.Text(value=None, visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
|
| 341 |
+
# ---------------------------------------------------------
|
| 342 |
+
# Allow clearing of all previous output
|
| 343 |
+
with gr.Row():
|
| 344 |
+
button_df = gr.Button("Submit Animal Report", scale = 3)
|
| 345 |
+
button_clear = gr.ClearButton(scale = 1,
|
| 346 |
+
components=[
|
| 347 |
+
camera,
|
| 348 |
+
location, identified_location,
|
| 349 |
+
#dead reset
|
| 350 |
+
radio_circumstance_dead, radio_physical_dead,
|
| 351 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
| 352 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
|
| 353 |
+
physical_boxes_dead,
|
| 354 |
+
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,
|
| 355 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead,
|
| 356 |
+
fe_name_recipient_dead, fe_collection_ref_dead,
|
| 357 |
+
#wounded reset
|
| 358 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
| 359 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
| 360 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
| 361 |
+
behavior_checkbox, behavior_text,
|
| 362 |
+
physical_boxes_wounded,
|
| 363 |
+
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,
|
| 364 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded,
|
| 365 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded,
|
| 366 |
+
error_box
|
| 367 |
+
])
|
| 368 |
|
| 369 |
+
# ---------------------------------------------------------
|
| 370 |
+
# Button Click Logic
|
| 371 |
+
button_clear.click()
|
| 372 |
+
button_clear.click(hide_physical,
|
| 373 |
+
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])
|
| 374 |
+
button_clear.click(hide_physical,
|
| 375 |
+
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])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
|
| 377 |
+
button_clear.click(reset_error_box, inputs=[error_box], outputs=[error_box])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
|
| 379 |
+
from validation_submission.submission import validate_save_individual
|
| 380 |
+
button_df.click(validate_save_individual, inputs=[individual, error_box],
|
| 381 |
+
outputs=[error_box])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
|
| 383 |
|
| 384 |
if __name__ == "__main__":
|
app/physical/physical_boxes_map.py
CHANGED
|
@@ -17,9 +17,6 @@ def draw_bounding_boxes(image_path, gdf):
|
|
| 17 |
# try:
|
| 18 |
font = ImageFont.truetype(PATH_ASSETS + "fonts/LiberationSans-Regular.ttf",
|
| 19 |
20)
|
| 20 |
-
# except IOError:
|
| 21 |
-
# print("default")
|
| 22 |
-
# font = ImageFont.load_default()
|
| 23 |
|
| 24 |
# Draw each bounding box on the image
|
| 25 |
for _, row in gdf.iterrows():
|
|
|
|
| 17 |
# try:
|
| 18 |
font = ImageFont.truetype(PATH_ASSETS + "fonts/LiberationSans-Regular.ttf",
|
| 19 |
20)
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Draw each bounding box on the image
|
| 22 |
for _, row in gdf.iterrows():
|
app/physical/physical_checkbox.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils.utils_config import get_custom_config_dropdowns
|
| 3 |
from utils.utils_checkbox import create_checkbox
|
| 4 |
-
from validation_submission.
|
| 5 |
#---------------------------------------------------------
|
| 6 |
def get_body_parts():
|
| 7 |
dropdown_config = get_custom_config_dropdowns("config_checkbox_physical.json")
|
|
@@ -72,9 +72,9 @@ def process_body_parts(section, matched_box):
|
|
| 72 |
#---------------------------------------------------------
|
| 73 |
|
| 74 |
def on_select_body_part(body_part_checkbox, body_part, individual):
|
| 75 |
-
individual =
|
| 76 |
body_part_checkbox = [body_part_check.lower() for body_part_check in body_part_checkbox]
|
| 77 |
-
individual =
|
| 78 |
return individual
|
| 79 |
|
| 80 |
#---------------------------------------------------------
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils.utils_config import get_custom_config_dropdowns
|
| 3 |
from utils.utils_checkbox import create_checkbox
|
| 4 |
+
from validation_submission.utils_individual import add_data_to_individual
|
| 5 |
#---------------------------------------------------------
|
| 6 |
def get_body_parts():
|
| 7 |
dropdown_config = get_custom_config_dropdowns("config_checkbox_physical.json")
|
|
|
|
| 72 |
#---------------------------------------------------------
|
| 73 |
|
| 74 |
def on_select_body_part(body_part_checkbox, body_part, individual):
|
| 75 |
+
individual = add_data_to_individual("wounded_dead", "physical_type_"+body_part.lower(), body_part.lower(), individual)
|
| 76 |
body_part_checkbox = [body_part_check.lower() for body_part_check in body_part_checkbox]
|
| 77 |
+
individual = add_data_to_individual("wounded_dead", "physical_anomaly_"+body_part.lower(), body_part_checkbox, individual)
|
| 78 |
return individual
|
| 79 |
|
| 80 |
#---------------------------------------------------------
|
app/physical/physical_select_animal.py
CHANGED
|
@@ -29,7 +29,6 @@ def find_bounding_box(evt: gr.SelectData, img, section: str):
|
|
| 29 |
# Gradio app
|
| 30 |
def create_bird_anatomy(visible, section: str):
|
| 31 |
# Draw bounding boxes on the image
|
| 32 |
-
print
|
| 33 |
img_with_boxes = gr.Image(value=PATH_ASSETS+'images/bird_boxed.png',
|
| 34 |
show_label=False,
|
| 35 |
height="600px",
|
|
|
|
| 29 |
# Gradio app
|
| 30 |
def create_bird_anatomy(visible, section: str):
|
| 31 |
# Draw bounding boxes on the image
|
|
|
|
| 32 |
img_with_boxes = gr.Image(value=PATH_ASSETS+'images/bird_boxed.png',
|
| 33 |
show_label=False,
|
| 34 |
height="600px",
|
app/validation_submission/add_json.py
DELETED
|
@@ -1,19 +0,0 @@
|
|
| 1 |
-
from validation_submission.create_json import create_json_one_individual, create_tmp
|
| 2 |
-
import json
|
| 3 |
-
|
| 4 |
-
def add_data_to_individual(key, value, individual):
|
| 5 |
-
# with open("data/one_individual.json", 'r') as openfile:
|
| 6 |
-
# one_individual = json.load(openfile)
|
| 7 |
-
# one_individual[key] = value
|
| 8 |
-
# create_json_one_individual(one_individual)
|
| 9 |
-
individual[key] = value
|
| 10 |
-
return individual
|
| 11 |
-
|
| 12 |
-
def add_data_tmp(tmp_name, key, value, individual):
|
| 13 |
-
# with open(f"app/assets/tmp_json/tmp_{tmp_name}.json", 'r') as openfile:
|
| 14 |
-
# tmp = json.load(openfile)
|
| 15 |
-
# tmp[key] = value
|
| 16 |
-
# create_tmp(tmp_name, tmp)
|
| 17 |
-
individual[key] = value
|
| 18 |
-
return individual
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/validation_submission/get_json.py
DELETED
|
@@ -1,20 +0,0 @@
|
|
| 1 |
-
import json
|
| 2 |
-
|
| 3 |
-
def get_json_one_individual():
|
| 4 |
-
with open("data/one_individual.json", 'r') as openfile:
|
| 5 |
-
one_individual = json.load(openfile)
|
| 6 |
-
return one_individual
|
| 7 |
-
|
| 8 |
-
## TO DO : check this works
|
| 9 |
-
import os
|
| 10 |
-
def get_json_all_individuals():
|
| 11 |
-
all_animals = os.getfiles("data")
|
| 12 |
-
all_individuals = []
|
| 13 |
-
for animal in all_animals:
|
| 14 |
-
all_individuals.append(animal)
|
| 15 |
-
return all_individuals
|
| 16 |
-
|
| 17 |
-
def get_json_tmp(tmp_name):
|
| 18 |
-
with open(f"app/assets/tmp_json/tmp_{tmp_name}.json", "r") as openfile:
|
| 19 |
-
tmp_json = json.load(openfile)
|
| 20 |
-
return tmp_json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/validation_submission/submission.py
CHANGED
|
@@ -1,30 +1,24 @@
|
|
| 1 |
import json
|
| 2 |
-
from validation_submission.get_json import get_json_all_individuals
|
| 3 |
from validation_submission.validation import validate_individual
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
def validate_save_individual(data, error_box):
|
| 6 |
individual, error_box = validate_individual(data, error_box)
|
| 7 |
if individual:
|
| 8 |
-
|
| 9 |
-
return
|
| 10 |
-
|
| 11 |
-
def
|
| 12 |
-
all_individuals = get_json_all_individuals()
|
| 13 |
-
all_individuals[str(len(all_individuals))] = one_individual
|
| 14 |
-
all_individuals_for_json = json.dumps(all_individuals)
|
| 15 |
-
with open("data/all_individuals.json", "w") as outfile:
|
| 16 |
-
outfile.write(all_individuals_for_json)
|
| 17 |
-
return all_individuals
|
| 18 |
-
|
| 19 |
-
from huggingface_hub import HfApi
|
| 20 |
-
import os
|
| 21 |
-
|
| 22 |
-
#save all individuals one by one in JSON wish md5 hash as json name
|
| 23 |
-
def push_to_dataset_hf():
|
| 24 |
token = os.environ.get("HF_TOKEN", None)
|
| 25 |
api = HfApi(token=token)
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
api.upload_file(
|
| 29 |
path_or_fileobj=f.name,
|
| 30 |
path_in_repo=path_in_repo,
|
|
|
|
| 1 |
import json
|
|
|
|
| 2 |
from validation_submission.validation import validate_individual
|
| 3 |
|
| 4 |
+
from huggingface_hub import HfApi
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
def validate_save_individual(data, error_box):
|
| 8 |
individual, error_box = validate_individual(data, error_box)
|
| 9 |
if individual:
|
| 10 |
+
push_to_dataset_hf(individual.model_dump())
|
| 11 |
+
return error_box
|
| 12 |
+
|
| 13 |
+
def push_to_dataset_hf(individual):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
token = os.environ.get("HF_TOKEN", None)
|
| 15 |
api = HfApi(token=token)
|
| 16 |
+
import tempfile
|
| 17 |
+
f = tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False)
|
| 18 |
+
json.dump(individual, f)
|
| 19 |
+
f.flush()
|
| 20 |
+
f.close()
|
| 21 |
+
path_in_repo= f"data/{individual['image_md5']}.json"
|
| 22 |
api.upload_file(
|
| 23 |
path_or_fileobj=f.name,
|
| 24 |
path_in_repo=path_in_repo,
|
app/validation_submission/{create_json.py → utils_individual.py}
RENAMED
|
@@ -1,8 +1,5 @@
|
|
| 1 |
-
import json
|
| 2 |
-
|
| 3 |
import random
|
| 4 |
import string
|
| 5 |
-
|
| 6 |
import hashlib
|
| 7 |
|
| 8 |
def generate_random_md5():
|
|
@@ -12,22 +9,7 @@ def generate_random_md5():
|
|
| 12 |
md5_hash = hashlib.md5(random_string.encode()).hexdigest()
|
| 13 |
return md5_hash
|
| 14 |
|
| 15 |
-
def
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
outfile.write(one_individual)
|
| 20 |
-
|
| 21 |
-
def create_json_all_individuals(all_individuals={}):
|
| 22 |
-
all_individuals = json.dumps(all_individuals)
|
| 23 |
-
with open("data/all_individuals.json", "w") as outfile:
|
| 24 |
-
outfile.write(all_individuals)
|
| 25 |
-
|
| 26 |
-
def create_tmp(tmp_name="wounded_dead", tmp={}):
|
| 27 |
-
tmp = json.dumps(tmp)
|
| 28 |
-
with open(f"app/assets/tmp_json/tmp_{tmp_name}.json", "w") as outfile:
|
| 29 |
-
outfile.write(tmp)
|
| 30 |
-
|
| 31 |
-
def reset_json():
|
| 32 |
-
create_json_one_individual()
|
| 33 |
-
create_tmp()
|
|
|
|
|
|
|
|
|
|
| 1 |
import random
|
| 2 |
import string
|
|
|
|
| 3 |
import hashlib
|
| 4 |
|
| 5 |
def generate_random_md5():
|
|
|
|
| 9 |
md5_hash = hashlib.md5(random_string.encode()).hexdigest()
|
| 10 |
return md5_hash
|
| 11 |
|
| 12 |
+
def add_data_to_individual(key, value, individual):
|
| 13 |
+
individual[key] = value
|
| 14 |
+
return individual
|
| 15 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/validation_submission/validation.py
CHANGED
|
@@ -2,7 +2,7 @@ import uuid
|
|
| 2 |
from pydantic import ValidationError
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
from validation_submission.get_json import get_json_tmp, get_json_one_individual
|
| 6 |
from circumstances.class_circumstance import Circumstances
|
| 7 |
from behavior.class_behavior import Behaviors
|
| 8 |
from physical.class_physical import PhysicalAnomalies
|
|
@@ -50,6 +50,7 @@ def validate_individual(data, error_box):
|
|
| 50 |
try :
|
| 51 |
individual = Report(identifier = data["identifier"],
|
| 52 |
image = img,
|
|
|
|
| 53 |
geolocalisation = geolocalisation,
|
| 54 |
wounded_state = data["wounded_state"],
|
| 55 |
wounded = Wounded(circumstances = circumstance,
|
|
@@ -65,6 +66,7 @@ def validate_individual(data, error_box):
|
|
| 65 |
try:
|
| 66 |
individual = Report(identifier = data["identifier"],
|
| 67 |
image = img,
|
|
|
|
| 68 |
geolocalisation = geolocalisation,
|
| 69 |
wounded_state = data["wounded_state"],
|
| 70 |
dead_state = data["dead_state"],
|
|
@@ -79,6 +81,7 @@ def validate_individual(data, error_box):
|
|
| 79 |
try:
|
| 80 |
individual = Report(identifier = data["identifier"],
|
| 81 |
image = img,
|
|
|
|
| 82 |
geolocalisation = geolocalisation,
|
| 83 |
wounded_state = data["wounded_state"],
|
| 84 |
dead_state = data["dead_state"])
|
|
|
|
| 2 |
from pydantic import ValidationError
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# from validation_submission.get_json import get_json_tmp, get_json_one_individual
|
| 6 |
from circumstances.class_circumstance import Circumstances
|
| 7 |
from behavior.class_behavior import Behaviors
|
| 8 |
from physical.class_physical import PhysicalAnomalies
|
|
|
|
| 50 |
try :
|
| 51 |
individual = Report(identifier = data["identifier"],
|
| 52 |
image = img,
|
| 53 |
+
image_md5 = data["image_md5"],
|
| 54 |
geolocalisation = geolocalisation,
|
| 55 |
wounded_state = data["wounded_state"],
|
| 56 |
wounded = Wounded(circumstances = circumstance,
|
|
|
|
| 66 |
try:
|
| 67 |
individual = Report(identifier = data["identifier"],
|
| 68 |
image = img,
|
| 69 |
+
image_md5 = data["image_md5"],
|
| 70 |
geolocalisation = geolocalisation,
|
| 71 |
wounded_state = data["wounded_state"],
|
| 72 |
dead_state = data["dead_state"],
|
|
|
|
| 81 |
try:
|
| 82 |
individual = Report(identifier = data["identifier"],
|
| 83 |
image = img,
|
| 84 |
+
image_md5 = data["image_md5"],
|
| 85 |
geolocalisation = geolocalisation,
|
| 86 |
wounded_state = data["wounded_state"],
|
| 87 |
dead_state = data["dead_state"])
|
app/wounded.py
CHANGED
|
@@ -4,7 +4,7 @@ from physical.physical_select_animal import create_bird_anatomy
|
|
| 4 |
from physical.physical_checkbox import process_body_parts
|
| 5 |
from behavior.behavior_checkbox import create_behavior_checkbox
|
| 6 |
from follow_up.followup_events import create_followup_dropdowns, create_followup_open
|
| 7 |
-
from validation_submission.
|
| 8 |
|
| 9 |
def show_section_wounded(visible, individual):
|
| 10 |
if visible==True:
|
|
|
|
| 4 |
from physical.physical_checkbox import process_body_parts
|
| 5 |
from behavior.behavior_checkbox import create_behavior_checkbox
|
| 6 |
from follow_up.followup_events import create_followup_dropdowns, create_followup_open
|
| 7 |
+
from validation_submission.utils_individual import add_data_to_individual
|
| 8 |
|
| 9 |
def show_section_wounded(visible, individual):
|
| 10 |
if visible==True:
|