Spaces:
Sleeping
Sleeping
rmm
commited on
Commit
·
e90cc61
1
Parent(s):
01fa6a9
feat: get coordinates from file, populate input boxes
Browse files- src/input/input_handling.py +13 -3
- src/input/input_validator.py +4 -2
src/input/input_handling.py
CHANGED
@@ -11,7 +11,7 @@ import cv2
|
|
11 |
import numpy as np
|
12 |
|
13 |
from input.input_observation import InputObservation
|
14 |
-
from input.input_validator import get_image_datetime, is_valid_email, is_valid_number
|
15 |
|
16 |
m_logger = logging.getLogger(__name__)
|
17 |
m_logger.setLevel(logging.INFO)
|
@@ -185,6 +185,16 @@ def metadata_inputs_one_file(file:UploadedFile, image_hash:str, dbg_ix:int=0) ->
|
|
185 |
author_email = st.session_state["input_author_email"]
|
186 |
filename = file.name
|
187 |
image_datetime = get_image_datetime(file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
image = st.session_state.images.get(image_hash, None)
|
189 |
# add the UI elements
|
190 |
#viewcontainer.title(f"Metadata for {filename}")
|
@@ -199,7 +209,7 @@ def metadata_inputs_one_file(file:UploadedFile, image_hash:str, dbg_ix:int=0) ->
|
|
199 |
# 3. Latitude Entry Box
|
200 |
latitude = viewcontainer.text_input(
|
201 |
"Latitude for " + filename,
|
202 |
-
|
203 |
key=f"input_latitude_{image_hash}")
|
204 |
if latitude and not is_valid_number(latitude):
|
205 |
viewcontainer.error("Please enter a valid latitude (numerical only).")
|
@@ -207,7 +217,7 @@ def metadata_inputs_one_file(file:UploadedFile, image_hash:str, dbg_ix:int=0) ->
|
|
207 |
# 4. Longitude Entry Box
|
208 |
longitude = viewcontainer.text_input(
|
209 |
"Longitude for " + filename,
|
210 |
-
|
211 |
key=f"input_longitude_{image_hash}")
|
212 |
if longitude and not is_valid_number(longitude):
|
213 |
viewcontainer.error("Please enter a valid longitude (numerical only).")
|
|
|
11 |
import numpy as np
|
12 |
|
13 |
from input.input_observation import InputObservation
|
14 |
+
from input.input_validator import get_image_datetime, is_valid_email, is_valid_number, get_image_latlon
|
15 |
|
16 |
m_logger = logging.getLogger(__name__)
|
17 |
m_logger.setLevel(logging.INFO)
|
|
|
185 |
author_email = st.session_state["input_author_email"]
|
186 |
filename = file.name
|
187 |
image_datetime = get_image_datetime(file)
|
188 |
+
latitude0, longitude0 = get_image_latlon(file)
|
189 |
+
msg = f"[D] {filename}: lat, lon from image metadata: {latitude0}, {longitude0}"
|
190 |
+
m_logger.debug(msg)
|
191 |
+
|
192 |
+
if latitude0 is None:
|
193 |
+
# get it from the default dict
|
194 |
+
latitude0 = spoof_metadata.get('latitude', 0) + dbg_ix
|
195 |
+
if longitude0 is None:
|
196 |
+
longitude0 = spoof_metadata.get('longitude', 0) - dbg_ix
|
197 |
+
|
198 |
image = st.session_state.images.get(image_hash, None)
|
199 |
# add the UI elements
|
200 |
#viewcontainer.title(f"Metadata for {filename}")
|
|
|
209 |
# 3. Latitude Entry Box
|
210 |
latitude = viewcontainer.text_input(
|
211 |
"Latitude for " + filename,
|
212 |
+
latitude0,
|
213 |
key=f"input_latitude_{image_hash}")
|
214 |
if latitude and not is_valid_number(latitude):
|
215 |
viewcontainer.error("Please enter a valid latitude (numerical only).")
|
|
|
217 |
# 4. Longitude Entry Box
|
218 |
longitude = viewcontainer.text_input(
|
219 |
"Longitude for " + filename,
|
220 |
+
longitude0,
|
221 |
key=f"input_longitude_{image_hash}")
|
222 |
if longitude and not is_valid_number(longitude):
|
223 |
viewcontainer.error("Please enter a valid longitude (numerical only).")
|
src/input/input_validator.py
CHANGED
@@ -45,7 +45,7 @@ def is_valid_email(email:str) -> bool:
|
|
45 |
return re.match(pattern, email) is not None
|
46 |
|
47 |
# Function to extract date and time from image metadata
|
48 |
-
def get_image_datetime(image_file):
|
49 |
"""
|
50 |
Extracts the original date and time from the EXIF metadata of an uploaded image file.
|
51 |
|
@@ -123,4 +123,6 @@ def get_image_latlon(image_file: UploadedFile) :
|
|
123 |
return lat, lon
|
124 |
|
125 |
except Exception as e: # FIXME: what types of exception?
|
126 |
-
st.warning(f"Could not extract latitude and longitude from image metadata. (file: {str(image_file)}")
|
|
|
|
|
|
45 |
return re.match(pattern, email) is not None
|
46 |
|
47 |
# Function to extract date and time from image metadata
|
48 |
+
def get_image_datetime(image_file:UploadedFile) -> str | None:
|
49 |
"""
|
50 |
Extracts the original date and time from the EXIF metadata of an uploaded image file.
|
51 |
|
|
|
123 |
return lat, lon
|
124 |
|
125 |
except Exception as e: # FIXME: what types of exception?
|
126 |
+
st.warning(f"Could not extract latitude and longitude from image metadata. (file: {str(image_file)}")
|
127 |
+
|
128 |
+
return None, None
|