From 5b6962407826c571b8d19deecf93dbff41c1629c Mon Sep 17 00:00:00 2001 From: Nicolas Barthes <nicolas.barthes@cnrs.fr> Date: Wed, 5 Jun 2024 12:18:16 +0200 Subject: [PATCH] added automated simple interface with default values --- src/pages/1-samples_selection.py | 56 +++++++++++++++++++------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/pages/1-samples_selection.py b/src/pages/1-samples_selection.py index a30e15e..aae214b 100644 --- a/src/pages/1-samples_selection.py +++ b/src/pages/1-samples_selection.py @@ -1,8 +1,9 @@ from Packages import * st.set_page_config(page_title="NIRS Utils", page_icon=":goat:", layout="wide") from Modules import * -repertoire_a_vider = 'D:/Mouhcine/nirs_workflow/src/Report/figures' +# empty temp figures +repertoire_a_vider = 'D:/Mouhcine/nirs_workflow/src/Report/figures' if os.path.exists(repertoire_a_vider): for fichier in os.listdir(repertoire_a_vider): chemin_fichier = os.path.join(repertoire_a_vider, fichier) @@ -11,27 +12,40 @@ if os.path.exists(repertoire_a_vider): elif os.path.isdir(chemin_fichier): shutil.rmtree(chemin_fichier) # HTML pour le bandeau "CEFE - CNRS" -# bandeau_html = """ -# <div style="width: 100%; background-color: #4682B4; padding: 10px; margin-bottom: 10px;"> -# <h1 style="text-align: center; color: white;">CEFE - CNRS</h1> -# </div> -# """ -# # Injecter le code HTML du bandeau -# st.markdown(bandeau_html, unsafe_allow_html=True) add_header() +#load specific model page css +local_css(css_file / "style_model.css") + +#define some variables tcr=pd.DataFrame() sam=pd.DataFrame() sam1=pd.DataFrame() +dim_red_methods=['', 'PCA','UMAP', 'NMF'] # List of dimensionality reduction algos +cluster_methods = ['', 'Kmeans','HDBSCAN', 'AP'] # List of clustering algos +selec_strategy = ['center','random'] -# path = os.path.dirname(os.path.abspath(__file__)).replace('\\','/') -# css_file = path[:path.find('/pages')]+'/style' -# local_css(css_file +"/style_model.css") -local_css(css_file / "style_model.css") - +# check session state and define default values if simple interface to automate processing st.session_state["interface"] = st.session_state.get('interface') if st.session_state["interface"] == 'simple': + st.write(':red[Automated Simple Interface]') hide_pages("Predictions") - + if 37 not in st.session_state: + default_reduction_option = 1 + else: + default_reduction_option = dim_red_methods.index(st.session_state.get(37)) + if 38 not in st.session_state: + default_clustering_option = 1 + else: + default_clustering_option = cluster_methods.index(st.session_state.get(38)) + if 102 not in st.session_state: + default_sample_selection_option = 1 + else: + default_sample_selection_option = selec_strategy.index(st.session_state.get(102)) + +if st.session_state["interface"] == 'advanced': + default_reduction_option = 0 + default_clustering_option = 0 + default_sample_selection_option = 0 ################################### I - Data Loading and Visualization ######################################## st.header("I - Spectral Data Visualization", divider='blue') @@ -111,9 +125,6 @@ scores, loadings, pc = st.columns([2, 3, 0.5]) influence, hotelling, qexp = st.columns([2, 2, 1]) st.header('III - Selected samples for chemical analysis', divider='blue') -dim_red_methods=['', 'PCA','UMAP', 'NMF'] # List of dimensionality reduction algos -cluster_methods = ['', 'Kmeans','HDBSCAN', 'AP'] # List of clustering algos - dr_model = None # dimensionality reduction model cl_model = None # clustering model @@ -122,8 +133,8 @@ t = pd.DataFrame # scores p = pd.DataFrame # loadings labels = [] if not spectra.empty: - dim_red_method = pc.selectbox("Dimensionality reduction techniques: ", options = dim_red_methods, key = 37) - clus_method = pc.selectbox("Clustering techniques: ", options = cluster_methods, key = 38) + dim_red_method = pc.selectbox("Dimensionality reduction techniques: ", options = dim_red_methods, index = default_reduction_option, key = 37) + clus_method = pc.selectbox("Clustering techniques: ", options = cluster_methods, index = default_clustering_option, key = 38) xc = standardize(spectra, center=True, scale=False) @@ -196,7 +207,6 @@ if not t.empty: #################################################### III - Samples selection using the reduced data preentation ###### -selec_strategy = ['center','random'] samples_df_chem = pd.DataFrame selected_samples = [] selected_samples_idx = [] @@ -205,7 +215,7 @@ selected_samples_idx = [] if labels: if clus_method: selection = scores.radio('Select samples selection strategy:', - options = selec_strategy) + options = selec_strategy, index = default_sample_selection_option, key=102) # Strategy 0 if selection == selec_strategy[0]: # list samples at clusters centers - Use sklearn.metrics.pairwise_distances_argmin if you want more than 1 sample per cluster @@ -499,8 +509,8 @@ Ac_Km = ['Spectra_Plot.png', 'Elbow.png', 'graphe_loadings.png', 'plot_axe1_axe2 # Streamlit container with st.container(): - header3, header4 = st.columns(2) - if header3.button("Exporter le rapport"): + header3, = st.columns(1) + if header3.button("Export report"): if test == '.csv': if dim_red_method == dim_red_methods[1] and clus_method == cluster_methods[1]: latex_report = report.report(sam, tcr, Nb_ech, nb_clu, 'sample', Ac_Km, 'csv', 'kmeans') -- GitLab