fix: cleaning and resets together
Browse files- app/circumstances/circumstances_dropdowns.py +0 -1
- app/mode_advanced.py +3 -5
- app/mode_simple.py +3 -8
- app/physical/physical_checkbox.py +0 -30
- app/validation_submission/resets.py +46 -0
- app/validation_submission/utils_individual.py +1 -4
- app/validation_submission/validation.py +3 -17
- test.py +0 -10
app/circumstances/circumstances_dropdowns.py
CHANGED
|
@@ -135,7 +135,6 @@ def on_select_dropdown_extra_level2(evt: gr.SelectData, individual):
|
|
| 135 |
|
| 136 |
|
| 137 |
def on_change_openfield_level2(openfield_level2_dead, individual):
|
| 138 |
-
# print("Saving open field")
|
| 139 |
individual = add_data_to_individual(
|
| 140 |
"circumstance_open_field", str(openfield_level2_dead).lower(), individual
|
| 141 |
)
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
def on_change_openfield_level2(openfield_level2_dead, individual):
|
|
|
|
| 138 |
individual = add_data_to_individual(
|
| 139 |
"circumstance_open_field", str(openfield_level2_dead).lower(), individual
|
| 140 |
)
|
app/mode_advanced.py
CHANGED
|
@@ -9,17 +9,15 @@ from dead_wounded.wounded import show_section_wounded
|
|
| 9 |
from circumstances.circumstances import show_circumstances
|
| 10 |
from circumstances.circumstances_dropdowns import *
|
| 11 |
from physical.physical_select_animal import show_physical, find_bounding_box
|
| 12 |
-
from physical.physical_checkbox import on_select_body_part
|
| 13 |
from behavior.behavior_checkbox import show_behavior, on_select_behavior
|
| 14 |
from follow_up.followup_events import save_fe
|
| 15 |
from styling.style import *
|
| 16 |
from validation_submission.utils_individual import generate_random_md5
|
| 17 |
from validation_submission.utils_individual import add_data_to_individual
|
| 18 |
from validation_submission.submission import validate_save_individual
|
| 19 |
-
from validation_submission.validation import reset_error_box
|
| 20 |
-
from validation_submission.utils_individual import reset_individual
|
| 21 |
from validation_submission.utils_save import save_details, save_image
|
| 22 |
-
|
| 23 |
|
| 24 |
from dotenv import load_dotenv
|
| 25 |
import os
|
|
@@ -129,7 +127,7 @@ with gr.Blocks(theme='shivi/calm_seafoam') as advanced:
|
|
| 129 |
location_data = gr.JSON(label="Identified GPS Location", visible=False)
|
| 130 |
hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 131 |
locationtext = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 132 |
-
btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required)")
|
| 133 |
btn_gpslocation.click(None, [], [], js=js_geocode)
|
| 134 |
hidden_input.change(display_location,
|
| 135 |
inputs=[hidden_input, individual],
|
|
|
|
| 9 |
from circumstances.circumstances import show_circumstances
|
| 10 |
from circumstances.circumstances_dropdowns import *
|
| 11 |
from physical.physical_select_animal import show_physical, find_bounding_box
|
| 12 |
+
from physical.physical_checkbox import on_select_body_part
|
| 13 |
from behavior.behavior_checkbox import show_behavior, on_select_behavior
|
| 14 |
from follow_up.followup_events import save_fe
|
| 15 |
from styling.style import *
|
| 16 |
from validation_submission.utils_individual import generate_random_md5
|
| 17 |
from validation_submission.utils_individual import add_data_to_individual
|
| 18 |
from validation_submission.submission import validate_save_individual
|
|
|
|
|
|
|
| 19 |
from validation_submission.utils_save import save_details, save_image
|
| 20 |
+
from validation_submission.resets import reset_individual, reset_error_box, hide_physical
|
| 21 |
|
| 22 |
from dotenv import load_dotenv
|
| 23 |
import os
|
|
|
|
| 127 |
location_data = gr.JSON(label="Identified GPS Location", visible=False)
|
| 128 |
hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 129 |
locationtext = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 130 |
+
btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required - May take a few seconds)")
|
| 131 |
btn_gpslocation.click(None, [], [], js=js_geocode)
|
| 132 |
hidden_input.change(display_location,
|
| 133 |
inputs=[hidden_input, individual],
|
app/mode_simple.py
CHANGED
|
@@ -8,16 +8,13 @@ from dead_wounded.wounded import show_section_wounded
|
|
| 8 |
from circumstances.circumstances import show_circumstances
|
| 9 |
from circumstances.circumstances_dropdowns import *
|
| 10 |
from physical.physical_select_animal import show_physical, find_bounding_box
|
| 11 |
-
from physical.physical_checkbox import on_select_body_part
|
| 12 |
from behavior.behavior_checkbox import show_behavior, on_select_behavior
|
| 13 |
from follow_up.followup_events import save_fe
|
| 14 |
from styling.style import *
|
| 15 |
-
from validation_submission.utils_individual import reset_individual
|
| 16 |
-
from validation_submission.utils_individual import add_data_to_individual
|
| 17 |
from validation_submission.submission import validate_save_individual
|
| 18 |
-
from validation_submission.validation import reset_error_box
|
| 19 |
-
from validation_submission.utils_individual import generate_random_md5
|
| 20 |
from validation_submission.utils_save import save_details, save_image
|
|
|
|
| 21 |
|
| 22 |
from dotenv import load_dotenv
|
| 23 |
import os
|
|
@@ -29,8 +26,6 @@ PATH_ICONS = PATH + PATH_ASSETS + "icons/"
|
|
| 29 |
with gr.Blocks(theme='shivi/calm_seafoam') as simple:
|
| 30 |
mode = "simple"
|
| 31 |
individual = gr.State({})
|
| 32 |
-
individual.value = add_data_to_individual("image_md5", generate_random_md5(), individual.value)
|
| 33 |
-
|
| 34 |
# ---------------------------------------------------------
|
| 35 |
# Header Text
|
| 36 |
with gr.Row():
|
|
@@ -106,7 +101,7 @@ with gr.Blocks(theme='shivi/calm_seafoam') as simple:
|
|
| 106 |
location_data = gr.JSON(label="Identified GPS Location", visible=False)
|
| 107 |
hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 108 |
locationtext = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 109 |
-
btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required)")
|
| 110 |
btn_gpslocation.click(None, [], [], js=js_geocode)
|
| 111 |
hidden_input.change(display_location,
|
| 112 |
inputs=[hidden_input, individual],
|
|
|
|
| 8 |
from circumstances.circumstances import show_circumstances
|
| 9 |
from circumstances.circumstances_dropdowns import *
|
| 10 |
from physical.physical_select_animal import show_physical, find_bounding_box
|
| 11 |
+
from physical.physical_checkbox import on_select_body_part
|
| 12 |
from behavior.behavior_checkbox import show_behavior, on_select_behavior
|
| 13 |
from follow_up.followup_events import save_fe
|
| 14 |
from styling.style import *
|
|
|
|
|
|
|
| 15 |
from validation_submission.submission import validate_save_individual
|
|
|
|
|
|
|
| 16 |
from validation_submission.utils_save import save_details, save_image
|
| 17 |
+
from validation_submission.resets import reset_individual, reset_error_box, hide_physical
|
| 18 |
|
| 19 |
from dotenv import load_dotenv
|
| 20 |
import os
|
|
|
|
| 26 |
with gr.Blocks(theme='shivi/calm_seafoam') as simple:
|
| 27 |
mode = "simple"
|
| 28 |
individual = gr.State({})
|
|
|
|
|
|
|
| 29 |
# ---------------------------------------------------------
|
| 30 |
# Header Text
|
| 31 |
with gr.Row():
|
|
|
|
| 101 |
location_data = gr.JSON(label="Identified GPS Location", visible=False)
|
| 102 |
hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 103 |
locationtext = gr.Textbox(visible=False, elem_id="textbox_id")
|
| 104 |
+
btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required - May take a few seconds)")
|
| 105 |
btn_gpslocation.click(None, [], [], js=js_geocode)
|
| 106 |
hidden_input.change(display_location,
|
| 107 |
inputs=[hidden_input, individual],
|
app/physical/physical_checkbox.py
CHANGED
|
@@ -17,7 +17,6 @@ def retrieve_config_options(label, dropdown_config):
|
|
| 17 |
|
| 18 |
|
| 19 |
def get_options_description(value, mode):
|
| 20 |
-
# print(f"Get options description: {mode}")
|
| 21 |
if mode == "simple":
|
| 22 |
dropdown_config = get_custom_config_dropdowns(
|
| 23 |
"config_checkbox_physical_simple.json"
|
|
@@ -132,32 +131,3 @@ def on_select_body_part(body_part_checkbox, body_part, individual):
|
|
| 132 |
)
|
| 133 |
return individual
|
| 134 |
|
| 135 |
-
|
| 136 |
-
# ---------------------------------------------------------
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
def hide_physical(mode):
|
| 140 |
-
(
|
| 141 |
-
checkbox_beak,
|
| 142 |
-
text_beak,
|
| 143 |
-
checkbox_body,
|
| 144 |
-
text_body,
|
| 145 |
-
checkbox_feathers,
|
| 146 |
-
text_feathers,
|
| 147 |
-
checkbox_head,
|
| 148 |
-
text_head,
|
| 149 |
-
checkbox_legs,
|
| 150 |
-
text_legs,
|
| 151 |
-
) = process_body_parts("wounded", mode, "None")
|
| 152 |
-
return (
|
| 153 |
-
checkbox_beak,
|
| 154 |
-
text_beak,
|
| 155 |
-
checkbox_body,
|
| 156 |
-
text_body,
|
| 157 |
-
checkbox_feathers,
|
| 158 |
-
text_feathers,
|
| 159 |
-
checkbox_head,
|
| 160 |
-
text_head,
|
| 161 |
-
checkbox_legs,
|
| 162 |
-
text_legs,
|
| 163 |
-
)
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
def get_options_description(value, mode):
|
|
|
|
| 20 |
if mode == "simple":
|
| 21 |
dropdown_config = get_custom_config_dropdowns(
|
| 22 |
"config_checkbox_physical_simple.json"
|
|
|
|
| 131 |
)
|
| 132 |
return individual
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/validation_submission/resets.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from physical.physical_checkbox import process_body_parts
|
| 4 |
+
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
import os
|
| 7 |
+
load_dotenv()
|
| 8 |
+
PATH = os.getcwd() + "/"
|
| 9 |
+
PATH_ASSETS = os.getenv('PATH_ASSETS')
|
| 10 |
+
PATH_ICONS = PATH + PATH_ASSETS + "icons/"
|
| 11 |
+
|
| 12 |
+
def reset_individual(individual):
|
| 13 |
+
individual = {}
|
| 14 |
+
return individual
|
| 15 |
+
|
| 16 |
+
def reset_error_box(error_icon, error_box):
|
| 17 |
+
error_icon = gr.Image(PATH_ICONS+"supprimer.png", height=80, width=80, visible=False)
|
| 18 |
+
error_box = gr.Text(value=None, visible=False)
|
| 19 |
+
return error_icon, error_box
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def hide_physical(mode):
|
| 23 |
+
(
|
| 24 |
+
checkbox_beak,
|
| 25 |
+
text_beak,
|
| 26 |
+
checkbox_body,
|
| 27 |
+
text_body,
|
| 28 |
+
checkbox_feathers,
|
| 29 |
+
text_feathers,
|
| 30 |
+
checkbox_head,
|
| 31 |
+
text_head,
|
| 32 |
+
checkbox_legs,
|
| 33 |
+
text_legs,
|
| 34 |
+
) = process_body_parts("wounded", mode, "None")
|
| 35 |
+
return (
|
| 36 |
+
checkbox_beak,
|
| 37 |
+
text_beak,
|
| 38 |
+
checkbox_body,
|
| 39 |
+
text_body,
|
| 40 |
+
checkbox_feathers,
|
| 41 |
+
text_feathers,
|
| 42 |
+
checkbox_head,
|
| 43 |
+
text_head,
|
| 44 |
+
checkbox_legs,
|
| 45 |
+
text_legs,
|
| 46 |
+
)
|
app/validation_submission/utils_individual.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import random
|
| 2 |
import string
|
| 3 |
import hashlib
|
| 4 |
-
import gradio as gr
|
| 5 |
|
| 6 |
def generate_random_md5():
|
| 7 |
# Generate a random string
|
|
@@ -14,7 +13,5 @@ def add_data_to_individual(key, value, individual):
|
|
| 14 |
individual[key] = value
|
| 15 |
return individual
|
| 16 |
|
| 17 |
-
|
| 18 |
-
individual = {}
|
| 19 |
-
return individual
|
| 20 |
|
|
|
|
| 1 |
import random
|
| 2 |
import string
|
| 3 |
import hashlib
|
|
|
|
| 4 |
|
| 5 |
def generate_random_md5():
|
| 6 |
# Generate a random string
|
|
|
|
| 13 |
individual[key] = value
|
| 14 |
return individual
|
| 15 |
|
| 16 |
+
|
|
|
|
|
|
|
| 17 |
|
app/validation_submission/validation.py
CHANGED
|
@@ -15,6 +15,8 @@ from validation_submission.processing import (
|
|
| 15 |
process_physical,
|
| 16 |
process_followup,
|
| 17 |
)
|
|
|
|
|
|
|
| 18 |
|
| 19 |
from dotenv import load_dotenv
|
| 20 |
import os
|
|
@@ -43,6 +45,7 @@ def validate_individual(data, error_icon, error_box, mode: str):
|
|
| 43 |
error_icon, error_box = reset_error_box(error_icon, error_box)
|
| 44 |
# data = get_json_one_individual() # TODO: This should change
|
| 45 |
data["identifier"] = str(uuid.uuid4())
|
|
|
|
| 46 |
img, geolocalisation, specie, number, comments = field_checker(data)
|
| 47 |
|
| 48 |
error_behavior = None
|
|
@@ -80,8 +83,6 @@ def validate_individual(data, error_icon, error_box, mode: str):
|
|
| 80 |
dead_state=data["dead_state"],
|
| 81 |
)
|
| 82 |
except ValidationError as e:
|
| 83 |
-
print("Error in wounded_state:")
|
| 84 |
-
print(e.json())
|
| 85 |
error_individual = e
|
| 86 |
|
| 87 |
elif data["dead_state"] == "Yes":
|
|
@@ -103,8 +104,6 @@ def validate_individual(data, error_icon, error_box, mode: str):
|
|
| 103 |
),
|
| 104 |
)
|
| 105 |
except ValidationError as e:
|
| 106 |
-
print("Error in dead_state:")
|
| 107 |
-
print(e.json())
|
| 108 |
error_individual = e
|
| 109 |
else:
|
| 110 |
try:
|
|
@@ -120,7 +119,6 @@ def validate_individual(data, error_icon, error_box, mode: str):
|
|
| 120 |
dead_state=data["dead_state"],
|
| 121 |
)
|
| 122 |
except ValidationError as e:
|
| 123 |
-
print(f"""Error in individual else: {e}""")
|
| 124 |
error_individual = e
|
| 125 |
if (
|
| 126 |
error_behavior
|
|
@@ -184,12 +182,6 @@ def show_error(
|
|
| 184 |
return error_box
|
| 185 |
|
| 186 |
|
| 187 |
-
def reset_error_box(error_icon, error_box):
|
| 188 |
-
error_icon = gr.Image(PATH_ICONS+"supprimer.png", height=80, width=80, visible=False)
|
| 189 |
-
error_box = gr.Text(value=None, visible=False)
|
| 190 |
-
return error_icon, error_box
|
| 191 |
-
|
| 192 |
-
|
| 193 |
#### VALIDATION FUNCTIONS
|
| 194 |
def validate_circumstance(data):
|
| 195 |
circumstance_raw = get_fields(data, "circumstance")
|
|
@@ -200,7 +192,6 @@ def validate_circumstance(data):
|
|
| 200 |
error = None
|
| 201 |
except ValidationError as e:
|
| 202 |
error = e
|
| 203 |
-
print(f"""Error in Validate_circumstance: {e}""")
|
| 204 |
circumstances = None
|
| 205 |
return circumstances, error
|
| 206 |
|
|
@@ -217,7 +208,6 @@ def validate_behavior(data, mode):
|
|
| 217 |
behavior = Behaviors(**behaviors_formatted)
|
| 218 |
error = None
|
| 219 |
except ValidationError as e:
|
| 220 |
-
print(f"""Error in behaviors validation: {e}""")
|
| 221 |
behavior = None
|
| 222 |
error = e
|
| 223 |
return behavior, error
|
|
@@ -226,7 +216,6 @@ def validate_behavior(data, mode):
|
|
| 226 |
def validate_physical(data, mode):
|
| 227 |
physical_raw = get_fields(data, "physical")
|
| 228 |
physical_formatted = process_physical(physical_raw)
|
| 229 |
-
# print(physical_formatted)
|
| 230 |
try:
|
| 231 |
if mode == "simple":
|
| 232 |
PhysicalAnomaliesSimple.model_validate(physical_formatted)
|
|
@@ -236,7 +225,6 @@ def validate_physical(data, mode):
|
|
| 236 |
physical = PhysicalAnomalies(**physical_formatted)
|
| 237 |
error = None
|
| 238 |
except ValidationError as e:
|
| 239 |
-
print(f"""Error in physical_anomalies validation: {e}""")
|
| 240 |
physical = None
|
| 241 |
error = e
|
| 242 |
return physical, error
|
|
@@ -250,7 +238,5 @@ def validate_follow_up(data):
|
|
| 250 |
followup = FollowUpEvents(**followup_formatted)
|
| 251 |
error = None
|
| 252 |
except ValidationError as e:
|
| 253 |
-
print(f"""Error in follow-up events validation: {e}""")
|
| 254 |
-
|
| 255 |
followup = None
|
| 256 |
return followup, error
|
|
|
|
| 15 |
process_physical,
|
| 16 |
process_followup,
|
| 17 |
)
|
| 18 |
+
from validation_submission.utils_individual import generate_random_md5
|
| 19 |
+
from validation_submission.resets import reset_error_box
|
| 20 |
|
| 21 |
from dotenv import load_dotenv
|
| 22 |
import os
|
|
|
|
| 45 |
error_icon, error_box = reset_error_box(error_icon, error_box)
|
| 46 |
# data = get_json_one_individual() # TODO: This should change
|
| 47 |
data["identifier"] = str(uuid.uuid4())
|
| 48 |
+
data["image_md5"] = generate_random_md5()
|
| 49 |
img, geolocalisation, specie, number, comments = field_checker(data)
|
| 50 |
|
| 51 |
error_behavior = None
|
|
|
|
| 83 |
dead_state=data["dead_state"],
|
| 84 |
)
|
| 85 |
except ValidationError as e:
|
|
|
|
|
|
|
| 86 |
error_individual = e
|
| 87 |
|
| 88 |
elif data["dead_state"] == "Yes":
|
|
|
|
| 104 |
),
|
| 105 |
)
|
| 106 |
except ValidationError as e:
|
|
|
|
|
|
|
| 107 |
error_individual = e
|
| 108 |
else:
|
| 109 |
try:
|
|
|
|
| 119 |
dead_state=data["dead_state"],
|
| 120 |
)
|
| 121 |
except ValidationError as e:
|
|
|
|
| 122 |
error_individual = e
|
| 123 |
if (
|
| 124 |
error_behavior
|
|
|
|
| 182 |
return error_box
|
| 183 |
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
#### VALIDATION FUNCTIONS
|
| 186 |
def validate_circumstance(data):
|
| 187 |
circumstance_raw = get_fields(data, "circumstance")
|
|
|
|
| 192 |
error = None
|
| 193 |
except ValidationError as e:
|
| 194 |
error = e
|
|
|
|
| 195 |
circumstances = None
|
| 196 |
return circumstances, error
|
| 197 |
|
|
|
|
| 208 |
behavior = Behaviors(**behaviors_formatted)
|
| 209 |
error = None
|
| 210 |
except ValidationError as e:
|
|
|
|
| 211 |
behavior = None
|
| 212 |
error = e
|
| 213 |
return behavior, error
|
|
|
|
| 216 |
def validate_physical(data, mode):
|
| 217 |
physical_raw = get_fields(data, "physical")
|
| 218 |
physical_formatted = process_physical(physical_raw)
|
|
|
|
| 219 |
try:
|
| 220 |
if mode == "simple":
|
| 221 |
PhysicalAnomaliesSimple.model_validate(physical_formatted)
|
|
|
|
| 225 |
physical = PhysicalAnomalies(**physical_formatted)
|
| 226 |
error = None
|
| 227 |
except ValidationError as e:
|
|
|
|
| 228 |
physical = None
|
| 229 |
error = e
|
| 230 |
return physical, error
|
|
|
|
| 238 |
followup = FollowUpEvents(**followup_formatted)
|
| 239 |
error = None
|
| 240 |
except ValidationError as e:
|
|
|
|
|
|
|
| 241 |
followup = None
|
| 242 |
return followup, error
|
test.py
DELETED
|
@@ -1,10 +0,0 @@
|
|
| 1 |
-
# app.py
|
| 2 |
-
import gradio as gr
|
| 3 |
-
|
| 4 |
-
def greet(name):
|
| 5 |
-
return f"Hello, {name}!"
|
| 6 |
-
|
| 7 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 8 |
-
|
| 9 |
-
if __name__ == "__main__":
|
| 10 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|