Spaces:
Runtime error
Runtime error
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 | |
import joblib | |
import pandas as pd | |
import numpy as np | |
# Load your models | |
emotion_model = load_model('lstm_model.h5') | |
recommender_model = joblib.load('knn_model.npy') | |
#load the dataset | |
# df = pd.read_csv('path_to_your_dataframe.csv') | |
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) | |