File size: 1,567 Bytes
05135b7 7d8d72f 05135b7 b8e63ab 6d4aaf2 05135b7 8924b87 7d8d72f |
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 |
import pandas as pd
import numpy as np
from scipy import spatial
from sentence_transformers import SentenceTransformer
import gradio as gr
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
def get_data():
lyrics_data=pd.read_csv('Lyrics.csv')
lyrics_data=lyrics_data.assign(embeddings=(lyrics_data['Lyric'].astype('str')).apply(lambda x: model.encode(x)))
lyrics_data=lyrics_data.drop(columns=['Unnamed: 0'],axis=1)
lyrics_data.dropna(inplace=True)
return lyrics_data
def closest_lyrics(Songpreference):
data=get_data()
inp_vector=model.encode(Songpreference)
s=data['embeddings'].apply(lambda x: 1 - spatial.distance.cosine(x, inp_vector) )
data=data.assign(similarity=s)
#data=data[['Artist','Title ','Album','Date',' Lyric','Year','similarity']]
data=data.sort_values('similarity',ascending=False).head(5)
data=data.drop(columns=['embeddings','similarity','Date','Year'],axis=1)
return data
iface = gr.Interface(
closest_lyrics,inputs=["text"],
outputs=["dataframe"],
examples=[["Romantic"],["Sad"],["workout"],["The Hello Katy"],["Freshness"]],
#css="https://www.w3schools.com/cssref/",
title='Songify',
description="Songify is a software tool designed to suggest personalized music playlists to users based on their preference and the Users can also discover new music and explore different genres through the app's recommendations. The goal of Songify is to help users find the perfect music for any mood or occasion quickly and effortlessly. ")
iface.launch(inline=False)
|