SpotifyProject / app.py
brendabor's picture
Update app.py
01e4bba
raw
history blame
1.21 kB
import streamlit as st
from tensorflow.keras.models import load_model
import joblib
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
# 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)