File size: 1,225 Bytes
edc4276
01e4bba
 
 
edc4276
401d1a7
 
 
edc4276
01e4bba
 
edc4276
 
 
 
 
 
 
01e4bba
edc4276
 
01e4bba
 
 
 
 
edc4276
 
01e4bba
 
edc4276
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import streamlit as st
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences

pip install joblib
import joblib

# Load your models
emotion_model = load_model('lstm_model.h5')
recommender_model = joblib.load('knn_model.npy')

st.title("Emotion-based Song Recommender")

# User input for lyrics
lyrics = st.text_area("Enter lyrics here:")

if st.button("Recommend Songs"):
    
    if lyrics:
        # Predict emotion
        # Here, ensure that the input shape and preprocessing of lyrics
        # match the requirements of your LSTM model
        sequence = tokenizer.texts_to_sequences([lyrics])
        padded_sequence = pad_sequences(sequence, maxlen=128)
        emotion = emotion_model.predict(padded_sequence)  # Adjust this as per your model's requirement

        # Get song recommendations
        # The recommend method should be defined as part of your KNN model
        # or as a separate function that uses the KNN model
        recommendations = recommender_model.recommend(emotion, ...)

        st.write("Emotion Detected:", emotion)
        st.write("Recommended Songs:", recommendations)