Spaces:
Sleeping
Sleeping
legend1234
commited on
Commit
•
e1092cb
1
Parent(s):
0fcf417
Use wide mode
Browse files
app.py
CHANGED
@@ -5,22 +5,34 @@ from io import StringIO
|
|
5 |
import joblib
|
6 |
import numpy as np
|
7 |
import pandas as pd
|
|
|
|
|
8 |
import streamlit as st
|
9 |
from b3clf.descriptor_padel import compute_descriptors
|
10 |
from b3clf.geometry_opt import geometry_optimize
|
11 |
-
from b3clf.utils import (
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
from streamlit_ketcher import st_ketcher
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Load the pre-trained model and feature scaler
|
18 |
-
model = joblib.load(
|
19 |
-
|
20 |
-
)
|
21 |
-
scaler = joblib.load(
|
22 |
-
"pre_trained/b3clf_scaler.joblib"
|
23 |
-
)
|
24 |
|
25 |
|
26 |
# Define a function to generate predictions
|
@@ -82,7 +94,6 @@ def generate_predictions(
|
|
82 |
# Get computed descriptors
|
83 |
X_features, info_df = get_descriptors(df=df_features)
|
84 |
|
85 |
-
|
86 |
# Select descriptors
|
87 |
X_features = select_descriptors(df=X_features)
|
88 |
|
@@ -124,10 +135,11 @@ st.title("BBB Permeability Prediction with Imbalanced Learning")
|
|
124 |
# Create a file uploader
|
125 |
|
126 |
st.subheader("Input Data")
|
127 |
-
file = st.file_uploader(
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
131 |
# st.write("The content of the file will be displayed below once uploaded.")
|
132 |
if file:
|
133 |
# if "csv" in file.name or "txt" in file.name:
|
@@ -141,7 +153,7 @@ if file:
|
|
141 |
# Create a temporary file path for the uploaded file
|
142 |
temp_file_path = os.path.join(temp_dir, file.name)
|
143 |
# Save the uploaded file to the temporary file path
|
144 |
-
with open(temp_file_path,
|
145 |
temp_file.write(file.read())
|
146 |
X_features, results = generate_predictions(temp_file_path)
|
147 |
|
@@ -162,5 +174,7 @@ if file:
|
|
162 |
predictions_csv = results.to_csv(index=False)
|
163 |
results_file_name = file.name.split(".")[0] + "_b3clf_predictions.csv"
|
164 |
st.download_button(
|
165 |
-
"Download predictions as CSV",
|
|
|
|
|
166 |
)
|
|
|
5 |
import joblib
|
6 |
import numpy as np
|
7 |
import pandas as pd
|
8 |
+
|
9 |
+
# page set up
|
10 |
import streamlit as st
|
11 |
from b3clf.descriptor_padel import compute_descriptors
|
12 |
from b3clf.geometry_opt import geometry_optimize
|
13 |
+
from b3clf.utils import (
|
14 |
+
get_descriptors,
|
15 |
+
predict_permeability,
|
16 |
+
scale_descriptors,
|
17 |
+
select_descriptors,
|
18 |
+
)
|
19 |
from streamlit_ketcher import st_ketcher
|
20 |
|
21 |
+
st.set_page_config(
|
22 |
+
page_title="BBB Permeability Prediction with Imbalanced Learning",
|
23 |
+
page_icon="🧊",
|
24 |
+
layout="wide",
|
25 |
+
# initial_sidebar_state="expanded",
|
26 |
+
# menu_items={
|
27 |
+
# 'Get Help': 'https://www.extremelycoolapp.com/help',
|
28 |
+
# 'Report a bug': "https://www.extremelycoolapp.com/bug",
|
29 |
+
# 'About': "# This is a header. This is an *extremely* cool app!"
|
30 |
+
# }
|
31 |
+
)
|
32 |
|
33 |
# Load the pre-trained model and feature scaler
|
34 |
+
model = joblib.load("pre_trained/b3clf_knn_kmeans_SMOTE.joblib")
|
35 |
+
scaler = joblib.load("pre_trained/b3clf_scaler.joblib")
|
|
|
|
|
|
|
|
|
36 |
|
37 |
|
38 |
# Define a function to generate predictions
|
|
|
94 |
# Get computed descriptors
|
95 |
X_features, info_df = get_descriptors(df=df_features)
|
96 |
|
|
|
97 |
# Select descriptors
|
98 |
X_features = select_descriptors(df=X_features)
|
99 |
|
|
|
135 |
# Create a file uploader
|
136 |
|
137 |
st.subheader("Input Data")
|
138 |
+
file = st.file_uploader(
|
139 |
+
"Upload a CSV or SDF file",
|
140 |
+
type=["csv", "sdf", "txt"],
|
141 |
+
# accept_multiple_files=False,
|
142 |
+
)
|
143 |
# st.write("The content of the file will be displayed below once uploaded.")
|
144 |
if file:
|
145 |
# if "csv" in file.name or "txt" in file.name:
|
|
|
153 |
# Create a temporary file path for the uploaded file
|
154 |
temp_file_path = os.path.join(temp_dir, file.name)
|
155 |
# Save the uploaded file to the temporary file path
|
156 |
+
with open(temp_file_path, "wb") as temp_file:
|
157 |
temp_file.write(file.read())
|
158 |
X_features, results = generate_predictions(temp_file_path)
|
159 |
|
|
|
174 |
predictions_csv = results.to_csv(index=False)
|
175 |
results_file_name = file.name.split(".")[0] + "_b3clf_predictions.csv"
|
176 |
st.download_button(
|
177 |
+
"Download predictions as CSV",
|
178 |
+
data=predictions_csv,
|
179 |
+
file_name=results_file_name,
|
180 |
)
|