Spaces:
Sleeping
Sleeping
first push
Browse files- src/streamlit_app.py +13 -25
src/streamlit_app.py
CHANGED
|
@@ -9,24 +9,21 @@ from sklearn.neighbors import KNeighborsClassifier
|
|
| 9 |
from sklearn.tree import DecisionTreeClassifier
|
| 10 |
from sklearn.metrics import accuracy_score, r2_score
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
UPLOAD_DIR = "
|
| 14 |
-
PROCESSED_DIR = "
|
| 15 |
-
PKL_DIR = "
|
| 16 |
-
ENCODERS_DIR = "
|
| 17 |
|
| 18 |
-
# Create
|
| 19 |
for folder in [UPLOAD_DIR, PROCESSED_DIR, PKL_DIR, ENCODERS_DIR]:
|
| 20 |
os.makedirs(folder, exist_ok=True)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
# Warn if directories don't exist
|
| 24 |
-
for folder in [UPLOAD_DIR, PROCESSED_DIR, PKL_DIR, ENCODERS_DIR]:
|
| 25 |
-
if not os.path.exists(folder):
|
| 26 |
-
st.warning(f"Directory not found: {folder}. Please create it before using this app.")
|
| 27 |
-
|
| 28 |
st.sidebar.title("Navigation")
|
| 29 |
-
page = st.sidebar.selectbox(
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# ========================
|
| 32 |
# Upload File Page
|
|
@@ -54,10 +51,7 @@ if page == "Upload File":
|
|
| 54 |
# ========================
|
| 55 |
elif page == "Preprocess Data":
|
| 56 |
st.title("Preprocess Uploaded CSV")
|
| 57 |
-
|
| 58 |
-
files = [f for f in os.listdir(UPLOAD_DIR) if f.endswith(".csv")]
|
| 59 |
-
else:
|
| 60 |
-
files = []
|
| 61 |
|
| 62 |
if files:
|
| 63 |
selected_file = st.selectbox("Select a CSV file to preprocess", files)
|
|
@@ -117,10 +111,7 @@ elif page == "Preprocess Data":
|
|
| 117 |
elif page == "Train & Select Model":
|
| 118 |
st.title("Train Models and Select the Best One")
|
| 119 |
|
| 120 |
-
|
| 121 |
-
processed_files = [f for f in os.listdir(PROCESSED_DIR) if f.endswith(".csv")]
|
| 122 |
-
else:
|
| 123 |
-
processed_files = []
|
| 124 |
|
| 125 |
if processed_files:
|
| 126 |
selected_file = st.selectbox("Select a processed CSV", processed_files)
|
|
@@ -190,10 +181,7 @@ elif page == "Train & Select Model":
|
|
| 190 |
elif page == "Create App":
|
| 191 |
st.title("Use Model for Prediction")
|
| 192 |
|
| 193 |
-
|
| 194 |
-
processed_files = [f for f in os.listdir(PROCESSED_DIR) if f.endswith(".csv")]
|
| 195 |
-
else:
|
| 196 |
-
processed_files = []
|
| 197 |
|
| 198 |
if processed_files:
|
| 199 |
selected_csv = st.selectbox("Select a processed CSV file", processed_files)
|
|
|
|
| 9 |
from sklearn.tree import DecisionTreeClassifier
|
| 10 |
from sklearn.metrics import accuracy_score, r2_score
|
| 11 |
|
| 12 |
+
# ====== Safe, relative folder paths ======
|
| 13 |
+
UPLOAD_DIR = "uploads"
|
| 14 |
+
PROCESSED_DIR = "processed"
|
| 15 |
+
PKL_DIR = "pkl"
|
| 16 |
+
ENCODERS_DIR = "encoders"
|
| 17 |
|
| 18 |
+
# ====== Create directories if they don't exist ======
|
| 19 |
for folder in [UPLOAD_DIR, PROCESSED_DIR, PKL_DIR, ENCODERS_DIR]:
|
| 20 |
os.makedirs(folder, exist_ok=True)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
st.sidebar.title("Navigation")
|
| 23 |
+
page = st.sidebar.selectbox(
|
| 24 |
+
"Go to",
|
| 25 |
+
["Upload File", "Preprocess Data", "Train & Select Model", "Create App"]
|
| 26 |
+
)
|
| 27 |
|
| 28 |
# ========================
|
| 29 |
# Upload File Page
|
|
|
|
| 51 |
# ========================
|
| 52 |
elif page == "Preprocess Data":
|
| 53 |
st.title("Preprocess Uploaded CSV")
|
| 54 |
+
files = [f for f in os.listdir(UPLOAD_DIR) if f.endswith(".csv")]
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
if files:
|
| 57 |
selected_file = st.selectbox("Select a CSV file to preprocess", files)
|
|
|
|
| 111 |
elif page == "Train & Select Model":
|
| 112 |
st.title("Train Models and Select the Best One")
|
| 113 |
|
| 114 |
+
processed_files = [f for f in os.listdir(PROCESSED_DIR) if f.endswith(".csv")]
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
if processed_files:
|
| 117 |
selected_file = st.selectbox("Select a processed CSV", processed_files)
|
|
|
|
| 181 |
elif page == "Create App":
|
| 182 |
st.title("Use Model for Prediction")
|
| 183 |
|
| 184 |
+
processed_files = [f for f in os.listdir(PROCESSED_DIR) if f.endswith(".csv")]
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
if processed_files:
|
| 187 |
selected_csv = st.selectbox("Select a processed CSV file", processed_files)
|