Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -35,8 +35,8 @@ def hybrid_recommendation(song_index):
|
|
35 |
|
36 |
# Preprocess for KNN
|
37 |
audio_features_knn = df[['danceability', 'energy', 'key', 'loudness', 'mode', 'speechiness',
|
38 |
-
|
39 |
-
|
40 |
mood_cats = df[['mood_cats']]
|
41 |
mood_cats_df = pd.DataFrame(mood_cats)
|
42 |
audio_features_scaled_knn = scaler_knn.fit_transform(audio_features_knn)
|
@@ -44,14 +44,13 @@ 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 |
-
#combined_features = pd.concat([mood_cats_df, pd.DataFrame(audio_features_scaled_knn, columns=audio_features_knn.columns)], axis=1)
|
48 |
|
49 |
# Predict using the KNN model
|
50 |
knn_recommendations = knn_model.kneighbors(combined_features, n_neighbors=5, return_distance=False)[0]
|
51 |
|
52 |
# Mapping emotion predictions to encoded categories
|
53 |
emotion_mapping = {0: 'happy', 1: 'sad', 2: 'calm', 3: 'anger'}
|
54 |
-
encoded_emotion =
|
55 |
emotion_category = emotion_mapping[encoded_emotion]
|
56 |
|
57 |
# Compute cosine similarity for content-based recommendation
|
|
|
35 |
|
36 |
# Preprocess for KNN
|
37 |
audio_features_knn = df[['danceability', 'energy', 'key', 'loudness', 'mode', 'speechiness',
|
38 |
+
'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo',
|
39 |
+
'duration_ms', 'time_signature']].values.reshape(1, -1)
|
40 |
mood_cats = df[['mood_cats']]
|
41 |
mood_cats_df = pd.DataFrame(mood_cats)
|
42 |
audio_features_scaled_knn = scaler_knn.fit_transform(audio_features_knn)
|
|
|
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 |
|
51 |
# Mapping emotion predictions to encoded categories
|
52 |
emotion_mapping = {0: 'happy', 1: 'sad', 2: 'calm', 3: 'anger'}
|
53 |
+
encoded_emotion = pd.Series(predicted_emotion).idxmax()
|
54 |
emotion_category = emotion_mapping[encoded_emotion]
|
55 |
|
56 |
# Compute cosine similarity for content-based recommendation
|