rmm commited on
Commit
c3a2524
·
1 Parent(s): f3eb9f5

docs: main entry point docstrings and minor refactor

Browse files
Files changed (3) hide show
  1. call_models/entry_and_hotdog.py +41 -3
  2. docs/main.md +7 -1
  3. mkdocs.yaml +10 -6
call_models/entry_and_hotdog.py CHANGED
@@ -6,6 +6,7 @@ import tempfile
6
 
7
  import pandas as pd
8
  import streamlit as st
 
9
  import folium
10
  from streamlit_folium import st_folium
11
  from huggingface_hub import HfApi
@@ -63,14 +64,29 @@ if "tab_log" not in st.session_state:
63
  st.session_state.tab_log = None
64
 
65
 
66
- def metadata2md():
 
 
 
 
 
 
67
  markdown_str = "\n"
68
  for key, value in st.session_state.full_data.items():
69
  markdown_str += f"- **{key}**: {value}\n"
70
  return markdown_str
71
 
72
 
73
- def push_observation(tab_log=None):
 
 
 
 
 
 
 
 
 
74
  # we get the data from session state: 1 is the dict 2 is the image.
75
  # first, lets do an info display (popup)
76
  metadata_str = json.dumps(st.session_state.full_data)
@@ -104,7 +120,26 @@ def push_observation(tab_log=None):
104
  st.info(msg)
105
 
106
 
107
- if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
  g_logger.info("App started.")
110
  g_logger.warning(f"[D] Streamlit version: {st.__version__}. Python version: {os.sys.version}")
@@ -305,3 +340,6 @@ if __name__ == "__main__":
305
  tab_hotdogs.write(f"Session Data: {json.dumps(st.session_state.full_data)}")
306
 
307
 
 
 
 
 
6
 
7
  import pandas as pd
8
  import streamlit as st
9
+ from streamlit.delta_generator import DeltaGenerator # for type hinting
10
  import folium
11
  from streamlit_folium import st_folium
12
  from huggingface_hub import HfApi
 
64
  st.session_state.tab_log = None
65
 
66
 
67
+ def metadata2md() -> str:
68
+ """Get metadata from cache and return as markdown-formatted key-value list
69
+
70
+ Returns:
71
+ str: Markdown-formatted key-value list of metadata
72
+
73
+ """
74
  markdown_str = "\n"
75
  for key, value in st.session_state.full_data.items():
76
  markdown_str += f"- **{key}**: {value}\n"
77
  return markdown_str
78
 
79
 
80
+ def push_observation(tab_log:DeltaGenerator=None):
81
+ """
82
+ Push the observation to the Hugging Face dataset
83
+
84
+ Args:
85
+ tab_log (streamlit.container): The container to log messages to. If not provided,
86
+ log messages are in any case written to the global logger (TODO: test - didn't
87
+ push any data since generating the logger)
88
+
89
+ """
90
  # we get the data from session state: 1 is the dict 2 is the image.
91
  # first, lets do an info display (popup)
92
  metadata_str = json.dumps(st.session_state.full_data)
 
120
  st.info(msg)
121
 
122
 
123
+
124
+ def main() -> None:
125
+ """
126
+ Main entry point to set up the streamlit UI and run the application.
127
+
128
+ The organisation is as follows:
129
+
130
+ 1. data input (a new observation) is handled in the sidebar
131
+ 2. the rest of the interface is organised in tabs:
132
+
133
+ - cetean classifier
134
+ - hotdog classifier
135
+ - map to present the obersvations
136
+ - table of recent log entries
137
+ - gallery of whale images
138
+
139
+ The majority of the tabs are instantiated from modules. Currently the two
140
+ classifiers are still in-line here.
141
+
142
+ """
143
 
144
  g_logger.info("App started.")
145
  g_logger.warning(f"[D] Streamlit version: {st.__version__}. Python version: {os.sys.version}")
 
340
  tab_hotdogs.write(f"Session Data: {json.dumps(st.session_state.full_data)}")
341
 
342
 
343
+
344
+ if __name__ == "__main__":
345
+ main()
docs/main.md CHANGED
@@ -1,4 +1,10 @@
 
 
 
 
 
 
 
1
 
2
- # Main entry point to the frontend
3
 
4
  ::: call_models.entry_and_hotdog
 
1
+ # Main entry point
2
+
3
+ This module sets up the streamlit UI frontend,
4
+ as well as logger and session state elements in the backend.
5
+
6
+ The session state is used to retain values from one interaction to the next, since the streamlit execution model is to re-run the entire script top-to-bottom upon each user interaction (e.g. click).
7
+ See streamlit [docs](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.session_state).
8
 
 
9
 
10
  ::: call_models.entry_and_hotdog
mkdocs.yaml CHANGED
@@ -22,14 +22,18 @@ plugins:
22
 
23
  nav:
24
  - README: index.md
 
 
 
25
  - API:
26
  - Main app: main.md
27
- - Data entry handling: input_handling.md
28
- - Map of observations: obs_map.md
29
- - Whale gallery: whale_gallery.md
30
- - Whale viewer: whale_viewer.md
31
- - Logging: st_logs.md
32
- - Tab-rendering fix (js): fix_tabrender.md
 
33
 
34
 
35
 
 
22
 
23
  nav:
24
  - README: index.md
25
+ #- Quickstart:
26
+ #- Installation: installation.md
27
+ #- Usage: usage.md
28
  - API:
29
  - Main app: main.md
30
+ - Modules:
31
+ - Data entry handling: input_handling.md
32
+ - Map of observations: obs_map.md
33
+ - Whale gallery: whale_gallery.md
34
+ - Whale viewer: whale_viewer.md
35
+ - Logging: st_logs.md
36
+ - Tab-rendering fix (js): fix_tabrender.md
37
 
38
 
39