fix: geolocalisation specie number and comments save to report
Browse files
app/classes.py
CHANGED
@@ -48,6 +48,9 @@ class Report(BaseModel):
|
|
48 |
image: ImageBase64
|
49 |
image_md5: str
|
50 |
geolocalisation: Geolocalisation
|
|
|
|
|
|
|
51 |
wounded_state: str
|
52 |
wounded: Optional[Wounded] = None
|
53 |
dead_state: str
|
|
|
48 |
image: ImageBase64
|
49 |
image_md5: str
|
50 |
geolocalisation: Geolocalisation
|
51 |
+
specie: Optional[str]
|
52 |
+
number: Optional[int]
|
53 |
+
comments: Optional[str]
|
54 |
wounded_state: str
|
55 |
wounded: Optional[Wounded] = None
|
56 |
dead_state: str
|
app/geolocalisation/class_geolocalisation.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from pydantic import BaseModel, Field
|
2 |
-
from typing import Literal, List, Union
|
3 |
|
4 |
class Longitude(BaseModel):
|
5 |
type: Literal['longitude']
|
@@ -12,5 +12,5 @@ class Latitude(BaseModel):
|
|
12 |
class Geolocalisation(BaseModel):
|
13 |
longitude: Longitude
|
14 |
latitude: Latitude
|
15 |
-
name: str
|
16 |
|
|
|
1 |
from pydantic import BaseModel, Field
|
2 |
+
from typing import Literal, List, Union, Optional
|
3 |
|
4 |
class Longitude(BaseModel):
|
5 |
type: Literal['longitude']
|
|
|
12 |
class Geolocalisation(BaseModel):
|
13 |
longitude: Longitude
|
14 |
latitude: Latitude
|
15 |
+
name: Optional[str]
|
16 |
|
app/geolocalisation/js_geolocation.py
CHANGED
@@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
|
|
1 |
# JavaScript code to get location and update hidden_input
|
2 |
js_geocode = """
|
3 |
function() {
|
@@ -31,5 +35,20 @@ js_geocode = """
|
|
31 |
}
|
32 |
"""
|
33 |
|
34 |
-
def display_location(location_json):
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import json
|
3 |
+
from geolocalisation.maps import create_geolocalisation_object, save_geolocalisation_to_json
|
4 |
+
|
5 |
# JavaScript code to get location and update hidden_input
|
6 |
js_geocode = """
|
7 |
function() {
|
|
|
35 |
}
|
36 |
"""
|
37 |
|
38 |
+
def display_location(location_json, individual):
|
39 |
+
geo_dict = json.loads(location_json)
|
40 |
+
print(geo_dict)
|
41 |
+
print(geo_dict["error"])
|
42 |
+
latitude = geo_dict["latitude"]
|
43 |
+
longitude = geo_dict["longitude"]
|
44 |
+
geolocalisation = create_geolocalisation_object(latitude, longitude, "NA")
|
45 |
+
individual = save_geolocalisation_to_json(geolocalisation, individual)
|
46 |
+
locationtext = gr.Textbox(
|
47 |
+
f"Latitude: {latitude} | Longitude: {longitude}",
|
48 |
+
visible=True,
|
49 |
+
show_label=False,
|
50 |
+
interactive=False)
|
51 |
+
return locationtext, individual
|
52 |
+
|
53 |
+
# def display_location(location_json):
|
54 |
+
# return location_json
|
app/mode_advanced.py
CHANGED
@@ -12,12 +12,14 @@ from physical.physical_select_animal import show_physical, find_bounding_box
|
|
12 |
from physical.physical_checkbox import on_select_body_part, hide_physical
|
13 |
from behavior.behavior_checkbox import show_behavior, on_select_behavior
|
14 |
from follow_up.followup_events import save_fe
|
|
|
15 |
from validation_submission.utils_individual import generate_random_md5
|
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 reset_individual
|
20 |
-
from
|
|
|
21 |
|
22 |
from dotenv import load_dotenv
|
23 |
import os
|
@@ -45,9 +47,6 @@ with gr.Blocks(theme='shivi/calm_seafoam') as advanced:
|
|
45 |
# ---------------------------------------------------------
|
46 |
# Camera
|
47 |
with gr.Row():
|
48 |
-
def save_image(camera, individual):
|
49 |
-
individual = add_data_to_individual("image", camera.tolist(), individual)
|
50 |
-
return individual
|
51 |
camera = gr.Image(elem_id="image")
|
52 |
camera.input(save_image, inputs=[camera, individual], outputs=[individual])
|
53 |
|
@@ -64,6 +63,10 @@ with gr.Blocks(theme='shivi/calm_seafoam') as advanced:
|
|
64 |
visible=True,
|
65 |
interactive=True
|
66 |
)
|
|
|
|
|
|
|
|
|
67 |
|
68 |
# Number of individuals
|
69 |
with gr.Row():
|
@@ -77,6 +80,10 @@ with gr.Blocks(theme='shivi/calm_seafoam') as advanced:
|
|
77 |
visible=True,
|
78 |
interactive=True
|
79 |
)
|
|
|
|
|
|
|
|
|
80 |
|
81 |
# Introducing text_box for comments
|
82 |
with gr.Row():
|
@@ -89,6 +96,10 @@ with gr.Blocks(theme='shivi/calm_seafoam') as advanced:
|
|
89 |
visible=True,
|
90 |
interactive=True
|
91 |
)
|
|
|
|
|
|
|
|
|
92 |
|
93 |
# ---------------------------------------------------------
|
94 |
# Location
|
@@ -114,12 +125,15 @@ with gr.Blocks(theme='shivi/calm_seafoam') as advanced:
|
|
114 |
|
115 |
with gr.Column(scale=1):
|
116 |
# Geolocation
|
117 |
-
gr.
|
118 |
-
location_data = gr.JSON(label="Identified GPS Location")
|
119 |
hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")
|
|
|
120 |
btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required)")
|
121 |
btn_gpslocation.click(None, [], [], js=js_geocode)
|
122 |
-
hidden_input.change(display_location,
|
|
|
|
|
123 |
|
124 |
# ---------------------------------------------------------
|
125 |
# Dead and Wounded Buttons
|
|
|
12 |
from physical.physical_checkbox import on_select_body_part, hide_physical
|
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
|
|
|
47 |
# ---------------------------------------------------------
|
48 |
# Camera
|
49 |
with gr.Row():
|
|
|
|
|
|
|
50 |
camera = gr.Image(elem_id="image")
|
51 |
camera.input(save_image, inputs=[camera, individual], outputs=[individual])
|
52 |
|
|
|
63 |
visible=True,
|
64 |
interactive=True
|
65 |
)
|
66 |
+
specie.change(save_details,
|
67 |
+
inputs=[gr.Textbox("specie", visible=False),
|
68 |
+
specie],
|
69 |
+
outputs=individual)
|
70 |
|
71 |
# Number of individuals
|
72 |
with gr.Row():
|
|
|
80 |
visible=True,
|
81 |
interactive=True
|
82 |
)
|
83 |
+
num_individuals.change(save_details,
|
84 |
+
inputs=[gr.Textbox("number", visible=False),
|
85 |
+
num_individuals],
|
86 |
+
outputs=individual)
|
87 |
|
88 |
# Introducing text_box for comments
|
89 |
with gr.Row():
|
|
|
96 |
visible=True,
|
97 |
interactive=True
|
98 |
)
|
99 |
+
comments.change(save_details,
|
100 |
+
inputs=[gr.Textbox("comments", visible=False),
|
101 |
+
comments],
|
102 |
+
outputs=individual)
|
103 |
|
104 |
# ---------------------------------------------------------
|
105 |
# Location
|
|
|
125 |
|
126 |
with gr.Column(scale=1):
|
127 |
# Geolocation
|
128 |
+
gr.Button("Location", icon=PATH_ICONS+"pin.png", variant="primary")
|
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],
|
136 |
+
outputs=[locationtext, individual])
|
137 |
|
138 |
# ---------------------------------------------------------
|
139 |
# Dead and Wounded Buttons
|
app/mode_simple.py
CHANGED
@@ -17,6 +17,7 @@ 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 |
|
21 |
from dotenv import load_dotenv
|
22 |
import os
|
@@ -44,9 +45,6 @@ with gr.Blocks(theme='shivi/calm_seafoam') as simple:
|
|
44 |
# ---------------------------------------------------------
|
45 |
# Camera
|
46 |
with gr.Row():
|
47 |
-
def save_image(camera, individual):
|
48 |
-
individual = add_data_to_individual("image", camera.tolist(), individual)
|
49 |
-
return individual
|
50 |
camera = gr.Image(elem_id="image")
|
51 |
camera.input(save_image, inputs=[camera, individual], outputs=[individual])
|
52 |
|
@@ -63,6 +61,10 @@ with gr.Blocks(theme='shivi/calm_seafoam') as simple:
|
|
63 |
visible=True,
|
64 |
interactive=True
|
65 |
)
|
|
|
|
|
|
|
|
|
66 |
|
67 |
# Number of individuals
|
68 |
with gr.Row():
|
@@ -76,6 +78,10 @@ with gr.Blocks(theme='shivi/calm_seafoam') as simple:
|
|
76 |
visible=True,
|
77 |
interactive=True
|
78 |
)
|
|
|
|
|
|
|
|
|
79 |
|
80 |
# Introducing text_box for comments
|
81 |
with gr.Row():
|
@@ -88,16 +94,23 @@ with gr.Blocks(theme='shivi/calm_seafoam') as simple:
|
|
88 |
visible=True,
|
89 |
interactive=True
|
90 |
)
|
|
|
|
|
|
|
|
|
91 |
|
92 |
with gr.Row():
|
93 |
with gr.Column(scale=1):
|
94 |
# Geolocation
|
95 |
gr.Button("Location", icon=PATH_ICONS+"pin.png", variant="primary")
|
96 |
-
location_data = gr.JSON(label="Identified GPS Location")
|
97 |
hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")
|
|
|
98 |
btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required)")
|
99 |
btn_gpslocation.click(None, [], [], js=js_geocode)
|
100 |
-
hidden_input.change(display_location,
|
|
|
|
|
101 |
|
102 |
# ---------------------------------------------------------
|
103 |
# Dead and Wounded Buttons
|
|
|
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
|
|
|
45 |
# ---------------------------------------------------------
|
46 |
# Camera
|
47 |
with gr.Row():
|
|
|
|
|
|
|
48 |
camera = gr.Image(elem_id="image")
|
49 |
camera.input(save_image, inputs=[camera, individual], outputs=[individual])
|
50 |
|
|
|
61 |
visible=True,
|
62 |
interactive=True
|
63 |
)
|
64 |
+
specie.change(save_details,
|
65 |
+
inputs=[gr.Textbox("specie", visible=False),
|
66 |
+
specie],
|
67 |
+
outputs=individual)
|
68 |
|
69 |
# Number of individuals
|
70 |
with gr.Row():
|
|
|
78 |
visible=True,
|
79 |
interactive=True
|
80 |
)
|
81 |
+
num_individuals.change(save_details,
|
82 |
+
inputs=[gr.Textbox("number", visible=False),
|
83 |
+
num_individuals],
|
84 |
+
outputs=individual)
|
85 |
|
86 |
# Introducing text_box for comments
|
87 |
with gr.Row():
|
|
|
94 |
visible=True,
|
95 |
interactive=True
|
96 |
)
|
97 |
+
comments.change(save_details,
|
98 |
+
inputs=[gr.Textbox("comments", visible=False),
|
99 |
+
comments],
|
100 |
+
outputs=individual)
|
101 |
|
102 |
with gr.Row():
|
103 |
with gr.Column(scale=1):
|
104 |
# Geolocation
|
105 |
gr.Button("Location", icon=PATH_ICONS+"pin.png", variant="primary")
|
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],
|
113 |
+
outputs=[locationtext, individual])
|
114 |
|
115 |
# ---------------------------------------------------------
|
116 |
# Dead and Wounded Buttons
|
app/validation_submission/utils_save.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from validation_submission.utils_individual import add_data_to_individual
|
2 |
+
|
3 |
+
def save_details(tag, data, individual):
|
4 |
+
individual = add_data_to_individual(tag, data, individual)
|
5 |
+
return individual
|
6 |
+
|
7 |
+
def save_image(camera, individual):
|
8 |
+
individual = add_data_to_individual("image", camera.tolist(), individual)
|
9 |
+
return individual
|
app/validation_submission/validation.py
CHANGED
@@ -2,7 +2,6 @@ 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 behavior.class_behavior_simple import BehaviorsSimple
|
@@ -32,19 +31,19 @@ def get_fields(data_dict, keyword):
|
|
32 |
extract[key] = val
|
33 |
return extract
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
def validate_individual(data, error_icon, error_box, mode: str):
|
37 |
error_icon, error_box = reset_error_box(error_icon, error_box)
|
38 |
# data = get_json_one_individual() # TODO: This should change
|
39 |
data["identifier"] = str(uuid.uuid4())
|
40 |
-
|
41 |
-
img = ImageBase64.to_base64(data["image"])
|
42 |
-
else:
|
43 |
-
img = None
|
44 |
-
if "geolocalisation" in data.keys():
|
45 |
-
geolocalisation = data["geolocalisation"]
|
46 |
-
else:
|
47 |
-
geolocalisation = None
|
48 |
|
49 |
error_behavior = None
|
50 |
error_circumstance = None
|
@@ -68,6 +67,9 @@ def validate_individual(data, error_icon, error_box, mode: str):
|
|
68 |
image=img,
|
69 |
image_md5=data["image_md5"],
|
70 |
geolocalisation=geolocalisation,
|
|
|
|
|
|
|
71 |
wounded_state=data["wounded_state"],
|
72 |
wounded=Wounded(
|
73 |
circumstances=circumstance,
|
@@ -89,6 +91,9 @@ def validate_individual(data, error_icon, error_box, mode: str):
|
|
89 |
image=img,
|
90 |
image_md5=data["image_md5"],
|
91 |
geolocalisation=geolocalisation,
|
|
|
|
|
|
|
92 |
wounded_state=data["wounded_state"],
|
93 |
dead_state=data["dead_state"],
|
94 |
dead=Dead(
|
@@ -108,6 +113,9 @@ def validate_individual(data, error_icon, error_box, mode: str):
|
|
108 |
image=img,
|
109 |
image_md5=data["image_md5"],
|
110 |
geolocalisation=geolocalisation,
|
|
|
|
|
|
|
111 |
wounded_state=data["wounded_state"],
|
112 |
dead_state=data["dead_state"],
|
113 |
)
|
|
|
2 |
from pydantic import ValidationError
|
3 |
import gradio as gr
|
4 |
|
|
|
5 |
from circumstances.class_circumstance import Circumstances
|
6 |
from behavior.class_behavior import Behaviors
|
7 |
from behavior.class_behavior_simple import BehaviorsSimple
|
|
|
31 |
extract[key] = val
|
32 |
return extract
|
33 |
|
34 |
+
def field_checker(data):
|
35 |
+
img = ImageBase64.to_base64(data["image"]) if "image" in data.keys() else None
|
36 |
+
geolocalisation = data["geolocalisation"] if "geolocalisation" in data.keys() else None
|
37 |
+
specie = data["specie"] if "specie" in data.keys() else "NA"
|
38 |
+
number = data["number"] if "specie" in data.keys() else 1
|
39 |
+
comments = data["comments"] if "specie" in data.keys() else "NA"
|
40 |
+
return img, geolocalisation, specie, number, comments
|
41 |
|
42 |
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
|
49 |
error_circumstance = None
|
|
|
67 |
image=img,
|
68 |
image_md5=data["image_md5"],
|
69 |
geolocalisation=geolocalisation,
|
70 |
+
specie=specie,
|
71 |
+
number=number,
|
72 |
+
comments=comments,
|
73 |
wounded_state=data["wounded_state"],
|
74 |
wounded=Wounded(
|
75 |
circumstances=circumstance,
|
|
|
91 |
image=img,
|
92 |
image_md5=data["image_md5"],
|
93 |
geolocalisation=geolocalisation,
|
94 |
+
specie=specie,
|
95 |
+
number=number,
|
96 |
+
comments=comments,
|
97 |
wounded_state=data["wounded_state"],
|
98 |
dead_state=data["dead_state"],
|
99 |
dead=Dead(
|
|
|
113 |
image=img,
|
114 |
image_md5=data["image_md5"],
|
115 |
geolocalisation=geolocalisation,
|
116 |
+
specie=specie,
|
117 |
+
number=number,
|
118 |
+
comments=comments,
|
119 |
wounded_state=data["wounded_state"],
|
120 |
dead_state=data["dead_state"],
|
121 |
)
|