Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,19 +5,17 @@ import joblib
|
|
5 |
import pandas as pd
|
6 |
import numpy as np
|
7 |
|
8 |
-
# Load your
|
9 |
emotion_model = load_model('lstm_model.h5')
|
10 |
|
11 |
-
#
|
12 |
-
joblib.dump(knn_model, 'knn_model.pkl')
|
13 |
-
# Load the model
|
14 |
recommender_model = joblib.load('knn_model.pkl')
|
15 |
|
16 |
-
# Load the tokenizer (
|
17 |
-
# tokenizer = joblib.load('tokenizer.pkl') # Update
|
18 |
|
19 |
# Load the dataset
|
20 |
-
df = pd.read_csv('df1.csv') #
|
21 |
|
22 |
# Set up the title of the app
|
23 |
st.title('Emotion and Audio Feature-based Song Recommendation System')
|
@@ -29,19 +27,20 @@ lyrics = st.text_area("Input the lyrics of the song here:")
|
|
29 |
# Input fields for audio features
|
30 |
st.header('Enter Audio Features')
|
31 |
audio_features = []
|
32 |
-
for feature_name in df.columns: #
|
33 |
feature = st.number_input(f"Enter value for {feature_name}:", step=0.01)
|
34 |
audio_features.append(feature)
|
35 |
|
36 |
# Predict and Recommend button
|
37 |
if st.button('Predict Emotion and Recommend Songs'):
|
38 |
if lyrics and all(audio_features):
|
|
|
39 |
sequence = tokenizer.texts_to_sequences([lyrics])
|
40 |
padded_sequence = pad_sequences(sequence, maxlen=128)
|
41 |
-
emotion = emotion_model.predict(padded_sequence).flatten()
|
42 |
|
43 |
# Combine emotion and audio features for recommendation
|
44 |
-
combined_features = np.concatenate([
|
45 |
|
46 |
# Generate recommendations using the KNN model
|
47 |
distances, indices = recommender_model.kneighbors([combined_features], n_neighbors=5)
|
@@ -51,6 +50,6 @@ if st.button('Predict Emotion and Recommend Songs'):
|
|
51 |
st.write("Emotion Detected:", emotion[0]) # Adjust as per your model's output
|
52 |
st.header('Recommended Songs')
|
53 |
for _, song in recommended_songs.iterrows():
|
54 |
-
st.write(song) #
|
55 |
else:
|
56 |
-
st.error("Please fill in all the fields.")
|
|
|
5 |
import pandas as pd
|
6 |
import numpy as np
|
7 |
|
8 |
+
# Load your emotion prediction model
|
9 |
emotion_model = load_model('lstm_model.h5')
|
10 |
|
11 |
+
# Load the KNN recommender model
|
|
|
|
|
12 |
recommender_model = joblib.load('knn_model.pkl')
|
13 |
|
14 |
+
# Load the tokenizer (ensure it's the one used during training)
|
15 |
+
# tokenizer = joblib.load('tokenizer.pkl') # Update this to the correct path
|
16 |
|
17 |
# Load the dataset
|
18 |
+
df = pd.read_csv('df1.csv') # Ensure this is the correct DataFrame
|
19 |
|
20 |
# Set up the title of the app
|
21 |
st.title('Emotion and Audio Feature-based Song Recommendation System')
|
|
|
27 |
# Input fields for audio features
|
28 |
st.header('Enter Audio Features')
|
29 |
audio_features = []
|
30 |
+
for feature_name in df.columns: # Ensure this matches your DataFrame's structure
|
31 |
feature = st.number_input(f"Enter value for {feature_name}:", step=0.01)
|
32 |
audio_features.append(feature)
|
33 |
|
34 |
# Predict and Recommend button
|
35 |
if st.button('Predict Emotion and Recommend Songs'):
|
36 |
if lyrics and all(audio_features):
|
37 |
+
# Process the lyrics
|
38 |
sequence = tokenizer.texts_to_sequences([lyrics])
|
39 |
padded_sequence = pad_sequences(sequence, maxlen=128)
|
40 |
+
emotion = emotion_model.predict(padded_sequence).flatten()
|
41 |
|
42 |
# Combine emotion and audio features for recommendation
|
43 |
+
combined_features = np.concatenate([emotion, audio_features]) # Ensure the concatenation logic matches your model's expectation
|
44 |
|
45 |
# Generate recommendations using the KNN model
|
46 |
distances, indices = recommender_model.kneighbors([combined_features], n_neighbors=5)
|
|
|
50 |
st.write("Emotion Detected:", emotion[0]) # Adjust as per your model's output
|
51 |
st.header('Recommended Songs')
|
52 |
for _, song in recommended_songs.iterrows():
|
53 |
+
st.write(song) # Customize this to display relevant song info
|
54 |
else:
|
55 |
+
st.error("Please fill in all the fields.")
|