ESMATUGBA commited on
Commit
b91edb9
·
verified ·
1 Parent(s): 8b26a6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -22
app.py CHANGED
@@ -3,9 +3,9 @@ import pandas as pd
3
  import joblib
4
  import matplotlib.pyplot as plt
5
 
6
- # --------------------------------------
7
- # 1️⃣ Dosya Yolları
8
- # --------------------------------------
9
  DATA_PATH = "spotify_clustered.csv"
10
  MODEL_PATH = "kmeans_music_model.pkl"
11
  SCALER_PATH = "scaler_music.pkl"
@@ -17,32 +17,32 @@ def load_data():
17
  except FileNotFoundError:
18
  st.error("spotify_clustered.csv bulunamadı! Lütfen root klasöre yükleyin.")
19
  st.stop()
20
- # Gereksiz sütunları kaldır
21
  unnecessary_cols = ['Unnamed: 0', 'track_id', 'album_name', 'explicit']
22
  df_display = df.drop(columns=[c for c in unnecessary_cols if c in df.columns])
23
  return df, df_display
24
 
25
- # Veri ve model yükle
26
  df, df_display = load_data()
 
 
27
  model = joblib.load(MODEL_PATH)
28
  scaler = joblib.load(SCALER_PATH)
29
 
30
- # --------------------------------------
31
- # 2️⃣ Sayfa Ayarları
32
- # --------------------------------------
33
  st.set_page_config(page_title="Spotify Clusters", layout="wide")
34
  st.title("🎵 Spotify Music Clustering / Spotify Müzik Kümeleme")
35
  st.markdown("---")
36
 
37
- # --------------------------------------
38
- # 3️⃣ Veri Önizleme
39
- # --------------------------------------
40
  st.subheader("📄 Dataset Preview / Veri Önizleme")
41
  st.dataframe(df_display.head(10), use_container_width=True)
42
 
43
- # --------------------------------------
44
  # 4️⃣ Görselleştirme
45
- # --------------------------------------
46
  col1, col2 = st.columns(2)
47
 
48
  with col1:
@@ -51,7 +51,7 @@ with col1:
51
 
52
  with col2:
53
  st.subheader("🎯 Feature Analysis / Özellik Analizi")
54
- fig, ax = plt.subplots(figsize=(8, 5))
55
  scatter = ax.scatter(df['danceability'], df['energy'], c=df['cluster'], cmap='viridis', alpha=0.6)
56
  ax.set_xlabel("Danceability / Dans Edilebilirlik")
57
  ax.set_ylabel("Energy / Enerji")
@@ -59,9 +59,9 @@ with col2:
59
  st.pyplot(fig, clear_figure=True)
60
  plt.close(fig)
61
 
62
- # --------------------------------------
63
- # 5️⃣ Tahmin Bölümü
64
- # --------------------------------------
65
  st.divider()
66
  st.subheader("🤖 Predict New Song Cluster / Yeni Şarkı Tahmini")
67
  st.info("Adjust sliders to see which cluster a song belongs to / Sürgüleri ayarlayın.")
@@ -93,12 +93,12 @@ if st.button("Predict Cluster / Kümeyi Tahmin Et ✨"):
93
  except Exception as e:
94
  st.error(f"Prediction Error / Tahmin Hatası: {e}")
95
 
96
- # --------------------------------------
97
- # 6️⃣ Küme Ortalamaları
98
- # --------------------------------------
99
  st.divider()
100
  st.subheader("🔍 Cluster Characteristics / Küme Özellikleri (Ortalamalar)")
101
- numeric_only = df.select_dtypes(include=['float64', 'int64'])
102
  if 'cluster' in df.columns:
103
  means = numeric_only.groupby(df['cluster']).mean()
104
- st.dataframe(means, use_container_width=True)
 
3
  import joblib
4
  import matplotlib.pyplot as plt
5
 
6
+ # -------------------------------
7
+ # 1️⃣ Dosya yolları
8
+ # -------------------------------
9
  DATA_PATH = "spotify_clustered.csv"
10
  MODEL_PATH = "kmeans_music_model.pkl"
11
  SCALER_PATH = "scaler_music.pkl"
 
17
  except FileNotFoundError:
18
  st.error("spotify_clustered.csv bulunamadı! Lütfen root klasöre yükleyin.")
19
  st.stop()
 
20
  unnecessary_cols = ['Unnamed: 0', 'track_id', 'album_name', 'explicit']
21
  df_display = df.drop(columns=[c for c in unnecessary_cols if c in df.columns])
22
  return df, df_display
23
 
 
24
  df, df_display = load_data()
25
+
26
+ # Model ve scaler yükle
27
  model = joblib.load(MODEL_PATH)
28
  scaler = joblib.load(SCALER_PATH)
29
 
30
+ # -------------------------------
31
+ # 2️⃣ Sayfa ayarları
32
+ # -------------------------------
33
  st.set_page_config(page_title="Spotify Clusters", layout="wide")
34
  st.title("🎵 Spotify Music Clustering / Spotify Müzik Kümeleme")
35
  st.markdown("---")
36
 
37
+ # -------------------------------
38
+ # 3️⃣ Veri önizleme
39
+ # -------------------------------
40
  st.subheader("📄 Dataset Preview / Veri Önizleme")
41
  st.dataframe(df_display.head(10), use_container_width=True)
42
 
43
+ # -------------------------------
44
  # 4️⃣ Görselleştirme
45
+ # -------------------------------
46
  col1, col2 = st.columns(2)
47
 
48
  with col1:
 
51
 
52
  with col2:
53
  st.subheader("🎯 Feature Analysis / Özellik Analizi")
54
+ fig, ax = plt.subplots(figsize=(8,5))
55
  scatter = ax.scatter(df['danceability'], df['energy'], c=df['cluster'], cmap='viridis', alpha=0.6)
56
  ax.set_xlabel("Danceability / Dans Edilebilirlik")
57
  ax.set_ylabel("Energy / Enerji")
 
59
  st.pyplot(fig, clear_figure=True)
60
  plt.close(fig)
61
 
62
+ # -------------------------------
63
+ # 5️⃣ Tahmin bölümü
64
+ # -------------------------------
65
  st.divider()
66
  st.subheader("🤖 Predict New Song Cluster / Yeni Şarkı Tahmini")
67
  st.info("Adjust sliders to see which cluster a song belongs to / Sürgüleri ayarlayın.")
 
93
  except Exception as e:
94
  st.error(f"Prediction Error / Tahmin Hatası: {e}")
95
 
96
+ # -------------------------------
97
+ # 6️⃣ Küme ortalamaları
98
+ # -------------------------------
99
  st.divider()
100
  st.subheader("🔍 Cluster Characteristics / Küme Özellikleri (Ortalamalar)")
101
+ numeric_only = df.select_dtypes(include=['float64','int64'])
102
  if 'cluster' in df.columns:
103
  means = numeric_only.groupby(df['cluster']).mean()
104
+ st.dataframe(means, use_container_width=True)