diff --git a/requirements.txt b/requirements.txt index c42848895198cdbf17d9284170252cec259d9d4a..dcac89731bbf231676fe94219f13555f37580105 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ Pillow>=8.4.0 protobuf>=3.19.0 watchdog>=2.1.8 pinard>=1.0 -julia>=0.6.2 +juliacall>=0.9.19 plotly>=5.20.0 pyodbc>=5.1.0 matplotlib>=3.8.4 diff --git a/src/Class_Mod/LWPLSR_.py b/src/Class_Mod/LWPLSR_.py index b5c7e499d3b10863fde0edb4bca63fbe69da683d..e5682ac39c37e85dd6871faf0e1646b5c5626e30 100644 --- a/src/Class_Mod/LWPLSR_.py +++ b/src/Class_Mod/LWPLSR_.py @@ -1,3 +1,5 @@ +import pandas as pd +import streamlit from Packages import * from Class_Mod.Miscellaneous import * @@ -9,42 +11,56 @@ class LWPLSR: """Initiate the LWPLSR and prepare data for Julia computing.""" self.x_train, self.y_train, self.x_test, self.y_test = x_train, x_test, y_train, y_test # prepare to send dataframes to julia and Jchemo - self.Main.x_train,self.Main.y_train,self.Main.x_test,self.Main.y_test = self.x_train, self.y_train, self.x_test, self.y_test + jl.x_train,jl.y_train,jl.x_test,jl.y_test = self.x_train, self.y_train, self.x_test, self.y_test + self.scores = pd.DataFrame + self.predicted_results_on_test = pd.DataFrame def Jchemo_lwplsr(self): """Send data to Julia to compute lwplsr. Args: - self.Main.x_train (DataFrame): - self.Main.y_train (DataFrame): - self.Main.x_test (DataFrame): - self.Main.y_test (DataFrame): + self.jl.x_train (DataFrame): + self.jl.y_train (DataFrame): + self.jl.x_test (DataFrame): + self.jl.y_test (DataFrame): Returns: self.scores (DataFrame): various metrics and scores self.predicted_results_on_test (DataFrame): """ # launch Julia Jchemo lwplsr - Main.eval(""" - #convert python pd.dataframes to julia dataframes - x_train_j = self.Main.x_train |> Pandas.DataFrame|> DataFrames.DataFrame; - y_train_j = self.Main.y_train |> Pandas.DataFrame|> DataFrames.DataFrame; - x_test_j = self.Main.x_test |> Pandas.DataFrame|> DataFrames.DataFrame; - y_test_j = self.Main.y_test |> Pandas.DataFrame|> DataFrames.DataFrame; - # Compute model + jl.eval(""" + using Pandas + using DataFrames + using Jchemo nlvdis = 5 ; metric = :mah h = 1 ; k = 200 ; nlv = 15 #; scal = true - mod = Main.Jchemo.model(Main.Jchemo.lwplsr; nlvdis, metric, h, k, nlv) - Main.Jchemo.fit!(mod, X_train_j, y_train_j) + mod = Jchemo.model(Jchemo.lwplsr; nlvdis, metric, h, k, nlv) + Jchemo.fit!(mod, X_train, y_train) + # Jchemo.pnames(mod) + # Jchemo.pnames(mod.fm) # predictions on test data calculation - res = Main.Jchemo.predict(mod, X_test_j) ; - scores = Main.Jchemo.mse(res.pred, y_test_j) - scoresjp = Pandas.DataFrame(scores); - resjp = Pandas.DataFrame(res.pred); + res = Jchemo.predict(mod, X_test) + # Jchemo.pnames(res) """) - self.scores = self.Main.scoresjp - self.predicted_results_on_test = pd.DataFrame(self.Main.resjp) + resjp = jl.seval(""" + Pandas.DataFrame(res.pred) + """) + scoresjp = jl.seval(""" + Jchemo.mse(res.pred, y_test) + """) + self.scores = pd.Dataframe(scoresjp) + self.predicted_results_on_test = pd.Dataframe(resjp) + + @property + def pred_data_(self): + return self.predicted_results_on_test, self.predicted_results_on_test, self.predicted_results_on_test + + # @property + # def model_(self): + # return self.trained @property - def scores_(self): - return self.scores, self.predicted_results_on_test \ No newline at end of file + def metrics_(self): + # self.scores = pd.DataFrame(self.scores, index=['test']) + return self.scores \ No newline at end of file diff --git a/src/Modules.py b/src/Modules.py index 5de6b6f793e062505b1ac79483954c92a487bda5..47dc8ed9437332c70126e557e9ae6a76aedb5123 100644 --- a/src/Modules.py +++ b/src/Modules.py @@ -1,5 +1,5 @@ from Class_Mod import PlsR, LinearPCA, Umap, find_col_index, PinardPlsr from Class_Mod import LWPLSR, list_files, metrics, TpeIpls, reg_plot, resid_plot, Sk_Kmeans, DxRead, Hdbscan, read_dx -# find_col_index from Class_Mod.Miscellaneous import prediction, download_results, plot_spectra +from style.header import add_header \ No newline at end of file diff --git a/src/Packages.py b/src/Packages.py index a05a7a33be587f8e934698637e2e010fcbbed021..c7bf15dcdb6ef8ba2320d02ee4477c6c00f4ad5b 100644 --- a/src/Packages.py +++ b/src/Packages.py @@ -25,8 +25,7 @@ from scipy.sparse.csgraph import minimum_spanning_tree from scipy.sparse import csgraph # Modelling -# import julia -#from julia import Main, Jchemo, DataFrames, Base, Pandas +from juliacall import Main as jl from pinard import utils from pinard import preprocessing as pp diff --git a/src/app.py b/src/app.py index 9b63fe162aa26ebce48e20c0d918e79b41b0c779..0ec3af010fb29c358eb9c9c12601849bf8a37c59 100644 --- a/src/app.py +++ b/src/app.py @@ -7,14 +7,15 @@ from Class_Mod.DATA_HANDLING import * # 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> -""" +# 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) +# st.markdown(bandeau_html, unsafe_allow_html=True) +add_header() # # TOC menu on the left show_pages( @@ -44,9 +45,7 @@ with st.sidebar: Page("pages\\1-samples_selection.py", "Samples Selection"), Page("pages\\2-model_creation.py", "Models Creation"), Page("pages\\3-prediction.py", "Predictions"), - - - ] + ] ) st.page_link('pages\\2-model_creation.py') st.page_link('pages\\3-prediction.py') @@ -55,30 +54,30 @@ with st.sidebar: # Page header with st.container(): - # Centrer les boutons - st.markdown( - """ - <style> - .stButton>button { - display: block; - margin: 0 auto; - width: 200px; - height: 50px; - font-size: 16px; - } - </style> - """, - unsafe_allow_html=True - ) + # Centrer les boutons - CODE DEPLACE dans le style/style.css + # st.markdown( + # """ + # <style> + # .stButton>button { + # display: block; + # margin: 0 auto; + # width: 200px; + # height: 50px; + # font-size: 16px; + # } + # </style> + # """, + # unsafe_allow_html=True + # ) header1, header2, header3,header4 = st.columns(4) - if header3.button("Inputs"): + if header1.button("Inputs"): st.switch_page('pages\\4-inputs.py') - if header1.button("Samples Selection"): + if header2.button("Samples Selection"): st.switch_page('pages\\1-samples_selection.py') - if header2.button("Model Creation"): + if header3.button("Models Creation"): st.switch_page('pages\\2-model_creation.py') - if header3.button("Predictions"): + if header4.button("Predictions"): st.switch_page('pages\\3-prediction.py') st.subheader("Plateforme d'Analyses Chimiques pour l'Ecologie-PACE :goat:") st.title("NIRS Utils") diff --git a/src/pages/1-samples_selection.py b/src/pages/1-samples_selection.py index fd13d437fd63f4e729c7d0d58180aca9af6db37b..8b33b5f16c78cb57c43520476311ad99f3b94070 100644 --- a/src/pages/1-samples_selection.py +++ b/src/pages/1-samples_selection.py @@ -6,13 +6,15 @@ from Class_Mod.DATA_HANDLING import * # 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) +# 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() + st.session_state["interface"] = st.session_state.get('interface') if st.session_state["interface"] == 'simple': diff --git a/src/pages/2-model_creation.py b/src/pages/2-model_creation.py index 2b08fda6f3b1851fe04172044adc76e300c6f3a6..8b0ea6ec6453e613c6016c4bf99c47e1a0cc9023 100644 --- a/src/pages/2-model_creation.py +++ b/src/pages/2-model_creation.py @@ -5,13 +5,15 @@ from Class_Mod.DATA_HANDLING import * # 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 / UM</h1> -</div> -""" -# Injecter le code HTML du bandeau -st.markdown(bandeau_html, unsafe_allow_html=True) +# bandeau_html = """ +# <div style="width: 100%; background-color: #4682B4; padding: 10px; margin-bottom: 10px;"> +# <h1 style="text-align: center; color: white;">CEFE - CNRS / UM</h1> +# </div> +# """ +# # Injecter le code HTML du bandeau +# st.markdown(bandeau_html, unsafe_allow_html=True) +add_header() + st.session_state["interface"] = st.session_state.get('interface') if st.session_state["interface"] == 'simple': diff --git a/src/pages/3-prediction.py b/src/pages/3-prediction.py index 3dc0c0e292d20724e10196a8a50545bc5f6c1ba2..1720334bb94cc9da8d8eb97e032b1c340b0ec2b9 100644 --- a/src/pages/3-prediction.py +++ b/src/pages/3-prediction.py @@ -3,13 +3,15 @@ st.set_page_config(page_title="NIRS Utils", page_icon=":goat:", layout="wide") from Modules import * from Class_Mod.DATA_HANDLING import * # 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) +# 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() + st.session_state["interface"] = st.session_state.get('interface') diff --git a/src/pages/4-inputs.py b/src/pages/4-inputs.py index 1818915adfcc5f7be02cdf9835d5893b29667b1f..439c3bf6d04763eda9454e440408be504898c9e5 100644 --- a/src/pages/4-inputs.py +++ b/src/pages/4-inputs.py @@ -2,15 +2,16 @@ import streamlit as st # HTML for the banner "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> -""" - - -# Inject the HTML code for the banner -st.markdown(bandeau_html, unsafe_allow_html=True) +# 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> +# """ +# +# +# # Inject the HTML code for the banner +# st.markdown(bandeau_html, unsafe_allow_html=True) +add_header() # Initialize session state diff --git a/src/style/header.py b/src/style/header.py new file mode 100644 index 0000000000000000000000000000000000000000..b91bf42a0dc1ae6b56cd69d1a2c9a726e19e2fdf --- /dev/null +++ b/src/style/header.py @@ -0,0 +1,11 @@ +from Packages import * +def add_header(): + st.markdown( + """ + <div style="width: 100%; background-color: #4682B4; padding: 10px; margin-bottom: 10px;"> + <h1 style="text-align: center; color: white;">PACE - MEEB / CEFE</h1> + <h2 style="text-align: center; color: white;">NIRS Utils</h2> + </div> + """, + unsafe_allow_html=True, + ) \ No newline at end of file diff --git a/src/style/style.css b/src/style/style.css index aa4b4bfccb7c1757dbfa6b50b00b5076f02e01fb..4e4b4a10a709f534be614e1c91f4534a59ea9e30 100644 --- a/src/style/style.css +++ b/src/style/style.css @@ -4,3 +4,11 @@ #MainMenu {visibility: hidden;} footer {visibility: hidden;} header {visibility: hidden;} + +.stButton>button { + display: block; + margin: 0 auto; + width: 200px; + height: 50px; + font-size: 16px; +} \ No newline at end of file