Spaces:
Sleeping
Sleeping
fix: clean push all observations
Browse files
src/classifier/classifier_image.py
CHANGED
|
@@ -7,7 +7,6 @@ g_logger = logging.getLogger(__name__)
|
|
| 7 |
g_logger.setLevel(LOG_LEVEL)
|
| 8 |
|
| 9 |
import whale_viewer as viewer
|
| 10 |
-
from dataset.hf_push_observations import push_observations
|
| 11 |
from utils.grid_maker import gridder
|
| 12 |
from utils.metadata_handler import metadata2md
|
| 13 |
from input.input_observation import InputObservation
|
|
@@ -113,7 +112,6 @@ def cetacean_show_results_and_review() -> None:
|
|
| 113 |
observation = _observation.to_dict()
|
| 114 |
st.session_state.public_observations[hash] = observation
|
| 115 |
|
| 116 |
-
#st.button(f"Upload observation {str(o)} to THE INTERNET!", on_click=push_observations)
|
| 117 |
# TODO: the metadata only fills properly if `validate` was clicked.
|
| 118 |
# TODO put condition on the debug
|
| 119 |
st.markdown(metadata2md(hash, debug=False))
|
|
|
|
| 7 |
g_logger.setLevel(LOG_LEVEL)
|
| 8 |
|
| 9 |
import whale_viewer as viewer
|
|
|
|
| 10 |
from utils.grid_maker import gridder
|
| 11 |
from utils.metadata_handler import metadata2md
|
| 12 |
from input.input_observation import InputObservation
|
|
|
|
| 112 |
observation = _observation.to_dict()
|
| 113 |
st.session_state.public_observations[hash] = observation
|
| 114 |
|
|
|
|
| 115 |
# TODO: the metadata only fills properly if `validate` was clicked.
|
| 116 |
# TODO put condition on the debug
|
| 117 |
st.markdown(metadata2md(hash, debug=False))
|
src/dataset/hf_push_observations.py
CHANGED
|
@@ -7,6 +7,7 @@ from streamlit.delta_generator import DeltaGenerator
|
|
| 7 |
import streamlit as st
|
| 8 |
from huggingface_hub import HfApi, CommitInfo
|
| 9 |
|
|
|
|
| 10 |
|
| 11 |
# get a global var for logger accessor in this module
|
| 12 |
LOG_LEVEL = logging.DEBUG
|
|
@@ -48,7 +49,7 @@ def push_observation(image_hash:str, api:HfApi, enable_push:False) -> CommitInfo
|
|
| 48 |
rv = api.upload_file(
|
| 49 |
path_or_fileobj=f.name,
|
| 50 |
path_in_repo=path_in_repo,
|
| 51 |
-
repo_id=
|
| 52 |
repo_type="dataset",
|
| 53 |
)
|
| 54 |
print(rv)
|
|
@@ -73,50 +74,4 @@ def push_all_observations(enable_push:bool=False):
|
|
| 73 |
|
| 74 |
# iterate over the list of observations
|
| 75 |
for hash in st.session_state.public_observations.keys():
|
| 76 |
-
rv = push_observation(hash, api, enable_push=enable_push)
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
def push_observations(tab_log:DeltaGenerator=None):
|
| 81 |
-
"""
|
| 82 |
-
Push the observations 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 observation since generating the logger)
|
| 88 |
-
|
| 89 |
-
"""
|
| 90 |
-
raise DeprecationWarning("This function is deprecated. Use push_all_observations instead.")
|
| 91 |
-
|
| 92 |
-
# we get the observation from session state: 1 is the dict 2 is the image.
|
| 93 |
-
# first, lets do an info display (popup)
|
| 94 |
-
metadata_str = json.dumps(st.session_state.public_observation)
|
| 95 |
-
|
| 96 |
-
st.toast(f"Uploading observations: {metadata_str}", icon="🦭")
|
| 97 |
-
g_logger.info(f"Uploading observations: {metadata_str}")
|
| 98 |
-
|
| 99 |
-
# get huggingface api
|
| 100 |
-
token = os.environ.get("HF_TOKEN", None)
|
| 101 |
-
api = HfApi(token=token)
|
| 102 |
-
|
| 103 |
-
f = tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False)
|
| 104 |
-
f.write(metadata_str)
|
| 105 |
-
f.close()
|
| 106 |
-
st.info(f"temp file: {f.name} with metadata written...")
|
| 107 |
-
|
| 108 |
-
path_in_repo= f"metadata/{st.session_state.public_observation['author_email']}/{st.session_state.public_observation['image_md5']}.json"
|
| 109 |
-
msg = f"fname: {f.name} | path: {path_in_repo}"
|
| 110 |
-
print(msg)
|
| 111 |
-
st.warning(msg)
|
| 112 |
-
# rv = api.upload_file(
|
| 113 |
-
# path_or_fileobj=f.name,
|
| 114 |
-
# path_in_repo=path_in_repo,
|
| 115 |
-
# repo_id="Saving-Willy/temp_dataset",
|
| 116 |
-
# repo_type="dataset",
|
| 117 |
-
# )
|
| 118 |
-
# print(rv)
|
| 119 |
-
# msg = f"observation attempted tx to repo happy walrus: {rv}"
|
| 120 |
-
g_logger.info(msg)
|
| 121 |
-
st.info(msg)
|
| 122 |
-
|
|
|
|
| 7 |
import streamlit as st
|
| 8 |
from huggingface_hub import HfApi, CommitInfo
|
| 9 |
|
| 10 |
+
from dataset.download import dataset_id
|
| 11 |
|
| 12 |
# get a global var for logger accessor in this module
|
| 13 |
LOG_LEVEL = logging.DEBUG
|
|
|
|
| 49 |
rv = api.upload_file(
|
| 50 |
path_or_fileobj=f.name,
|
| 51 |
path_in_repo=path_in_repo,
|
| 52 |
+
repo_id=dataset_id,
|
| 53 |
repo_type="dataset",
|
| 54 |
)
|
| 55 |
print(rv)
|
|
|
|
| 74 |
|
| 75 |
# iterate over the list of observations
|
| 76 |
for hash in st.session_state.public_observations.keys():
|
| 77 |
+
rv = push_observation(hash, api, enable_push=enable_push)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/pages/4_🔥_classifiers.py
CHANGED
|
@@ -28,8 +28,6 @@ from classifier.classifier_hotdog import hotdog_classify
|
|
| 28 |
classifier_name = "Saving-Willy/cetacean-classifier"
|
| 29 |
#classifier_revision = '0f9c15e2db4d64e7f622ade518854b488d8d35e6'
|
| 30 |
classifier_revision = 'main' # default/latest version
|
| 31 |
-
dataset_id = "Saving-Willy/temp_dataset"
|
| 32 |
-
data_files = "data/train-00000-of-00001.parquet"
|
| 33 |
############################################################
|
| 34 |
|
| 35 |
g_logger = logging.getLogger(__name__)
|
|
|
|
| 28 |
classifier_name = "Saving-Willy/cetacean-classifier"
|
| 29 |
#classifier_revision = '0f9c15e2db4d64e7f622ade518854b488d8d35e6'
|
| 30 |
classifier_revision = 'main' # default/latest version
|
|
|
|
|
|
|
| 31 |
############################################################
|
| 32 |
|
| 33 |
g_logger = logging.getLogger(__name__)
|