vancauwe commited on
Commit
20526a2
·
unverified ·
2 Parent(s): 8083970 cffe3cc

Merge pull request #22 from sdsc-ordes/chore/docs-complete

Browse files
src/input_handling.py CHANGED
@@ -27,7 +27,16 @@ allowed_image_types = ['jpg', 'jpeg', 'png', 'webp']
27
 
28
  import random
29
  import string
30
- def generate_random_md5():
 
 
 
 
 
 
 
 
 
31
  # Generate a random string
32
  random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=16))
33
  # Encode the string and compute its MD5 hash
 
27
 
28
  import random
29
  import string
30
+ def generate_random_md5() -> str:
31
+ """
32
+ Generates a random MD5 hash.
33
+
34
+ This function creates a random string of 16 alphanumeric characters,
35
+ encodes it, and then computes its MD5 hash.
36
+
37
+ Returns:
38
+ str: The MD5 hash of the generated random string.
39
+ """
40
  # Generate a random string
41
  random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=16))
42
  # Encode the string and compute its MD5 hash
src/main.py CHANGED
@@ -156,8 +156,9 @@ def main() -> None:
156
  #g_logger.warning("warning message")
157
 
158
  # Streamlit app
159
- #tab_gallery, tab_inference, tab_hotdogs, tab_map, tab_data, tab_log = st.tabs(["Cetecean classifier", "Hotdog classifier", "Map", "Data", "Log", "Beautiful cetaceans"])
160
- tab_inference, tab_hotdogs, tab_map, tab_data, tab_log, tab_gallery = st.tabs(["Cetecean classifier", "Hotdog classifier", "Map", "Data", "Log", "Beautiful cetaceans"])
 
161
  st.session_state.tab_log = tab_log
162
 
163
 
@@ -180,6 +181,7 @@ def main() -> None:
180
  with tab_map:
181
  # visual structure: a couple of toggles at the top, then the map inlcuding a
182
  # dropdown for tileset selection.
 
183
  tab_map_ui_cols = st.columns(2)
184
  with tab_map_ui_cols[0]:
185
  show_db_points = st.toggle("Show Points from DB", True)
@@ -208,9 +210,13 @@ def main() -> None:
208
 
209
 
210
 
211
- with tab_data:
212
  # the goal of this tab is to allow selection of the new obsvation's location by map click/adjust.
213
- st.markdown("Coming later hope! :construction:")
 
 
 
 
214
 
215
  st.write("Click on the map to capture a location.")
216
  #m = folium.Map(location=visp_loc, zoom_start=7)
@@ -248,7 +254,7 @@ def main() -> None:
248
  tab_log.info(f"{st.session_state.full_data}")
249
 
250
  df = pd.DataFrame(submitted_data, index=[0])
251
- with tab_data:
252
  st.table(df)
253
 
254
 
@@ -260,12 +266,17 @@ def main() -> None:
260
  # - these species are shown
261
  # - the user can override the species prediction using the dropdown
262
  # - an observation is uploaded if the user chooses.
 
 
 
 
263
 
264
  if tab_inference.button("Identify with cetacean classifier"):
265
  #pipe = pipeline("image-classification", model="Saving-Willy/cetacean-classifier", trust_remote_code=True)
266
  cetacean_classifier = AutoModelForImageClassification.from_pretrained("Saving-Willy/cetacean-classifier",
267
  revision=classifier_revision,
268
  trust_remote_code=True)
 
269
 
270
  if st.session_state.image is None:
271
  # TODO: cleaner design to disable the button until data input done?
@@ -317,11 +328,15 @@ def main() -> None:
317
  # purposes, an hotdog image classifier) which will be run locally.
318
  # - this model predicts if the image is a hotdog or not, and returns probabilities
319
  # - the input image is the same as for the ceteacean classifier - defined in the sidebar
 
 
 
 
 
320
 
321
  if tab_hotdogs.button("Get Hotdog Prediction"):
322
 
323
  pipeline_hot_dog = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
324
- tab_hotdogs.title("Hot Dog? Or Not?")
325
 
326
  if st.session_state.image is None:
327
  st.info("Please upload an image first.")
 
156
  #g_logger.warning("warning message")
157
 
158
  # Streamlit app
159
+ #tab_gallery, tab_inference, tab_hotdogs, tab_map, tab_coords, tab_log = st.tabs(["Cetecean classifier", "Hotdog classifier", "Map", "Data", "Log", "Beautiful cetaceans"])
160
+ tab_inference, tab_hotdogs, tab_map, tab_coords, tab_log, tab_gallery = \
161
+ st.tabs(["Cetecean classifier", "Hotdog classifier", "Map", "*:gray[Dev:coordinates]*", "Log", "Beautiful cetaceans"])
162
  st.session_state.tab_log = tab_log
163
 
164
 
 
181
  with tab_map:
182
  # visual structure: a couple of toggles at the top, then the map inlcuding a
183
  # dropdown for tileset selection.
184
+ sw_map.add_header_text()
185
  tab_map_ui_cols = st.columns(2)
186
  with tab_map_ui_cols[0]:
187
  show_db_points = st.toggle("Show Points from DB", True)
 
210
 
211
 
212
 
213
+ with tab_coords:
214
  # the goal of this tab is to allow selection of the new obsvation's location by map click/adjust.
215
+ st.markdown("Coming later! :construction:")
216
+ st.markdown(
217
+ f"""*The goal is to allow interactive definition for the coordinates of a new
218
+ observation, by click/drag points on the map.*""")
219
+
220
 
