Spaces:
Runtime error
Runtime error
Update W3-assignment-streamlit.py
Browse files- W3-assignment-streamlit.py +21 -13
W3-assignment-streamlit.py
CHANGED
|
@@ -6,6 +6,7 @@ import pandas as pd
|
|
| 6 |
import numpy as np
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
|
|
|
|
| 9 |
from sklearn.impute import SimpleImputer
|
| 10 |
from sklearn.preprocessing import StandardScaler
|
| 11 |
from sklearn.decomposition import PCA
|
|
@@ -21,21 +22,28 @@ st.sidebar.title("Controls")
|
|
| 21 |
import os
|
| 22 |
from pathlib import Path
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
"
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
#
|
| 38 |
-
df_raw =
|
| 39 |
|
| 40 |
# Choose number of clusters (K)
|
| 41 |
k = st.sidebar.slider("Number of clusters (K)", min_value=2, max_value=8, value=4, step=1)
|
|
|
|
| 6 |
import numpy as np
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
|
| 9 |
+
|
| 10 |
from sklearn.impute import SimpleImputer
|
| 11 |
from sklearn.preprocessing import StandardScaler
|
| 12 |
from sklearn.decomposition import PCA
|
|
|
|
| 22 |
import os
|
| 23 |
from pathlib import Path
|
| 24 |
|
| 25 |
+
@st.cache_data(show_spinner=False)
|
| 26 |
+
def load_data() -> pd.DataFrame:
|
| 27 |
+
"""
|
| 28 |
+
Try both locations:
|
| 29 |
+
1) data/youtube_shorts_tiktok_trends_2025.csv
|
| 30 |
+
2) ./youtube_shorts_tiktok_trends_2025.csv
|
| 31 |
+
"""
|
| 32 |
+
candidates = [
|
| 33 |
+
Path("data/youtube_shorts_tiktok_trends_2025.csv"),
|
| 34 |
+
Path("youtube_shorts_tiktok_trends_2025.csv"),
|
| 35 |
+
]
|
| 36 |
+
for p in candidates:
|
| 37 |
+
if p.exists():
|
| 38 |
+
return pd.read_csv(p, low_memory=False)
|
| 39 |
|
| 40 |
+
raise FileNotFoundError(
|
| 41 |
+
f"CSV not found in any of: {[str(p) for p in candidates]}. "
|
| 42 |
+
"Make sure the file is committed to your Space."
|
| 43 |
+
)
|
| 44 |
|
| 45 |
+
# load data
|
| 46 |
+
df_raw = load_data()
|
| 47 |
|
| 48 |
# Choose number of clusters (K)
|
| 49 |
k = st.sidebar.slider("Number of clusters (K)", min_value=2, max_value=8, value=4, step=1)
|