diff --git a/src/annescribe/webapp/home.py b/src/annescribe/webapp/home.py index 1e34790..90c1060 100644 --- a/src/annescribe/webapp/home.py +++ b/src/annescribe/webapp/home.py @@ -19,7 +19,7 @@ def render_home(container, with container.container(): col1, col2 = st.columns([3, 1]) with col1: - st.title('Annescribe Home') + st.title('AnneScribe Home') st.write("Welcome to AnneScribe, the audio transcription tool for your every Masterarbeit need.") with col2: authenticator.logout(callback=lambda x: st.session_state.clear()) diff --git a/src/annescribe/webapp_main.py b/src/annescribe/webapp_main.py index c6f18f2..5a7de54 100644 --- a/src/annescribe/webapp_main.py +++ b/src/annescribe/webapp_main.py @@ -14,6 +14,14 @@ from annescribe.webapp.home import render_home logger = get_logger(__name__) CONFIG_FILE = os.environ.get('CONFIG_FILE', "config.yml") +AUTH_FILE = os.environ.get('AUTH_FILE', "auth.yml") + +# set wide mode +st.set_page_config( + page_title="AnneScribe", + layout="wide", + initial_sidebar_state="auto", +) if CONFIG_FILE is None: raise ValueError('CONFIG_FILE environment variable is not set') @@ -23,56 +31,49 @@ elif not os.path.exists(CONFIG_FILE): with open(CONFIG_FILE, 'r') as config_file: config = yaml.safe_load(config_file) -AUTH_FILE = os.environ.get('AUTH_FILE', "auth.yml") if AUTH_FILE is None: raise ValueError('AUTH_YML_FILE environment variable is not set') if os.path.exists(AUTH_FILE): with open(AUTH_FILE, 'r') as auth_file: auth_config = yaml.safe_load(auth_file) - print(logger.info(f'User authentication enabled')) + logger.info(f'User authentication enabled') authentication_enabled = True + authenticator = st_auth.Authenticate( + auth_config["credentials"], + auth_config["cookie"]["name"], + auth_config["cookie"]["key"], + auth_config["cookie"]["expiry_days"], + ) else: logger.info(f"AUTH_FILE {AUTH_FILE} does not exist, user authentication disabled") authentication_enabled = False -# set wide mode -st.set_page_config( - page_title="Annescribe", - layout="wide", - initial_sidebar_state="auto", -) -if authentication_enabled: - authenticator = st_auth.Authenticate( - auth_config["credentials"], - auth_config["cookie"]["name"], - auth_config["cookie"]["key"], - auth_config["cookie"]["expiry_days"], - ) +if not authentication_enabled: + authentication_status = True +else: + authentication_status = st.session_state.get("authentication_status") + if authentication_status is None: + authentication_status = False + st.session_state["authentication_status"] = False content_wrapper = st.empty() + def render_login(): with content_wrapper.container(): - st.title('Annescribe Login') + st.title('AnneScribe Login') if authentication_enabled: authenticator.login() -if "authentication_status" not in st.session_state: - print("schniedel") - st.session_state["authentication_status"] = None - st.session_state["username"] = None - -authentication_status = st.session_state.get("authentication_status") -username = st.session_state.get("username") if authentication_status is True: + username = st.session_state.get("username") render_home(content_wrapper, config, authenticator if authentication_enabled else None) else: # make sure to remove cookie st.markdown("Please login. If no login form is shown, please refresh the page and or press R.") render_login() - -# st_autorefresh(interval=2000, ) \ No newline at end of file +# st_autorefresh(interval=2000, )