Spaces:
Sleeping
Sleeping
Pavan Kumar Jonnakuti commited on
Commit Β·
9a677df
1
Parent(s): f9abe22
Remove redundant runtime cache downloader and protect cache Parquet files from unlinking
Browse files- streamlit/dashboard.py +6 -41
streamlit/dashboard.py
CHANGED
|
@@ -111,45 +111,6 @@ st.set_page_config(
|
|
| 111 |
},
|
| 112 |
)
|
| 113 |
|
| 114 |
-
|
| 115 |
-
def is_lfs_pointer(path):
|
| 116 |
-
"""Check if a file is an LFS pointer file or doesn't exist."""
|
| 117 |
-
if not path.exists():
|
| 118 |
-
return True
|
| 119 |
-
if path.stat().st_size > 2000:
|
| 120 |
-
return False
|
| 121 |
-
try:
|
| 122 |
-
with open(path, "r", encoding="utf-8", errors="ignore") as f:
|
| 123 |
-
first_line = f.readline()
|
| 124 |
-
return first_line.startswith("version https://git-lfs")
|
| 125 |
-
except:
|
| 126 |
-
return False
|
| 127 |
-
|
| 128 |
-
def ensure_cache_files():
|
| 129 |
-
"""Ensure all parquet cache files exist and are not LFS pointer files."""
|
| 130 |
-
CACHE_DIR.mkdir(exist_ok=True)
|
| 131 |
-
files = {
|
| 132 |
-
"profiles.parquet": "https://huggingface.co/spaces/jpawan33/Argolytics/resolve/main/streamlit/cache/profiles.parquet",
|
| 133 |
-
"bgc_profiles.parquet": "https://huggingface.co/spaces/jpawan33/Argolytics/resolve/main/streamlit/cache/bgc_profiles.parquet",
|
| 134 |
-
"meta.parquet": "https://huggingface.co/spaces/jpawan33/Argolytics/resolve/main/streamlit/cache/meta.parquet",
|
| 135 |
-
"incois_launch_dates.csv": "https://huggingface.co/spaces/jpawan33/Argolytics/resolve/main/streamlit/cache/incois_launch_dates.csv"
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
import urllib.request
|
| 139 |
-
for name, url in files.items():
|
| 140 |
-
path = CACHE_DIR / name
|
| 141 |
-
if is_lfs_pointer(path):
|
| 142 |
-
try:
|
| 143 |
-
if path.exists():
|
| 144 |
-
path.unlink()
|
| 145 |
-
with st.spinner(f"Initializing cache file {name} (one-time setup)..."):
|
| 146 |
-
urllib.request.urlretrieve(url, path)
|
| 147 |
-
except Exception as e:
|
| 148 |
-
st.error(f"Failed to download {name} from Hugging Face: {e}")
|
| 149 |
-
|
| 150 |
-
ensure_cache_files()
|
| 151 |
-
|
| 152 |
-
|
| 153 |
# ==================== CUSTOM CSS ====================
|
| 154 |
st.markdown(
|
| 155 |
"""
|
|
@@ -986,8 +947,12 @@ with st.sidebar:
|
|
| 986 |
|
| 987 |
# ββ Refresh ββ
|
| 988 |
if st.button("π Refresh Data", use_container_width=True, type="primary"):
|
| 989 |
-
|
| 990 |
-
f.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 991 |
st.cache_data.clear()
|
| 992 |
st.rerun()
|
| 993 |
|
|
|
|
| 111 |
},
|
| 112 |
)
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
# ==================== CUSTOM CSS ====================
|
| 115 |
st.markdown(
|
| 116 |
"""
|
|
|
|
| 947 |
|
| 948 |
# ββ Refresh ββ
|
| 949 |
if st.button("π Refresh Data", use_container_width=True, type="primary"):
|
| 950 |
+
if PROF_FILE.exists():
|
| 951 |
+
for f in CACHE_DIR.glob("*.parquet"):
|
| 952 |
+
try:
|
| 953 |
+
f.unlink()
|
| 954 |
+
except:
|
| 955 |
+
pass
|
| 956 |
st.cache_data.clear()
|
| 957 |
st.rerun()
|
| 958 |
|