rmm commited on
Commit
60a7864
·
1 Parent(s): 18a41f5

doc: added docstrings to new functions

Browse files
src/classifier/classifier_image.py CHANGED
@@ -21,8 +21,20 @@ def add_classifier_header() -> None:
21
  Once inference is complete, the top three predictions are shown.
22
  You can override the prediction by selecting a species from the dropdown.*""")
23
 
 
24
  # func to just run classification, store results.
25
  def cetacean_just_classify(cetacean_classifier):
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  images = st.session_state.images
28
  #observations = st.session_state.observations
@@ -44,7 +56,18 @@ def cetacean_just_classify(cetacean_classifier):
44
 
45
 
46
  # func to show results and allow review
47
- def cetacean_show_results_and_review():
 
 
 
 
 
 
 
 
 
 
 
48
  images = st.session_state.images
49
  observations = st.session_state.observations
50
  hashes = st.session_state.image_hashes
@@ -105,6 +128,14 @@ def cetacean_show_results_and_review():
105
 
106
  # func to just present results
107
  def cetacean_show_results():
 
 
 
 
 
 
 
 
108
  images = st.session_state.images
109
  observations = st.session_state.observations
110
  hashes = st.session_state.image_hashes
 
21
  Once inference is complete, the top three predictions are shown.
22
  You can override the prediction by selecting a species from the dropdown.*""")
23
 
24
+
25
  # func to just run classification, store results.
26
  def cetacean_just_classify(cetacean_classifier):
27
+ """
28
+ Infer cetacean species for all observations in the session state.
29
+
30
+ - this function runs the classifier, and stores results in the session state.
31
+ - the top 3 predictions are stored in the observation object, which is retained
32
+ in st.session_state.observations
33
+ - to display results use cetacean_show_results() or cetacean_show_results_and_review()
34
+
35
+ Args:
36
+ cetacean_classifier ([type]): saving-willy model from Saving Willy Hugging Face space
37
+ """
38
 
39
  images = st.session_state.images
40
  #observations = st.session_state.observations
 
56
 
57
 
58
  # func to show results and allow review
59
+ def cetacean_show_results_and_review() -> None:
60
+ """
61
+ Present classification results and allow user to review and override the prediction.
62
+
63
+ - for each observation in the session state, displays the image, summarised
64
+ metadata, and the top 3 predictions.
65
+ - allows user to override the prediction by selecting a species from the dropdown.
66
+ - the selected species is stored in the observation object, which is retained in
67
+ st.session_state.observations
68
+
69
+ """
70
+
71
  images = st.session_state.images
72
  observations = st.session_state.observations
73
  hashes = st.session_state.image_hashes
 
128
 
129
  # func to just present results
130
  def cetacean_show_results():
131
+ """
132
+ Present classification results that may be pushed to the online dataset.
133
+
134
+ - for each observation in the session state, displays the image, summarised
135
+ metadata, the top 3 predictions, and the selected species (which may have
136
+ been manually selected, or the top prediction accepted).
137
+
138
+ """
139
  images = st.session_state.images
140
  observations = st.session_state.observations
141
  hashes = st.session_state.image_hashes
src/input/input_validator.py CHANGED
@@ -10,13 +10,24 @@ from PIL import ExifTags
10
 
11
  from streamlit.runtime.uploaded_file_manager import UploadedFile
12
 
13
- def generate_random_md5():
 
 
 
 
 
 
 
 
 
 
14
  # Generate a random string
15
- random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=16))
16
  # Encode the string and compute its MD5 hash
17
  md5_hash = hashlib.md5(random_string.encode()).hexdigest()
18
  return md5_hash
19
 
 
20
  def is_valid_number(number:str) -> bool:
21
  """
22
  Check if the given string is a valid number (int or float, sign ok)
@@ -30,6 +41,7 @@ def is_valid_number(number:str) -> bool:
30
  pattern = r'^[-+]?[0-9]*\.?[0-9]+$'
31
  return re.match(pattern, number) is not None
32
 
 
33
  # Function to validate email address
34
  def is_valid_email(email:str) -> bool:
35
  """
@@ -46,6 +58,7 @@ def is_valid_email(email:str) -> bool:
46
  pattern = r'^[a-zA-Z0-9_]+[a-zA-Z0-9._%+-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
47
  return re.match(pattern, email) is not None
48
 
 
49
  # Function to extract date and time from image metadata
50
  def get_image_datetime(image_file:UploadedFile) -> str | None:
51
  """
@@ -71,6 +84,7 @@ def get_image_datetime(image_file:UploadedFile) -> str | None:
71
  # TODO: add to logger
72
  return None
73
 
 
74
  def decimal_coords(coords:tuple, ref:str) -> Fraction:
75
  """
76
  Converts coordinates from degrees, minutes, and seconds to decimal degrees.
 
10
 
11
  from streamlit.runtime.uploaded_file_manager import UploadedFile
12
 
13
+ def generate_random_md5(length:int=16) -> str:
14
+ """
15
+ Generate a random MD5 hash.
16
+
17
+ Args:
18
+ length (int): The length of the random string to generate. Default is 16.
19
+
20
+ Returns:
21
+ str: The MD5 hash of the generated random string.
22
+ """
23
+
24
  # Generate a random string
25
+ random_string = ''.join(random.choices(string.ascii_letters + string.digits, length=16))
26
  # Encode the string and compute its MD5 hash
27
  md5_hash = hashlib.md5(random_string.encode()).hexdigest()
28
  return md5_hash
29
 
30
+
31
  def is_valid_number(number:str) -> bool:
32
  """
33
  Check if the given string is a valid number (int or float, sign ok)
 
41
  pattern = r'^[-+]?[0-9]*\.?[0-9]+$'
42
  return re.match(pattern, number) is not None
43
 
44
+
45
  # Function to validate email address
46
  def is_valid_email(email:str) -> bool:
47
  """
 
58
  pattern = r'^[a-zA-Z0-9_]+[a-zA-Z0-9._%+-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
59
  return re.match(pattern, email) is not None
60
 
61
+
62
  # Function to extract date and time from image metadata
63
  def get_image_datetime(image_file:UploadedFile) -> str | None:
64
  """
 
84
  # TODO: add to logger
85
  return None
86
 
87
+
88
  def decimal_coords(coords:tuple, ref:str) -> Fraction:
89
  """
90
  Converts coordinates from degrees, minutes, and seconds to decimal degrees.