Spaces:
Sleeping
Sleeping
rmm
commited on
Commit
·
6430cbd
1
Parent(s):
c096386
docs: docstrings and mkdocs md files for three modules
Browse files- call_models/obs_map.py +35 -6
- call_models/whale_gallery.py +12 -8
- call_models/whale_viewer.py +4 -3
- docs/obs_map.md +5 -0
- docs/whale_gallery.md +3 -1
- docs/whale_viewer.md +2 -0
- mkdocs.yaml +1 -1
call_models/obs_map.py
CHANGED
|
@@ -62,7 +62,21 @@ _colors = [
|
|
| 62 |
|
| 63 |
whale2color = {k: v for k, v in zip(sw_wv.WHALE_CLASSES, _colors)}
|
| 64 |
|
| 65 |
-
def create_map(tile_name:str, location:Tuple, zoom_start: int = 7):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
# https://xyzservices.readthedocs.io/en/stable/gallery.html
|
| 67 |
# get teh attribtuions from here once we pick the 2-3-4 options
|
| 68 |
# make esri ocean the default
|
|
@@ -103,12 +117,27 @@ def create_map(tile_name:str, location:Tuple, zoom_start: int = 7):
|
|
| 103 |
|
| 104 |
def present_obs_map(dataset_id:str = "Saving-Willy/Happywhale-kaggle",
|
| 105 |
data_files:str = "data/train-00000-of-00001.parquet",
|
| 106 |
-
dbg_show_extra:bool = False):
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
observations
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
# load/download data from huggingface dataset
|
| 113 |
metadata = load_dataset(dataset_id, data_files=data_files)
|
| 114 |
|
|
|
|
| 62 |
|
| 63 |
whale2color = {k: v for k, v in zip(sw_wv.WHALE_CLASSES, _colors)}
|
| 64 |
|
| 65 |
+
def create_map(tile_name:str, location:Tuple[float], zoom_start: int = 7) -> folium.Map:
|
| 66 |
+
"""
|
| 67 |
+
Create a folium map with the specified tile layer
|
| 68 |
+
|
| 69 |
+
Parameters:
|
| 70 |
+
tile_name (str): The name of the tile layer to use. Options include:
|
| 71 |
+
'Open Street Map', 'Esri Ocean', 'Esri Images',
|
| 72 |
+
'Stamen Toner', 'Stamen Watercolor',
|
| 73 |
+
'CartoDB Positron', 'CartoDB Dark_Matter'.
|
| 74 |
+
location (Tuple): Coordinates (lat, lon) of the map center, as floats.
|
| 75 |
+
zoom_start (int, optional): The initial zoom level for the map. Default is 7.
|
| 76 |
+
|
| 77 |
+
Returns:
|
| 78 |
+
folium.Map: A folium Map object with the specified settings.
|
| 79 |
+
"""
|
| 80 |
# https://xyzservices.readthedocs.io/en/stable/gallery.html
|
| 81 |
# get teh attribtuions from here once we pick the 2-3-4 options
|
| 82 |
# make esri ocean the default
|
|
|
|
| 117 |
|
| 118 |
def present_obs_map(dataset_id:str = "Saving-Willy/Happywhale-kaggle",
|
| 119 |
data_files:str = "data/train-00000-of-00001.parquet",
|
| 120 |
+
dbg_show_extra:bool = False) -> dict:
|
| 121 |
+
"""
|
| 122 |
+
Render map plus tile selector, with markers for whale observations
|
|
|
|
| 123 |
|
| 124 |
+
|
| 125 |
+
This function loads whale observation data from a specified dataset and
|
| 126 |
+
file, creates a pandas DataFrame compliant with Folium/Streamlit maps, and
|
| 127 |
+
renders an interactive map with markers for each observation. The map
|
| 128 |
+
allows users to select a tileset, and displays markers with species-specific
|
| 129 |
+
colors.
|
| 130 |
+
|
| 131 |
+
Args:
|
| 132 |
+
dataset_id (str): The ID of the dataset to load from Hugging Face. Default is "Saving-Willy/Happywhale-kaggle".
|
| 133 |
+
data_files (str): The path to the data file to load. Default is "data/train-00000-of-00001.parquet".
|
| 134 |
+
dbg_show_extra (bool): If True, add a few extra sample markers for visualization. Default is False.
|
| 135 |
+
|
| 136 |
+
Returns:
|
| 137 |
+
dict: Selected data from the Folium/leaflet.js interactions in the browser.
|
| 138 |
+
|
| 139 |
+
"""
|
| 140 |
+
|
| 141 |
# load/download data from huggingface dataset
|
| 142 |
metadata = load_dataset(dataset_id, data_files=data_files)
|
| 143 |
|
call_models/whale_gallery.py
CHANGED
|
@@ -3,17 +3,22 @@ import streamlit as st
|
|
| 3 |
|
| 4 |
import whale_viewer as sw_wv
|
| 5 |
|
| 6 |
-
|
|
|
|
| 7 |
"""
|
| 8 |
Renders a gallery of whale images + urls in a grid format using Streamlit.
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
Parameters:
|
| 11 |
-
|
| 12 |
|
| 13 |
-
The function formats whale names, creates a grid layout for images, and applies custom CSS styles
|
| 14 |
-
Each image is displayed with a caption and a link to a reference URL.
|
| 15 |
"""
|
| 16 |
-
def
|
|
|
|
| 17 |
return name.replace("_", " ").capitalize()
|
| 18 |
|
| 19 |
# make a grid of images, use some css to get more uniform
|
|
@@ -58,7 +63,7 @@ def render_whale_gallery(n_cols:int = 4):
|
|
| 58 |
cols = cycle(st.columns(n_cols))
|
| 59 |
for ix in range(len(sw_wv.df_whale_img_ref)):
|
| 60 |
img_name = sw_wv.df_whale_img_ref.iloc[ix].loc["WHALE_IMAGES"]
|
| 61 |
-
whale_name =
|
| 62 |
url = sw_wv.df_whale_img_ref.iloc[ix].loc['WHALE_REFERENCES']
|
| 63 |
image_path = f"images/references/{img_name}"
|
| 64 |
#next(cols).image(image_path, width=150, caption=f"{whale_name}")
|
|
@@ -91,5 +96,4 @@ if __name__ == "__main__":
|
|
| 91 |
tg_cont = st.container(key="swgallery")
|
| 92 |
with tg_cont:
|
| 93 |
render_whale_gallery(n_cols=4)
|
| 94 |
-
|
| 95 |
-
pass
|
|
|
|
| 3 |
|
| 4 |
import whale_viewer as sw_wv
|
| 5 |
|
| 6 |
+
|
| 7 |
+
def render_whale_gallery(n_cols:int = 4) -> None:
|
| 8 |
"""
|
| 9 |
Renders a gallery of whale images + urls in a grid format using Streamlit.
|
| 10 |
|
| 11 |
+
The function formats whale names, creates a grid layout for images, and
|
| 12 |
+
applies custom CSS styles Each image is displayed with a caption and a link
|
| 13 |
+
to a reference URL.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
Parameters:
|
| 17 |
+
n_cols (int): Number of columns in the grid. Default is 4.
|
| 18 |
|
|
|
|
|
|
|
| 19 |
"""
|
| 20 |
+
def _format_whale_name(name:str) -> str:
|
| 21 |
+
'''clean up the whale name for display'''
|
| 22 |
return name.replace("_", " ").capitalize()
|
| 23 |
|
| 24 |
# make a grid of images, use some css to get more uniform
|
|
|
|
| 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"]
|
| 66 |
+
whale_name = _format_whale_name(str(sw_wv.df_whale_img_ref.iloc[ix].name))
|
| 67 |
url = sw_wv.df_whale_img_ref.iloc[ix].loc['WHALE_REFERENCES']
|
| 68 |
image_path = f"images/references/{img_name}"
|
| 69 |
#next(cols).image(image_path, width=150, caption=f"{whale_name}")
|
|
|
|
| 96 |
tg_cont = st.container(key="swgallery")
|
| 97 |
with tg_cont:
|
| 98 |
render_whale_gallery(n_cols=4)
|
| 99 |
+
|
|
|
call_models/whale_viewer.py
CHANGED
|
@@ -104,8 +104,8 @@ df_whale_img_ref = pd.DataFrame(
|
|
| 104 |
|
| 105 |
def format_whale_name(whale_class:str) -> str:
|
| 106 |
"""
|
| 107 |
-
Formats a whale class name
|
| 108 |
-
|
| 109 |
Args:
|
| 110 |
whale_class (str): The class name of the whale, with words separated by underscores.
|
| 111 |
|
|
@@ -125,7 +125,8 @@ def display_whale(whale_classes:List[str], i:int, viewcontainer=None):
|
|
| 125 |
i (int): The index of the whale class to display.
|
| 126 |
viewcontainer: The container to display the whale information. If
|
| 127 |
not provided, use the current streamlit context (works via
|
| 128 |
-
'with
|
|
|
|
| 129 |
Returns:
|
| 130 |
None
|
| 131 |
|
|
|
|
| 104 |
|
| 105 |
def format_whale_name(whale_class:str) -> str:
|
| 106 |
"""
|
| 107 |
+
Formats a whale class name for display
|
| 108 |
+
|
| 109 |
Args:
|
| 110 |
whale_class (str): The class name of the whale, with words separated by underscores.
|
| 111 |
|
|
|
|
| 125 |
i (int): The index of the whale class to display.
|
| 126 |
viewcontainer: The container to display the whale information. If
|
| 127 |
not provided, use the current streamlit context (works via
|
| 128 |
+
'with `container`' syntax)
|
| 129 |
+
|
| 130 |
Returns:
|
| 131 |
None
|
| 132 |
|
docs/obs_map.md
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
::: call_models.obs_map
|
|
|
|
| 1 |
+
This module provides rendering of observations on an interactive map, with a variety of tilesets available.
|
| 2 |
+
|
| 3 |
+
Note: OSM, ESRI, and CartoDB map tiles are served without authentication/tokens,
|
| 4 |
+
and so render correctly on the huggingface deployment. The Stamen tiles render
|
| 5 |
+
on localhost but require a token to present on a 3rd-party site.
|
| 6 |
|
| 7 |
::: call_models.obs_map
|
docs/whale_gallery.md
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
-
::: call_models.whale_gallery
|
|
|
|
| 1 |
+
This module provides a gallery of the whales and dolphins that the classifier
|
| 2 |
+
is trained on. It diplays the images and links to further info on the species.
|
| 3 |
|
| 4 |
+
::: call_models.whale_gallery
|
docs/whale_viewer.md
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
::: call_models.whale_viewer
|
|
|
|
| 1 |
+
This module provides a streamlit rendering for the whales and dolphins that the classifier is aware of, and also holds the
|
| 2 |
+
metadata for them (images, class names that the classifier uses, and URLS for further information about each species).
|
| 3 |
|
| 4 |
::: call_models.whale_viewer
|
mkdocs.yaml
CHANGED
|
@@ -25,9 +25,9 @@ nav:
|
|
| 25 |
- API:
|
| 26 |
- Main app: main.md
|
| 27 |
- Data entry handling: input_handling.md
|
|
|
|
| 28 |
- Whale gallery: whale_gallery.md
|
| 29 |
- Whale viewer: whale_viewer.md
|
| 30 |
-
- Map of observations: obs_map.md
|
| 31 |
- Logging: st_logs.md
|
| 32 |
- Tab-rendering fix (js): fix_tabrender.md
|
| 33 |
|
|
|
|
| 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 |
|