221
  st.write("Click on the map to capture a location.")
222
  #m = folium.Map(location=visp_loc, zoom_start=7)
 
254
  tab_log.info(f"{st.session_state.full_data}")
255
 
256
  df = pd.DataFrame(submitted_data, index=[0])
257
+ with tab_coords:
258
  st.table(df)
259
 
260
 
 
266
  # - these species are shown
267
  # - the user can override the species prediction using the dropdown
268
  # - an observation is uploaded if the user chooses.
269
+ tab_inference.markdown("""
270
+ *Run classifer to identify the species of cetean on the uploaded image.
271
+ Once inference is complete, the top three predictions are shown.
272
+ You can override the prediction by selecting a species from the dropdown.*""")
273
 
274
  if tab_inference.button("Identify with cetacean classifier"):
275
  #pipe = pipeline("image-classification", model="Saving-Willy/cetacean-classifier", trust_remote_code=True)
276
  cetacean_classifier = AutoModelForImageClassification.from_pretrained("Saving-Willy/cetacean-classifier",
277
  revision=classifier_revision,
278
  trust_remote_code=True)
279
+
280
 
281
  if st.session_state.image is None:
282
  # TODO: cleaner design to disable the button until data input done?
 
328
  # purposes, an hotdog image classifier) which will be run locally.
329
  # - this model predicts if the image is a hotdog or not, and returns probabilities
330
  # - the input image is the same as for the ceteacean classifier - defined in the sidebar
331
+ tab_hotdogs.title("Hot Dog? Or Not?")
332
+ tab_hotdogs.write("""
333
+ *Run alternative classifer on input images. Here we are using
334
+ a binary classifier - hotdog or not - from
335
+ huggingface.co/julien-c/hotdog-not-hotdog.*""")
336
 
337
  if tab_hotdogs.button("Get Hotdog Prediction"):
338
 
339
  pipeline_hot_dog = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
 
340
 
341
  if st.session_state.image is None:
342
  st.info("Please upload an image first.")
src/obs_map.py CHANGED
@@ -189,4 +189,11 @@ def present_obs_map(dataset_id:str = "Saving-Willy/Happywhale-kaggle",
189
  # this is just debug info --
190
  #st.info("[D]" + str(metadata.column_names))
191
 
192
- return st_data
 
 
 
 
 
 
 
 
189
  # this is just debug info --
190
  #st.info("[D]" + str(metadata.column_names))
191
 
192
+ return st_data
193
+
194
+
195
+ def add_header_text() -> None:
196
+ """
197
+ Add brief explainer text to the tab
198
+ """
199
+ st.write("A map showing the observations in the dataset, with markers colored by species.")
src/whale_gallery.py CHANGED
@@ -59,7 +59,11 @@ def render_whale_gallery(n_cols:int = 4) -> None:
59
  """,
60
  unsafe_allow_html=True,
61
  )
62
-
 
 
 
 
63
  cols = cycle(st.columns(n_cols))
64
  for ix in range(len(sw_wv.df_whale_img_ref)):
65
  img_name = sw_wv.df_whale_img_ref.iloc[ix].loc["WHALE_IMAGES"]
 
59
  """,
60
  unsafe_allow_html=True,
61
  )
62
+ _n = len(sw_wv.df_whale_img_ref)
63
+ st.markdown(
64
+ f"""*The {_n} classes of cetaceans that our classifier can identify.
65
+ The links provide more information about each species, from NOAA or
66
+ wikipedia.*""")
67
  cols = cycle(st.columns(n_cols))
68
  for ix in range(len(sw_wv.df_whale_img_ref)):
69
  img_name = sw_wv.df_whale_img_ref.iloc[ix].loc["WHALE_IMAGES"]
src/whale_viewer.py CHANGED
@@ -1,4 +1,5 @@
1
  from typing import List
 
2
 
3
  from PIL import Image
4
  import pandas as pd
@@ -117,22 +118,20 @@ def format_whale_name(whale_class:str) -> str:
117
  return whale_name
118
 
119
 
120
- def display_whale(whale_classes:List[str], i:int, viewcontainer=None):
121
  """
122
  Display whale image and reference to the provided viewcontainer.
123
 
124
  Args:
125
  whale_classes (List[str]): A list of whale class names.
126
  i (int): The index of the whale class to display.
127
- viewcontainer: The container to display the whale information. If
128
- not provided, use the current streamlit context (works via
129
- 'with `container`' syntax)
130
 
131
  Returns:
132
  None
133
 
134
- TODO: how to find the object type of viewcontainer.? they are just "deltagenerators" but
135
- we want the result of the generator.. In any case, it works ok with either call signature.
136
  """
137
  import streamlit as st
138
  if viewcontainer is None:
 
1
  from typing import List
2
+ from streamlit.delta_generator import DeltaGenerator
3
 
4
  from PIL import Image
5
  import pandas as pd
 
118
  return whale_name
119
 
120
 
121
+ def display_whale(whale_classes:List[str], i:int, viewcontainer:DeltaGenerator=None) -> None:
122
  """
123
  Display whale image and reference to the provided viewcontainer.
124
 
125
  Args:
126
  whale_classes (List[str]): A list of whale class names.
127
  i (int): The index of the whale class to display.
128
+ viewcontainer (streamlit.delta_generator.DeltaGenerator): The container
129
+ to display the whale information. If not provided, use the current
130
+ streamlit context (works via 'with `container`' syntax)
131
 
132
  Returns:
133
  None
134
 
 
 
135
  """
136
  import streamlit as st
137
  if viewcontainer is None: