From 85fdaf336f394da3730be36b35933eee177aeb57 Mon Sep 17 00:00:00 2001 From: Alexander Getka <59709326+AlexanderGetka-cbica@users.noreply.github.com> Date: Mon, 9 Dec 2024 02:33:52 -0500 Subject: [PATCH 1/4] Update .dockerignore --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index 6859030b..7f0d3858 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ .github test +test_data **/*.nii.gz build **/build From a3ce5085e9698d7062f97ddba3282600658f0968 Mon Sep 17 00:00:00 2001 From: Alexander Getka Date: Mon, 9 Dec 2024 03:01:23 -0500 Subject: [PATCH 2/4] Cloud data isolation --- src/viewer/utils/utils_menu.py | 1 + src/viewer/utils/utils_session.py | 34 +++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/viewer/utils/utils_menu.py b/src/viewer/utils/utils_menu.py index ad986285..176a3c6e 100644 --- a/src/viewer/utils/utils_menu.py +++ b/src/viewer/utils/utils_menu.py @@ -16,6 +16,7 @@ def menu() -> Any: email = st.session_state.cloud_session_token['email'] logout_url = "https://cbica-nichart.auth.us-east-1.amazoncognito.com/logout?client_id=4shr6mm2h0p0i4o9uleqpu33fj&response_type=code&scope=email+openid+phone&redirect_uri=https://cbica-nichart-alb-272274500.us-east-1.elb.amazonaws.com/oauth2/idpresponse" st.sidebar.info(f"Logged in as {email}.") + st.sidebar.info(f"User ID: {st.session_state.cloud_user_id}") ## TODO: Make this button also delete user data automatically st.sidebar.button("Log out", on_click=redirect, args=(logout_url,)) if st.session_state.pipeline == "Home": diff --git a/src/viewer/utils/utils_session.py b/src/viewer/utils/utils_session.py index d2762b98..867bacc7 100644 --- a/src/viewer/utils/utils_session.py +++ b/src/viewer/utils/utils_session.py @@ -26,19 +26,19 @@ def config_page() -> None: ## Function to parse AWS login (if available) def process_session_token(): - ''' - WARNING: We use unsupported features of Streamlit - However, this is quite fast and works well with - the latest version of Streamlit (1.27) - Also, this does not verify the session token's - authenticity. It only decodes the token. - ''' - headers = _get_websocket_headers() + #headers = _get_websocket_headers() + headers = st.context.headers if not headers or "X-Amzn-Oidc-Data" not in headers: return {} return jwt.decode( headers["X-Amzn-Oidc-Data"], algorithms=["ES256"], options={"verify_signature": False} ) + +def process_session_user_id(): + headers = st.context.headers + if not headers or "X-Amzn-Oidc-Identity" not in headers: + return "NO_USER_FOUND" + return headers["X-Amzn-Oidc-Identity"] def init_session_state() -> None: @@ -64,10 +64,14 @@ def init_session_state() -> None: st.session_state.cloud_session_token = process_session_token() if st.session_state.cloud_session_token: st.session_state.has_cloud_session = True + st.session_state.cloud_user_id = process_session_user_id() else: st.session_state.has_cloud_session = False else: st.session_state.has_cloud_session = False + + ## REMOVE THIS + st.write(st.session_state.cloud_session_token) ################################### @@ -172,9 +176,17 @@ def init_session_state() -> None: # Set initial values for paths st.session_state.paths["root"] = os.path.dirname(os.path.dirname(os.getcwd())) st.session_state.paths["init"] = st.session_state.paths["root"] - st.session_state.paths["dir_out"] = os.path.join( - st.session_state.paths["root"], "output_folder" - ) + if st.session_state.has_cloud_session: + user_id = st.session_state.cloud_user_id + st.session_state.paths["dir_out"] = os.path.join( + st.session_state.paths["root"], "output_folder", user_id + ) + else: + st.session_state.paths["dir_out"] = os.path.join( + st.session_state.paths["root"], "output_folder" + ) + + if not os.path.exists(st.session_state.paths["dir_out"]): os.makedirs(st.session_state.paths["dir_out"]) From 9fe80f9af0a3eb84f1f629469a3e90588f3e85e8 Mon Sep 17 00:00:00 2001 From: Alexander Getka Date: Mon, 9 Dec 2024 05:46:22 -0500 Subject: [PATCH 3/4] Docker updates, some other fixes --- .dockerignore | 1 + Dockerfile | 3 ++- requirements.txt | 2 +- src/viewer/pages/process_sMRI_DLMUSE.py | 2 +- src/viewer/utils/utils_session.py | 2 -- src/viewer/utils/utils_st.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.dockerignore b/.dockerignore index 7f0d3858..6a1e7891 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,7 @@ .github test test_data +output_folder **/*.nii.gz build **/build diff --git a/Dockerfile b/Dockerfile index 0fe3850c..fe659948 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,10 +42,11 @@ ARG MAMBA_DOCKERFILE_ACTIVATE=1 ARG CUDA_VERSION COPY --chown=$MAMBA_USER:$MAMBA_USER requirements.txt /tmp/requirements.txt +RUN grep -v -E '^(torch)' /tmp/requirements.txt > /tmp/requirements2.txt USER root RUN apt-get update && apt-get install -y python3-tk git USER $MAMBA_USER -RUN pip install --verbose -r /tmp/requirements.txt && pip uninstall -y torch && pip install --verbose torch==2.3.1 --index-url https://download.pytorch.org/whl/cu${CUDA_VERSION} +RUN pip install --verbose -r /tmp/requirements2.txt && pip uninstall -y torch && pip install --verbose torch==2.3.1 --index-url https://download.pytorch.org/whl/cu${CUDA_VERSION} RUN mkdir ~/dummyinput && mkdir ~/dummyoutput RUN git clone https://github.com/CBICA/PredCRD.git && cd PredCRD && pip install -e . RUN git clone https://github.com/CBICA/DLWMLS.git && cd DLWMLS && pip install -e . && DLWMLS -i ~/dummyinput -o ~/dummyoutput diff --git a/requirements.txt b/requirements.txt index fad0d6af..1ac934a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ spare-scores NiChartHarmonize DLICV DLMUSE -NiChart_DLMUSE +NiChart_DLMUSE>=1.0.9 DLWMLS @ git+https://github.com/CBICA/DLWMLS # general python dependencies diff --git a/src/viewer/pages/process_sMRI_DLMUSE.py b/src/viewer/pages/process_sMRI_DLMUSE.py index a72ced95..becd7653 100644 --- a/src/viewer/pages/process_sMRI_DLMUSE.py +++ b/src/viewer/pages/process_sMRI_DLMUSE.py @@ -177,7 +177,7 @@ def panel_dlmuse() -> None: with st.expander('View DLMUSE volumes'): df_dlmuse=pd.read_csv(st.session_state.paths["csv_dlmuse"]) - st.dataframe(df_files) + st.dataframe(df_dlmuse) s_title="DLMUSE Segmentation" s_text=""" diff --git a/src/viewer/utils/utils_session.py b/src/viewer/utils/utils_session.py index 867bacc7..0f8a117a 100644 --- a/src/viewer/utils/utils_session.py +++ b/src/viewer/utils/utils_session.py @@ -70,8 +70,6 @@ def init_session_state() -> None: else: st.session_state.has_cloud_session = False - ## REMOVE THIS - st.write(st.session_state.cloud_session_token) ################################### diff --git a/src/viewer/utils/utils_st.py b/src/viewer/utils/utils_st.py index c7d7a59c..d52745e9 100644 --- a/src/viewer/utils/utils_st.py +++ b/src/viewer/utils/utils_st.py @@ -213,7 +213,7 @@ def help_working_dir(): - On the desktop app, you can initiate a NiChart pipeline by selecting the **working directory** from a previously completed task. - - On the cloud app, the results are deleted in regular intervals, so they may not be available. + - On the cloud app, the results are deleted in regular intervals, so they may not be available if you come back later. """ ) col1, col2 = st.columns([0.5, 0.1]) From 33e58590bc30a67d8be89d49bd24ad10653629f5 Mon Sep 17 00:00:00 2001 From: Alexander Getka <59709326+AlexanderGetka-cbica@users.noreply.github.com> Date: Tue, 10 Dec 2024 12:45:24 -0500 Subject: [PATCH 4/4] Update .dockerignore --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index 6a1e7891..e416cced 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,5 @@ .github +.git test test_data output_folder