rmm commited on
Commit
0e02e00
·
1 Parent(s): beca8fa

fix: public_observations now a dict, for multi-image handling

Browse files

- renamed the session_state variable from singular to plural
- was initialised as a dict, but then overwritten each time, meaning
access was order-dependent and lossy

src/classifier/classifier_image.py CHANGED
@@ -40,7 +40,7 @@ def cetacean_just_classify(cetacean_classifier):
40
  g_logger.info(msg)
41
 
42
  # TODO: what is the difference between public and regular; and why is this not array-ready?
43
- st.session_state.public_observation = observation
44
  st.write(f"*[D] Observation {hash} classified as {st.session_state.whale_prediction1[hash]}*")
45
 
46
 
@@ -78,10 +78,10 @@ def cetacean_show_results_and_review():
78
  if selected_class != st.session_state.whale_prediction1[hash]:
79
  observation['class_overriden'] = selected_class # TODO: this should be boolean!
80
 
81
- st.session_state.public_observation = observation
82
  st.button(f"Upload observation {str(o)} to THE INTERNET!", on_click=push_observations)
83
  # TODO: the metadata only fills properly if `validate` was clicked.
84
- st.markdown(metadata2md())
85
 
86
  msg = f"[D] full observation after inference: {observation}"
87
  g_logger.debug(msg)
@@ -136,7 +136,7 @@ def cetacean_show_results():
136
  # st.session_state.public_observation = observation
137
  st.button(f"Upload observation {str(o)} to THE INTERNET!", on_click=push_observations)
138
  # TODO: the metadata only fills properly if `validate` was clicked.
139
- st.markdown(metadata2md())
140
  st.markdown(f"- **hash**: {hash}")
141
 
142
  msg = f"[D] full observation after inference: {observation}"
@@ -163,6 +163,7 @@ def cetacean_classify_show_and_review(cetacean_classifier):
163
  Args:
164
  cetacean_classifier ([type]): saving-willy model from Saving Willy Hugging Face space
165
  """
 
166
  images = st.session_state.images
167
  observations = st.session_state.observations
168
  hashes = st.session_state.image_hashes
 
40
  g_logger.info(msg)
41
 
42
  # TODO: what is the difference between public and regular; and why is this not array-ready?
43
+ st.session_state.public_observations[hash] = observation
44
  st.write(f"*[D] Observation {hash} classified as {st.session_state.whale_prediction1[hash]}*")
45
 
46
 
 
78
  if selected_class != st.session_state.whale_prediction1[hash]:
79
  observation['class_overriden'] = selected_class # TODO: this should be boolean!
80
 
81
+ st.session_state.public_observations[hash] = observation
82
  st.button(f"Upload observation {str(o)} to THE INTERNET!", on_click=push_observations)
83
  # TODO: the metadata only fills properly if `validate` was clicked.
84
+ st.markdown(metadata2md(hash))
85
 
86
  msg = f"[D] full observation after inference: {observation}"
87
  g_logger.debug(msg)
 
136
  # st.session_state.public_observation = observation
137
  st.button(f"Upload observation {str(o)} to THE INTERNET!", on_click=push_observations)
138
  # TODO: the metadata only fills properly if `validate` was clicked.
139
+ st.markdown(metadata2md(hash))
140
  st.markdown(f"- **hash**: {hash}")
141
 
142
  msg = f"[D] full observation after inference: {observation}"
 
163
  Args:
164
  cetacean_classifier ([type]): saving-willy model from Saving Willy Hugging Face space
165
  """
166
+ raise DeprecationWarning("This function is deprecated. Use individual steps instead")
167
  images = st.session_state.images
168
  observations = st.session_state.observations
169
  hashes = st.session_state.image_hashes
src/main.py CHANGED
@@ -53,8 +53,8 @@ if "handler" not in st.session_state:
53
  st.session_state['handler'] = setup_logging()
54
 
55
 
56
- if "public_observation" not in st.session_state:
57
- st.session_state.public_observation = {}
58
 
59
  if "classify_whale_done" not in st.session_state:
60
  st.session_state.classify_whale_done = {}
 
53
  st.session_state['handler'] = setup_logging()
54
 
55
 
56
+ if "public_observations" not in st.session_state:
57
+ st.session_state.public_observations = {}
58
 
59
  if "classify_whale_done" not in st.session_state:
60
  st.session_state.classify_whale_done = {}
src/utils/metadata_handler.py CHANGED
@@ -1,16 +1,26 @@
1
  import streamlit as st
2
 
3
- def metadata2md() -> str:
4
  """Get metadata from cache and return as markdown-formatted key-value list
5
 
 
 
 
6
  Returns:
7
  str: Markdown-formatted key-value list of metadata
8
 
9
  """
10
  markdown_str = "\n"
11
- keys_to_print = ["latitude","longitude","author_email","date","time"]
12
- for key, value in st.session_state.public_observation.items():
13
- if key in keys_to_print:
14
- markdown_str += f"- **{key}**: {value}\n"
 
 
 
 
 
 
 
15
  return markdown_str
16
 
 
1
  import streamlit as st
2
 
3
+ def metadata2md(image_hash:str) -> str:
4
  """Get metadata from cache and return as markdown-formatted key-value list
5
 
6
+ Args:
7
+ image_hash (str): The hash of the image to get metadata for
8
+
9
  Returns:
10
  str: Markdown-formatted key-value list of metadata
11
 
12
  """
13
  markdown_str = "\n"
14
+ # FIXME get the right keys
15
+ # keys_to_print = ["latitude","longitude","author_email","date","time"]
16
+ keys_to_print = ["latitude","longitude","author_email","date_option","time_option"]
17
+
18
+ observation = st.session_state.public_observations.get(image_hash, {})
19
+
20
+ #for key, value in st.session_state.public_observation.items():
21
+ for key, value in observation.items():
22
+ if key in keys_to_print:
23
+ markdown_str += f"- **{key}**: {value}\n"
24
+
25
  return markdown_str
26