Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,36 +6,51 @@ import pandas as pd
|
|
6 |
import numpy as np
|
7 |
from sklearn.preprocessing import StandardScaler
|
8 |
|
9 |
-
# Load the emotion prediction model
|
10 |
-
emotion_model = load_model('lstm_model.h5')
|
11 |
-
|
12 |
# Load the tokenizer (ensure it's the one used during training)
|
13 |
tokenizer = joblib.load('tokenizer.pkl')
|
14 |
|
|
|
|
|
|
|
15 |
# Load the dataset
|
16 |
df = pd.read_csv('df1.csv')
|
17 |
df = df.drop(['Unnamed: 0', 'lyrics_filename', 'analysis_url', 'track_href', "type", "id", "uri"], axis=1)
|
18 |
|
19 |
-
#
|
20 |
-
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
|
|
24 |
|
25 |
-
#
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo',
|
31 |
-
'duration_ms', 'time_signature']]
|
32 |
-
mood_cats = df[['mood_cats']]
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
# Set up the title of the app
|
41 |
st.title('Emotion and Audio Feature-based Song Recommendation System')
|
@@ -49,7 +64,7 @@ padded_sequence = pad_sequences(sequence, maxlen=50)
|
|
49 |
emotion = emotion_model.predict(padded_sequence).flatten()
|
50 |
|
51 |
# Combine emotion and audio features for recommendation
|
52 |
-
combined_features_hybrid = np.concatenate([emotion, query_data[
|
53 |
|
54 |
# Generate recommendations using the hybrid model
|
55 |
hybrid_recs = hybrid_recommendation(song_index=0)
|
|
|
6 |
import numpy as np
|
7 |
from sklearn.preprocessing import StandardScaler
|
8 |
|
|
|
|
|
|
|
9 |
# Load the tokenizer (ensure it's the one used during training)
|
10 |
tokenizer = joblib.load('tokenizer.pkl')
|
11 |
|
12 |
+
# Load the emotion prediction model
|
13 |
+
emotion_model = load_model('lstm_model.h5')
|
14 |
+
|
15 |
# Load the dataset
|
16 |
df = pd.read_csv('df1.csv')
|
17 |
df = df.drop(['Unnamed: 0', 'lyrics_filename', 'analysis_url', 'track_href', "type", "id", "uri"], axis=1)
|
18 |
|
19 |
+
# Preprocess for content-based
|
20 |
+
audio_feature_columns = ['danceability', 'energy', 'key', 'loudness', 'mode', 'speechiness',
|
21 |
+
'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo',
|
22 |
+
'duration_ms', 'time_signature']
|
23 |
|
24 |
+
audio_features = df[audio_feature_columns]
|
25 |
+
mood_cats = df[['mood_cats']]
|
26 |
+
mood_cats_df = pd.DataFrame(mood_cats)
|
27 |
|
28 |
+
# Normalize audio features for content-based
|
29 |
+
scaler_cb = StandardScaler()
|
30 |
+
audio_features_scaled_cb = scaler_cb.fit_transform(audio_features)
|
31 |
+
audio_features_df_cb = pd.DataFrame(audio_features_scaled_cb, columns=audio_feature_columns)
|
32 |
+
combined_features_cb = pd.concat([mood_cats, audio_features_df_cb], axis=1)
|
33 |
|
34 |
+
# Load the similarity matrix for content-based
|
35 |
+
similarity_matrix = np.load('similarity_matrix.npy')
|
|
|
|
|
|
|
36 |
|
37 |
+
# Load the content-based recommendation function
|
38 |
+
recommend_cont = joblib.load('recommendation_cont_function.joblib')
|
39 |
+
|
40 |
+
# Preprocessing for KNN
|
41 |
+
scaler_knn = StandardScaler()
|
42 |
+
audio_features_scaled_knn = scaler_knn.fit_transform(audio_features)
|
43 |
+
audio_features_df_knn = pd.DataFrame(audio_features_scaled_knn, columns=audio_feature_columns)
|
44 |
+
combined_features_knn = pd.concat([mood_cats_df, audio_features_df_knn], axis=1)
|
45 |
+
|
46 |
+
# Load the KNN model
|
47 |
+
knn = joblib.load('knn_model.joblib')
|
48 |
+
|
49 |
+
# Load the KNN recommendation function
|
50 |
+
recommend_knn = joblib.load('recommendation_knn_function.joblib')
|
51 |
+
|
52 |
+
# Load the hybrid recommendation function
|
53 |
+
hybrid_recommendation = joblib.load('hybrid_recommendation_function.joblib')
|
54 |
|
55 |
# Set up the title of the app
|
56 |
st.title('Emotion and Audio Feature-based Song Recommendation System')
|
|
|
64 |
emotion = emotion_model.predict(padded_sequence).flatten()
|
65 |
|
66 |
# Combine emotion and audio features for recommendation
|
67 |
+
combined_features_hybrid = np.concatenate([emotion, query_data[audio_feature_columns].values])
|
68 |
|
69 |
# Generate recommendations using the hybrid model
|
70 |
hybrid_recs = hybrid_recommendation(song_index=0)
|