Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| def check_auth(ui: dict, password: str = "KliWinBa25!") -> None: | |
| """ | |
| Simple password protection with multilingual support. | |
| """ | |
| if "authenticated" not in st.session_state: | |
| st.session_state["authenticated"] = False | |
| if not st.session_state["authenticated"]: | |
| st.title(f"{ui['auth']['title']}") | |
| pw = st.text_input(ui["auth"]["prompt"], type="password") | |
| if pw == password: | |
| st.session_state["authenticated"] = True | |
| st.success(ui["auth"]["success"]) | |
| if st.button(ui["auth"]["continue_button"]): | |
| st.rerun() | |
| elif pw != "": | |
| st.error(ui["auth"]["error"]) | |
| st.stop() | |
| def init_session_state(): | |
| """ | |
| Initializes all required Streamlit session state variables. | |
| """ | |
| defaults = { | |
| "eingabedaten": None, | |
| "df_heizsysteme": None, | |
| "user_values": {}, | |
| "heizlast_user": None, | |
| "selected_objekt_id": None, | |
| "selected_objekt_id_batch_detail": None, | |
| "szenario_bestaetigt": False, | |
| "szenario": None, | |
| "annuitaeten_gesamt_batch": [] | |
| } | |
| for key, value in defaults.items(): | |
| if key not in st.session_state: | |
| st.session_state[key] = value | |
| def handle_language_switch(lang): | |
| if "LANG_PREV" not in st.session_state: | |
| st.session_state["LANG_PREV"] = lang | |
| if st.session_state["LANG_PREV"] != lang: | |
| st.session_state["scenario"] = None | |
| st.session_state["radio_scenario"] = None | |
| st.session_state["scenario_confirmed"] = False | |
| st.session_state["LANG_PREV"] = lang | |
| def ensure_scenario_state(): | |
| if "scenario_confirmed" not in st.session_state: | |
| st.session_state.scenario_confirmed = False | |
| if "scenario" not in st.session_state: | |
| st.session_state.scenario = None |