diff --git a/src/app.py b/src/app.py index 07edda00120c3c439a30b56bb91f75f11d3e73ff..c10bab39826b923a889af1cbf9ba8f209a9f9a9b 100644 --- a/src/app.py +++ b/src/app.py @@ -4,13 +4,10 @@ st.set_page_config(page_title="NIRS Utils", page_icon=":goat:", layout="wide") -# page layout -BackgroundImg(change = None) -add_header() -add_sidebar(pages_folder) -local_css(css_file / "style_app.css") - +# layout +UiComponents(pagespath = pages_folder, csspath= css_file,imgpath=image_path , + header=True, sidebar= True, bgimg=True, colborders=False) # Page affiliation diff --git a/src/common.py b/src/common.py index c7bd9cab2f270cbc6d3586fb368c527bd33e913a..de93c5153dc7e2700f09808b1101c04b01a51f2e 100644 --- a/src/common.py +++ b/src/common.py @@ -12,13 +12,14 @@ import streamlit as st from pathlib import Path -css_file = Path("style/") +css_file = Path("style/style_model.css") pages_folder = Path("pages/") +image_path = Path('./images/img-sky.jpg') from utils.data_parsing import JcampParser, CsvParser -from style.layout import BackgroundImg, add_header, add_sidebar, local_css +from style.layout import UiComponents from utils.data_handling import * from utils.data_parsing import * from utils.hash import * diff --git a/src/pages/0-inputs.py b/src/pages/0-inputs.py index c168653b1aaa6e5f056ce0f342f6ff2a5bf227cc..920ea78f17a14d5e77f4a7ec8970ca0df971542f 100644 --- a/src/pages/0-inputs.py +++ b/src/pages/0-inputs.py @@ -5,11 +5,10 @@ st.set_page_config(page_title="NIRS Utils", page_icon=":goat:", layout="wide") +# layout +UiComponents(pagespath = pages_folder, csspath= css_file,imgpath=image_path , + header=True, sidebar= True, bgimg=True, colborders=False) -# page layout -add_header() -add_sidebar(pages_folder) -local_css(css_file / "style_app.css") # Initialize session state diff --git a/src/pages/1-samples_selection.py b/src/pages/1-samples_selection.py index a534e62a28320aa239170c1a80af7f8aaa57c54b..ed2464f52a1410110740ced89d568b3a21f4e111 100644 --- a/src/pages/1-samples_selection.py +++ b/src/pages/1-samples_selection.py @@ -1,24 +1,20 @@ from common import * st.set_page_config(page_title="NIRS Utils", page_icon=":goat:", layout="wide") -local_css(css_file / "style_model.css")#load specific model page css - - - -# page layout -add_header() -add_sidebar(pages_folder) -local_css(css_file / "style_app.css") +# layout +UiComponents(pagespath = pages_folder, csspath= css_file,imgpath=image_path , + header=True, sidebar= True, bgimg=False, colborders=True) st.header("Calibration Subset Selection") # page title st.markdown("Create a predictive model, then use it for predicting your target variable (chemical data) from NIRS spectra") c1, c2 = st.columns([3, 1]) c1.image("./images/sample selection.png", use_column_width=True) # graphical abstract + # empty temp figures report_path = Path("report") report_path_rel = Path("./report") diff --git a/src/pages/2-model_creation.py b/src/pages/2-model_creation.py index 5f5b86fdb421fccb5987d0747edf51ffd393f775..26aa959d7ae221979b5c0264b75d780c7d3b82a8 100644 --- a/src/pages/2-model_creation.py +++ b/src/pages/2-model_creation.py @@ -1,12 +1,13 @@ -from packages import * -st.set_page_config(page_title = "NIRS Utils", page_icon = ":goat:", layout = "wide") from common import * -local_css(css_file / "style_model.css")#load specific model page css +st.set_page_config(page_title = "NIRS Utils", page_icon = ":goat:", layout = "wide") + -from utils.data_handling import * +# layout +UiComponents(pagespath = pages_folder, csspath= css_file,imgpath=image_path , + header=True, sidebar= True, bgimg=False, colborders=True) hash_ = '' def p_hash(add): diff --git a/src/style/__init__.py b/src/style/__init__.py index 9cc5331717b294ef3d29278bc63b6612b96f890d..7b243b70c72df00a486026812a9e540db67b5f7c 100644 --- a/src/style/__init__.py +++ b/src/style/__init__.py @@ -1 +1 @@ -from .layout import add_header, add_sidebar \ No newline at end of file +from .layout import UiComponents \ No newline at end of file diff --git a/src/style/layout.py b/src/style/layout.py index f4fe35f5bc2f2b9e89fe8f8a53754c0ccdb6f290..0d1dc990cfd79de13e978e8d31a75690a3a92866 100644 --- a/src/style/layout.py +++ b/src/style/layout.py @@ -1,104 +1,93 @@ # from packages import * import streamlit as st -## load the custom CSS in the style folder -@st.cache_data -def local_css(file_name): +def UiComponents(pagespath, csspath, imgpath, header = True, sidebar = True, bgimg = True, colborders = True): import streamlit as st - with open(file_name) as f: - st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True) - #~~~~~~~~~~~~~~~~~~~~~~~~~~~ background image ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@st.cache_data -def BackgroundImg(change): - import base64 - import streamlit as st - image_path = './images/img-sky.jpg' - with open(image_path, "rb") as image_file: - base64_image= base64.b64encode(image_file.read()).decode('utf-8') - - - # CSS code to set the background image - # Get the base64-encoded image + if header == True: + st.markdown( + """ + <div style="width: 100%;height: 170px; background-color: rgb(0,0,0,0);border: 4px solid rgb(122,176,199); padding: 0px; margin-bottom: 10px;border-radius: 20%; "> + <h1 style="font-family: 'Arial',d;text-align: center; color: #39bf55;">PACE - MEEB / CEFE</h1> + <h2 style="font-family: 'Arial';text-align: center; color: #2cb048;">NIRS Utils</h2> + </div> + """, + unsafe_allow_html=True + ) - # CSS code to set the background image - background_image_style = f""" - <style> - .stApp {{ - background-image: url("data:image/jpeg;base64,{base64_image}"); - background-size: cover; - background-repeat: no-repeat; - background-attachment: fixed; - }} - </style> - """ + st.markdown(""" + <style> + .block-container { + padding-top: 3rem; + padding-bottom: 0rem; + padding-left: 5rem; + padding-right: 5rem; + } + </style> + """, + unsafe_allow_html=True + ) + + if sidebar == True: + from st_pages import Page, show_pages + # from st_pages import Page, Section, show_pages, add_page_title, hide_pages - # Inject the CSS style - st.markdown(background_image_style, unsafe_allow_html=True) + if 'interface' not in st.session_state: + st.session_state['interface'] = 'simple' + else: + st.session_state["interface"] = st.session_state.get('interface') - #~~~~~~~~~~~~~~~~~~~~~~~~~~~ add header ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # # TOC menu on the left + show_pages( + [Page("app.py", "Home"), + Page(str(pagespath / "0-inputs.py"), "Inputs"), + Page(str(pagespath / "1-samples_selection.py"), "Samples Selection"), + Page(str(pagespath / "2-model_creation.py"), "Models Creation & Predictions"), -def add_header(): - import streamlit as st - st.markdown( - """ - <div style="width: 100%;height: 170px; background-color: rgb(0,0,0,0);border: 4px solid rgb(122,176,199); padding: 0px; margin-bottom: 10px;border-radius: 20%; "> - <h1 style="font-family: 'Arial',d;text-align: center; color: #39bf55;">PACE - MEEB / CEFE</h1> - <h2 style="font-family: 'Arial';text-align: center; color: #2cb048;">NIRS Utils</h2> - </div> - """, - unsafe_allow_html=True, - ) + ] + ) - st.markdown(""" - <style> - .block-container { - padding-top: 3rem; - padding-bottom: 0rem; - padding-left: 5rem; - padding-right: 5rem; - } - </style> - """, unsafe_allow_html=True) + with st.sidebar: + interface = st.radio(label="Interface", options=['simple', 'advanced'], key='interface') + # st.page_link(str(pages_folder / '1-samples_selection.py')) + if st.session_state['interface'] == 'simple': + # st.page_link(str(pages_folder / '2-model_creation.py')) + pass + # if advanced interface, split Models Creation and Predictions + elif st.session_state['interface'] == 'advanced': + show_pages( + [Page("app.py", "Home"), + Page(str(pagespath / "0-inputs.py"), "Inputs"), + Page(str(pagespath / "1-samples_selection.py"), "Samples Selection"), + Page(str(pagespath / "2-model_creation.py"), "Models Creation"), + Page(str(pagespath / "3-prediction.py"), "Predictions"), + ] + ) - #~~~~~~~~~~~~~~~~~~~~~~~~~~~ add sidebar ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -def add_sidebar(pages_folder): - import streamlit as st - from st_pages import Page, show_pages - # from st_pages import Page, Section, show_pages, add_page_title, hide_pages - - - if 'interface' not in st.session_state: - st.session_state['interface'] = 'simple' - else: - st.session_state["interface"] = st.session_state.get('interface') + if colborders == True: + import streamlit as st + with open(csspath) as f: + st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True) + + if bgimg == True: + import base64 + with open(imgpath, "rb") as image_file: + base64_image= base64.b64encode(image_file.read()).decode('utf-8') - # # TOC menu on the left - show_pages( - [Page("app.py", "Home"), - Page(str(pages_folder / "0-inputs.py"), "Inputs"), - Page(str(pages_folder / "1-samples_selection.py"), "Samples Selection"), - Page(str(pages_folder / "2-model_creation.py"), "Models Creation & Predictions"), + # CSS code to set the background image + # Get the base64-encoded image - ] - ) + # CSS code to set the background image + background_image_style = f""" + <style> + .stApp {{ + background-image: url("data:image/jpeg;base64,{base64_image}"); + background-size: cover; + background-repeat: no-repeat; + background-attachment: fixed; + }} + </style> + """ - with st.sidebar: - interface = st.radio(label="Interface", options=['simple', 'advanced'], key='interface') - # st.page_link(str(pages_folder / '1-samples_selection.py')) - if st.session_state['interface'] == 'simple': - # st.page_link(str(pages_folder / '2-model_creation.py')) - pass - # if advanced interface, split Models Creation and Predictions - elif st.session_state['interface'] == 'advanced': - show_pages( - [Page("app.py", "Home"), - Page(str(pages_folder / "0-inputs.py"), "Inputs"), - Page(str(pages_folder / "1-samples_selection.py"), "Samples Selection"), - Page(str(pages_folder / "2-model_creation.py"), "Models Creation"), - Page(str(pages_folder / "3-prediction.py"), "Predictions"), - ] - ) - # st.page_link(str(pages_folder / '2-model_creation.py')) - # st.page_link(str(pages_folder / '3-prediction.py')) + # Inject the CSS style + st.markdown(background_image_style, unsafe_allow_html=True) \ No newline at end of file