Vũ Thanh Hà commited on
Commit
f5356cd
1 Parent(s): 171412a

add tensorboard

Browse files
pages/1_download_tb.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ import pandas as pd
4
+
5
+ import streamlit as st
6
+ # from streamlit_tensorboard import st_tensorboard
7
+ from huggingface_hub import list_models
8
+ from huggingface_hub import HfApi
9
+
10
+ # ==============================================================
11
+
12
+ st.set_page_config(layout="wide")
13
+
14
+ # ==============================================================
15
+
16
+ logdir="/tmp/tensorboard_logs"
17
+ os.makedirs(logdir, exist_ok=True)
18
+
19
+ def clean_logdir(logdir):
20
+ try:
21
+ shutil.rmtree(logdir)
22
+ except Exception as e:
23
+ print(e)
24
+
25
+ @st.cache_resource
26
+ def get_models():
27
+ _author = "hahunavth"
28
+ _filter = "emofs2"
29
+ return list(
30
+ list_models(author=_author, filter=_filter, sort="last_modified", direction=-1)
31
+ )
32
+
33
+
34
+ TB_FILE_PREFIX = "events.out.tfevents"
35
+ def download_repoo_tb(repo_id, api, log_dir, df):
36
+ repo_name = repo_id.split("/")[-1]
37
+ if api.repo_exists(repo_id):
38
+ files = api.list_repo_files(repo_id)
39
+ else:
40
+ raise ValueError(f"Repo {repo_id} does not exist")
41
+
42
+ tb_files = [f for f in files if f.split('/')[-1].startswith(TB_FILE_PREFIX)]
43
+
44
+ tb_files_info = list(api.list_files_info(repo_id, tb_files))
45
+ tb_files_info = [f for f in tb_files_info if f.size > 0]
46
+
47
+ for repo_file in tb_files_info:
48
+ path = repo_file.path
49
+ size = repo_file.size
50
+ stage = path.split('/')[-2]
51
+ fname = path.split('/')[-1]
52
+
53
+ sub_folder = path.replace(f"/{fname}", '')
54
+ if ((df["repo"]==repo_name) & (df["path"]==path) & (df["size"]==size)).any() and os.path.exists(os.path.join(log_dir, repo_name, path)):
55
+ print(f"Skipping {repo_name}/{path}")
56
+ continue
57
+ else:
58
+ print(f"Downloading {repo_name}/{path}")
59
+ api.hf_hub_download(repo_id=repo_id, filename=fname, subfolder=sub_folder, local_dir=os.path.join(log_dir, repo_name))
60
+ new_df = pd.DataFrame([{
61
+ "repo": repo_name,
62
+ "path": path,
63
+ "size": size,
64
+ }])
65
+ df = pd.concat([df, new_df], ignore_index=True)
66
+ return df
67
+
68
+ @st.cache_resource
69
+ def create_cache_dataframe():
70
+ return pd.DataFrame(columns=["repo", "path", "size"])
71
+
72
+ # ==============================================================
73
+
74
+ api = HfApi()
75
+ df = create_cache_dataframe()
76
+
77
+ models = get_models()
78
+ model_ids = [model.id for model in models]
79
+
80
+ # select many
81
+ with st.expander("Download tf", expanded=True):
82
+ with st.form("my_form"):
83
+ selected_models = st.multiselect("Select models", model_ids, default=None)
84
+ submit = st.form_submit_button("Download logs")
85
+
86
+ if submit:
87
+ # download tensorboard logs
88
+ with st.spinner("Downloading logs..."):
89
+ for model_id in selected_models:
90
+ st.write(f"Downloading logs for {model_id}")
91
+ df = download_repoo_tb(model_id, api, logdir, df)
92
+
93
+ clean_btn = st.button("Clean all")
94
+ if clean_btn:
95
+ clean_logdir(logdir)
96
+ create_cache_dataframe.clear()
97
+ get_models.clear()
98
+
99
+ # with st.expander("...", expanded=True):
100
+ # st_tensorboard(logdir=logdir, port=6006, width=1760, scrolling=False)
101
+
102
+ # st.text(st)
pages/2_tensorboard.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_tensorboard import st_tensorboard
3
+
4
+
5
+ st.set_page_config(layout="wide")
6
+
7
+ logdir="/tmp/tensorboard_logs"
8
+
9
+ st_tensorboard(logdir=logdir, port=6006, width=1760, scrolling=False)
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
  huggingface_hub
2
  kaggle
 
 
 
1
  huggingface_hub
2
  kaggle
3
+ st_tensorboard
4
+ pandas