brendabor commited on
Commit
b26a98b
·
1 Parent(s): 981503f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -44,7 +44,7 @@ def hybrid_recommendation(song_index):
44
  audio_features_df = pd.DataFrame(audio_features_scaled_knn, columns=audio_features_knn.columns)
45
  # Combine mood and audio features
46
  combined_features = pd.concat([mood_cats_df, audio_features_df], axis=1)
47
-
48
  # Predict using the KNN model
49
  knn_recommendations = knn_model.kneighbors(combined_features, n_neighbors=5, return_distance=False)[0]
50
 
@@ -57,12 +57,11 @@ def hybrid_recommendation(song_index):
57
  features_for_similarity = df[['danceability', 'energy', 'key', 'loudness', 'mode', 'speechiness',
58
  'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo',
59
  'duration_ms', 'time_signature']].values
60
- scaler = StandardScaler()
61
- audio_features_scaled = scaler.fit_transform(features_for_similarity)
62
  # Combine mood and audio features
63
- combined_features = pd.concat([emotion_category, pd.DataFrame(audio_features_scaled)], axis=1)
64
-
65
- cosine_similarities = cosine_similarity(combined_features)
66
 
67
  # Combine recommendations from both models
68
  combined_indices = np.argsort(-np.concatenate([knn_recommendations, cosine_similarities]))
 
44
  audio_features_df = pd.DataFrame(audio_features_scaled_knn, columns=audio_features_knn.columns)
45
  # Combine mood and audio features
46
  combined_features = pd.concat([mood_cats_df, audio_features_df], axis=1)
47
+
48
  # Predict using the KNN model
49
  knn_recommendations = knn_model.kneighbors(combined_features, n_neighbors=5, return_distance=False)[0]
50
 
 
57
  features_for_similarity = df[['danceability', 'energy', 'key', 'loudness', 'mode', 'speechiness',
58
  'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo',
59
  'duration_ms', 'time_signature']].values
60
+ scaler_cb = StandardScaler()
61
+ audio_features_scaled_cb = scaler_cb.fit_transform(features_for_similarity)
62
  # Combine mood and audio features
63
+ combined_features_cb = np.concatenate([np.array([emotion_category]), audio_features_scaled_cb])
64
+ cosine_similarities = cosine_similarity([combined_features_cb])
 
65
 
66
  # Combine recommendations from both models
67
  combined_indices = np.argsort(-np.concatenate([knn_recommendations, cosine_similarities]))