-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal.py
More file actions
35 lines (26 loc) · 1.26 KB
/
final.py
File metadata and controls
35 lines (26 loc) · 1.26 KB
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
# ... Previous code for fetching and processing songs based on mood ...
# Assuming you have a trained mood classification model called 'classifier'
# Function to predict mood for a given song's lyrics
def predict_mood(song_lyrics):
# Preprocess the lyrics data as needed (cleaning, tokenization, vectorization)
lyrics_tfidf = tfidf_vectorizer.transform([song_lyrics])
# Predict the mood label for the song
mood_label = classifier.predict(lyrics_tfidf)[0]
return mood_label
# Initialize a list to store recommended songs
recommended_songs = []
# Loop through the fetched songs
for song_data in all_lyrics:
song_title = song_data['title']
artist_name = song_data['artist']
lyrics = song_data['lyrics']
# Predict the mood for the song's lyrics
predicted_mood = predict_mood(lyrics)
# Check if the predicted mood matches the user's specified mood
if predicted_mood == desired_mood:
recommended_songs.append({'title': song_title, 'artist': artist_name, 'lyrics': lyrics})
# Now, recommended_songs contains songs that match the user's specified mood
for song_data in recommended_songs:
print(f"Title: {song_data['title']}")
print(f"Artist: {song_data['artist']}")
print(f"Lyrics: {song_data['lyrics']}\n")