rmm commited on
Commit
a5ced3e
·
1 Parent(s): 4d650d5

chore: cleanup variable names and add docstrings

Browse files
src/input/input_handling.py CHANGED
@@ -393,7 +393,7 @@ def add_input_UI_elements() -> None:
393
  st.session_state.container_metadata_inputs = container_metadata_inputs
394
 
395
 
396
- def dbg_show_observation_hashes():
397
  """
398
  Displays information about each observation including the hash
399
 
 
393
  st.session_state.container_metadata_inputs = container_metadata_inputs
394
 
395
 
396
+ def dbg_show_observation_hashes() -> None:
397
  """
398
  Displays information about each observation including the hash
399
 
src/main.py CHANGED
@@ -24,7 +24,7 @@ from maps.alps_map import present_alps_map
24
  from maps.obs_map import present_obs_map
25
  from utils.st_logs import setup_logging, parse_log_buffer
26
  from utils.workflow_state import WorkflowFSM, FSM_STATES
27
- from utils.workflow_ui import refresh_progress, init_workflow_viz
28
  from hf_push_observations import push_all_observations
29
 
30
  from classifier.classifier_image import cetacean_just_classify, cetacean_show_results_and_review, cetacean_show_results
@@ -117,7 +117,7 @@ def main() -> None:
117
  st.session_state.tab_log = tab_log
118
 
119
  # put this early so the progress indicator is at the top (also refreshed at end)
120
- refresh_progress()
121
 
122
  # create a sidebar, and parse all the input (returned as `observations` object)
123
  with st.sidebar:
@@ -265,7 +265,7 @@ def main() -> None:
265
  # trigger a refresh too (refreshhing the prog indicator means the script reruns and
266
  # we can enter the next state - visualising the results / review)
267
  # ok it doesn't if done programmatically. maybe interacting with teh button? check docs.
268
- refresh_progress()
269
  #TODO: validate this doesn't harm performance adversely.
270
  st.rerun()
271
 
@@ -373,7 +373,7 @@ def main() -> None:
373
 
374
 
375
  # after all other processing, we can show the stage/state
376
- refresh_progress()
377
 
378
 
379
  if __name__ == "__main__":
 
24
  from maps.obs_map import present_obs_map
25
  from utils.st_logs import setup_logging, parse_log_buffer
26
  from utils.workflow_state import WorkflowFSM, FSM_STATES
27
+ from utils.workflow_ui import refresh_progress_display, init_workflow_viz
28
  from hf_push_observations import push_all_observations
29
 
30
  from classifier.classifier_image import cetacean_just_classify, cetacean_show_results_and_review, cetacean_show_results
 
117
  st.session_state.tab_log = tab_log
118
 
119
  # put this early so the progress indicator is at the top (also refreshed at end)
120
+ refresh_progress_display()
121
 
122
  # create a sidebar, and parse all the input (returned as `observations` object)
123
  with st.sidebar:
 
265
  # trigger a refresh too (refreshhing the prog indicator means the script reruns and
266
  # we can enter the next state - visualising the results / review)
267
  # ok it doesn't if done programmatically. maybe interacting with teh button? check docs.
268
+ refresh_progress_display()
269
  #TODO: validate this doesn't harm performance adversely.
270
  st.rerun()
271
 
 
373
 
374
 
375
  # after all other processing, we can show the stage/state
376
+ refresh_progress_display()
377
 
378
 
379
  if __name__ == "__main__":
src/utils/workflow_ui.py CHANGED
@@ -1,18 +1,41 @@
1
  import streamlit as st
2
 
3
- def refresh_progress():
 
 
 
4
  with st.sidebar:
5
- tot = st.session_state.workflow_fsm.num_states - 1
6
- cur_i = st.session_state.workflow_fsm.current_state_index
7
- cur_t = st.session_state.workflow_fsm.current_state
8
- st.session_state.disp_progress[0].markdown(f"*Progress: {cur_i}/{tot}. Current: {cur_t}.*")
9
- st.session_state.disp_progress[1].progress(cur_i/tot)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- def init_workflow_viz():
12
  # add progress indicator to session_state
13
  if "progress" not in st.session_state:
14
  with st.sidebar:
15
  st.session_state.disp_progress = [st.empty(), st.empty()]
16
- # add button to sidebar, with the callback to refesh_progress
17
- st.sidebar.button("Refresh Progress", on_click=refresh_progress)
 
18
 
 
1
  import streamlit as st
2
 
3
+ def refresh_progress_display() -> None:
4
+ """
5
+ Updates the workflow progress display in the Streamlit sidebar.
6
+ """
7
  with st.sidebar:
8
+ num_states = st.session_state.workflow_fsm.num_states - 1
9
+ current_state_index = st.session_state.workflow_fsm.current_state_index
10
+ current_state_name = st.session_state.workflow_fsm.current_state
11
+ colour = 'primary'
12
+ if current_state_index == num_states: # highlight that we finished
13
+ colour = 'green'
14
+ status = f":{colour}[*Progress: {current_state_index}/{num_states}. Current: {current_state_name}.*]"
15
+
16
+ st.session_state.disp_progress[0].markdown(status)
17
+ st.session_state.disp_progress[1].progress(current_state_index/num_states)
18
+
19
+
20
+ def init_workflow_viz(debug:bool=True) -> None:
21
+ """
22
+ Set up the streamlit elements for visualising the workflow progress.
23
+
24
+ Adds placeholders for progress indicators, and adds a button to manually refresh
25
+ the displayed progress. Note: The button is mainly a development aid.
26
+
27
+ Args:
28
+ debug (bool): If True, include the manual refresh button. Default is True.
29
+
30
+ """
31
+
32
 
33
+ #Initialise the layout containers used in the input handling
34
  # add progress indicator to session_state
35
  if "progress" not in st.session_state:
36
  with st.sidebar:
37
  st.session_state.disp_progress = [st.empty(), st.empty()]
38
+ if debug:
39
+ # add button to sidebar, with the callback to refesh_progress
40
+ st.sidebar.button("Refresh Progress", on_click=refresh_progress_display)
41