Madhumitha19 commited on
Commit
29b39e7
1 Parent(s): fb2d8d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -29
app.py CHANGED
@@ -4,18 +4,11 @@ from tensorflow.keras.preprocessing.sequence import pad_sequences
4
  import joblib
5
  import pandas as pd
6
  import numpy as np
7
- from sklearn.metrics.pairwise import cosine_similarity
8
  from sklearn.preprocessing import StandardScaler
9
 
10
  # Load the emotion prediction model
11
  emotion_model = load_model('lstm_model.h5')
12
 
13
- # Load the KNN recommender model
14
- # try:
15
- # recommender_model = joblib.load('knn_model.pkl')
16
- # except Exception as e:
17
- # st.error(f"Error loading KNN model: {e}")
18
-
19
  # Load the tokenizer (ensure it's the one used during training)
20
  tokenizer = joblib.load('tokenizer.pkl')
21
 
@@ -23,21 +16,15 @@ tokenizer = joblib.load('tokenizer.pkl')
23
  df = pd.read_csv('df1.csv')
24
  df = df.drop(['Unnamed: 0', 'lyrics_filename', 'analysis_url', 'track_href', "type", "id", "uri"], axis=1)
25
 
26
- # Load the similarity matrix
27
- similarity_matrix = np.load('similarity_matrix.npy')
28
 
29
- # Load the content-based recommendation function
30
- recommend_cont_func = joblib.load('recommendation_cont_function.joblib')
31
 
32
  # Load the hybrid recommendation function
33
  hybrid_recommendation = joblib.load('hybrid_recommendation_function.joblib')
34
 
35
- # Load the KNN model
36
- knn = joblib.load('knn_model.joblib')
37
-
38
- # Load the KNN recommendation function
39
- recommend_knn = joblib.load('recommendation_knn_function.joblib')
40
-
41
  # Preprocess for content-based
42
  audio_features = df[['danceability', 'energy', 'key', 'loudness', 'mode', 'speechiness',
43
  'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo',
@@ -50,18 +37,6 @@ audio_features_df = pd.DataFrame(audio_features_scaled, columns=audio_features.c
50
  mood_cats_df = pd.DataFrame(mood_cats)
51
  combined_features_content = pd.concat([mood_cats_df, audio_features_df], axis=1)
52
 
53
- # Preprocess for KNN
54
- audio_features_knn = df[['danceability', 'energy', 'key', 'loudness', 'mode', 'speechiness',
55
- 'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo',
56
- 'duration_ms', 'time_signature']]
57
- mood_cats_knn = df[['mood_cats']]
58
-
59
- scaler_knn = StandardScaler()
60
- audio_features_scaled_knn = scaler_knn.fit_transform(audio_features_knn)
61
- audio_features_df_knn = pd.DataFrame(audio_features_scaled_knn, columns=audio_features_knn.columns)
62
- mood_cats_df_knn = pd.DataFrame(mood_cats_knn)
63
- combined_features_knn = pd.concat([mood_cats_df_knn, audio_features_df_knn], axis=1)
64
-
65
  # Set up the title of the app
66
  st.title('Emotion and Audio Feature-based Song Recommendation System')
67
 
 
4
  import joblib
5
  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
 
 
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
+ # Load the content-based recommendation module
20
+ recommend_cont_module = joblib.load('recommendation_cont_function.joblib')
21
 
22
+ # Call the function from the module
23
+ hybrid_recs = recommend_cont_module.recommend_cont(song_index=0)
24
 
25
  # Load the hybrid recommendation function
26
  hybrid_recommendation = joblib.load('hybrid_recommendation_function.joblib')
27
 
 
 
 
 
 
 
28
  # Preprocess for content-based
29
  audio_features = df[['danceability', 'energy', 'key', 'loudness', 'mode', 'speechiness',
30
  'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo',
 
37
  mood_cats_df = pd.DataFrame(mood_cats)
38
  combined_features_content = pd.concat([mood_cats_df, audio_features_df], axis=1)
39
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  # Set up the title of the app
41
  st.title('Emotion and Audio Feature-based Song Recommendation System')
42