SLAVA / streamlit_app.py
sharafetdinov42's picture
Cache fix
d7e6665 verified
raw
history blame
1.17 kB
import os, time, pathlib, shutil
os.environ.setdefault("TMPDIR", "/tmp/streamlit_tmp")
tmpdir = pathlib.Path(os.environ["TMPDIR"])
tmpdir.mkdir(parents=True, exist_ok=True)
def prune_old_files(root: str, max_age_sec: int = 30 * 60):
now = time.time()
p = pathlib.Path(root)
if not p.exists():
return
for path in p.rglob("*"):
try:
if path.is_file() and (now - path.stat().st_mtime > max_age_sec):
path.unlink(missing_ok=True)
except Exception:
pass
for path in sorted(p.rglob("*"), reverse=True):
try:
if path.is_dir() and not any(path.iterdir()):
path.rmdir()
except Exception:
pass
prune_old_files(tmpdir.as_posix(), max_age_sec=30 * 60)
prune_old_files("/tmp", max_age_sec=60 * 60)
import streamlit as st
main_page = st.Page("main.py", title="Описание"
)
Leaderboard_page = st.Page("Leaderboard.py", title="Лидерборд"
)
pg = st.navigation(
{
"Main": [Leaderboard_page, main_page],
}
)
st.set_page_config(page_title="Leaderboard", layout="wide", page_icon="🏆",
)
pg.run()