From dca4969004ad97de4b9fbdc8e972b9a7cef6dab4 Mon Sep 17 00:00:00 2001
From: barthes <nicolas.barthes@cefe.cnrs.fr>
Date: Tue, 26 Mar 2024 15:43:13 +0100
Subject: [PATCH] updated requirements.txt updated .gitignore for .streamlit
 config folder

---
 .gitignore               |  1 -
 app.py                   | 15 ++++++++-------
 application_functions.py |  2 ++
 requirements.txt         |  3 ++-
 4 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/.gitignore b/.gitignore
index b2c0c60..56516f3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
 .idea/
-.streamlit/
 GUI_Pinard.iml
 __pycache__/
\ No newline at end of file
diff --git a/app.py b/app.py
index 708e629..8338188 100644
--- a/app.py
+++ b/app.py
@@ -70,7 +70,7 @@ with st.container():
                 categorical_variable_2 = settings_column.selectbox("Second Variable Select (hover data)", options = cat_cols)
                 plot_pc = scatter_column.plotly_chart(px.scatter(data_frame=pc_data, x=pc_1, y=pc_2, template="simple_white", height=800, color=categorical_variable, hover_data = [categorical_variable_2], hover_name=pc_data.index, title="PC plot of sample spectra"))
             # Clustering method
-            cluster_type = ['', 'k-means']
+            cluster_type = ['', 'k-means', 'umap']
             # cluster_type = ['k-means', 'umap'] # uncomment if more clustering algorithms available
             type_cluster = settings_column.selectbox("Clustering method: ", options=cluster_type, key=38)
             # clustering via K-Means
@@ -130,7 +130,7 @@ with st.container():
                     pd.DataFrame(export).T.to_csv('./data/sample_selections/Samples_from_' + sselectx_csv.name + '_for_Chemical_Analysis.csv')
             else:
                 scatter_column.write("_Please Choose a file_")
-            # clustering via UMAP / HDBSCAN
+            # clustering via UMAP / HDBSCAN -- TO BE DONE !!!
             if type_cluster == 'umap':
                 import hdbscan
                 # plot de pc with colored clusters and selected samples
@@ -204,16 +204,17 @@ with st.container():
                 model_column.write('Model Imported')
     result = ''
     if st.button("Predict"):
+        # use prediction function from application_functions.py to predict chemical values
         result = prediction(NIRS_csv, qsep, qhdr, model_loaded)
         st.write('Predicted values are: ')
         st.dataframe(result)
         pd.DataFrame(result).to_csv(export_name + '.csv')
         st.write('Predictions exported to ' + export_name + '.csv')
-        # # export to local drive
-        # from urllib.request import urlretrieve
-        # url = ('http://localhost:8501' + export_name[1:] + '.csv')
-        # filename = export_name + '.csv'
-        # urlretrieve(url, filename)
+        # export to local drive
+        from urllib.request import urlretrieve
+        url = ('http://localhost:8501' + export_name[1:] + '.csv')
+        filename = export_name + '.csv'
+        urlretrieve(url, filename)
         # create a report with information on the prediction
         ## see https://stackoverflow.com/a/59578663
     if type(result) is list:
diff --git a/application_functions.py b/application_functions.py
index d4ff907..caecb1c 100644
--- a/application_functions.py
+++ b/application_functions.py
@@ -193,4 +193,6 @@ def list_files(mypath, import_type):
     from os import listdir
     from os.path import isfile, join
     list_files = [f for f in listdir(mypath) if isfile(join(mypath, f)) and f.endswith(import_type + '.pkl')]
+    if list_files == []:
+        list_files = ['Please, create a model before - no model available yet']
     return list_files
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index b833c6c..6afe88c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,4 +4,5 @@ Pillow>=8.4.0
 protobuf>=3.19.0
 watchdog>=2.1.8
 pinard>=1.0
-julia>=0.6.2
\ No newline at end of file
+julia>=0.6.2
+plotly>=5.20.0
\ No newline at end of file
-- 
GitLab