Spaces:
Running
Running
Default year updated
Browse files- streamlit_app.py +17 -4
streamlit_app.py
CHANGED
|
@@ -237,9 +237,12 @@ def _oauth_gate() -> None:
|
|
| 237 |
st.rerun()
|
| 238 |
|
| 239 |
# ββ 2) Not signed in yet β render the sign-in screen βββββββββββββββββββββ
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
| 243 |
|
| 244 |
auth_url = (
|
| 245 |
"https://huggingface.co/oauth/authorize?"
|
|
@@ -693,7 +696,17 @@ if not kpi_daily.empty and "Year" in kpi_daily.columns:
|
|
| 693 |
int(y) for y in kpi_daily["Year"].dropna().unique() if not pd.isna(y)
|
| 694 |
)
|
| 695 |
years_avail = sorted(years_avail, reverse=True)
|
| 696 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 697 |
|
| 698 |
if min_date and max_date:
|
| 699 |
sel_dates = st.sidebar.date_input(
|
|
|
|
| 237 |
st.rerun()
|
| 238 |
|
| 239 |
# ββ 2) Not signed in yet β render the sign-in screen βββββββββββββββββββββ
|
| 240 |
+
# Generate the state token once per session; reuse it across reruns so
|
| 241 |
+
# the link in the sign-in button doesn't change underneath the user.
|
| 242 |
+
if "_oauth_state" not in st.session_state:
|
| 243 |
+
import secrets as _secrets
|
| 244 |
+
st.session_state["_oauth_state"] = _secrets.token_urlsafe(24)
|
| 245 |
+
new_state = st.session_state["_oauth_state"]
|
| 246 |
|
| 247 |
auth_url = (
|
| 248 |
"https://huggingface.co/oauth/authorize?"
|
|
|
|
| 696 |
int(y) for y in kpi_daily["Year"].dropna().unique() if not pd.isna(y)
|
| 697 |
)
|
| 698 |
years_avail = sorted(years_avail, reverse=True)
|
| 699 |
+
|
| 700 |
+
# Default the year filter to the current calendar year when present in the
|
| 701 |
+
# data; otherwise fall back to "All years" so the dashboard still loads
|
| 702 |
+
# something on empty / future-dated runs.
|
| 703 |
+
from datetime import datetime as _dt
|
| 704 |
+
_current_year = _dt.now().year
|
| 705 |
+
_year_options = ["All years"] + years_avail
|
| 706 |
+
_year_default_index = (
|
| 707 |
+
_year_options.index(_current_year) if _current_year in years_avail else 0
|
| 708 |
+
)
|
| 709 |
+
sel_year = st.sidebar.selectbox("Year", _year_options, index=_year_default_index)
|
| 710 |
|
| 711 |
if min_date and max_date:
|
| 712 |
sel_dates = st.sidebar.date_input(
|