Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
-
|
|
|
|
|
4 |
|
5 |
# Load your models
|
6 |
-
emotion_model = 'lstm_model.h5'
|
7 |
-
recommender_model = 'knn_model.npy'
|
8 |
|
9 |
st.title("Emotion-based Song Recommender")
|
10 |
|
@@ -12,11 +14,18 @@ st.title("Emotion-based Song Recommender")
|
|
12 |
lyrics = st.text_area("Enter lyrics here:")
|
13 |
|
14 |
if st.button("Recommend Songs"):
|
|
|
15 |
if lyrics:
|
16 |
# Predict emotion
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# Get song recommendations
|
|
|
|
|
20 |
recommendations = recommender_model.recommend(emotion, ...)
|
21 |
|
22 |
st.write("Emotion Detected:", emotion)
|
|
|
1 |
import streamlit as st
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
import joblib
|
4 |
+
from tensorflow.keras.preprocessing.text import Tokenizer
|
5 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
6 |
|
7 |
# Load your models
|
8 |
+
emotion_model = load_model('lstm_model.h5')
|
9 |
+
recommender_model = joblib.load('knn_model.npy')
|
10 |
|
11 |
st.title("Emotion-based Song Recommender")
|
12 |
|
|
|
14 |
lyrics = st.text_area("Enter lyrics here:")
|
15 |
|
16 |
if st.button("Recommend Songs"):
|
17 |
+
|
18 |
if lyrics:
|
19 |
# Predict emotion
|
20 |
+
# Here, ensure that the input shape and preprocessing of lyrics
|
21 |
+
# match the requirements of your LSTM model
|
22 |
+
sequence = tokenizer.texts_to_sequences([lyrics])
|
23 |
+
padded_sequence = pad_sequences(sequence, maxlen=128)
|
24 |
+
emotion = emotion_model.predict(padded_sequence) # Adjust this as per your model's requirement
|
25 |
|
26 |
# Get song recommendations
|
27 |
+
# The recommend method should be defined as part of your KNN model
|
28 |
+
# or as a separate function that uses the KNN model
|
29 |
recommendations = recommender_model.recommend(emotion, ...)
|
30 |
|
31 |
st.write("Emotion Detected:", emotion)
|