Main code added
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
from scipy import spatial
|
4 |
+
from sentence_transformers import SentenceTransformer
|
5 |
+
import gradio as gr
|
6 |
+
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
7 |
+
|
8 |
+
def get_data():
|
9 |
+
lyrics_data=pd.read_csv('/content/Lyrics.csv')
|
10 |
+
lyrics_data=lyrics_data.assign(embeddings=(lyrics_data['Lyric'].astype('str')).apply(lambda x: model.encode(x)))
|
11 |
+
lyrics_data=lyrics_data.drop(columns=['Unnamed: 0'],axis=1)
|
12 |
+
lyrics_data.dropna(inplace=True)
|
13 |
+
return lyrics_data
|
14 |
+
|
15 |
+
def closest_lyrics(Songpreference):
|
16 |
+
data=get_data()
|
17 |
+
inp_vector=model.encode(Songpreference)
|
18 |
+
s=data['embeddings'].apply(lambda x: 1 - spatial.distance.cosine(x, inp_vector) )
|
19 |
+
data=data.assign(similarity=s)
|
20 |
+
#data=data[['Artist','Title ','Album','Date',' Lyric','Year','similarity']]
|
21 |
+
data=data.sort_values('similarity',ascending=False).head(5)
|
22 |
+
data=data.drop(columns=['embeddings','similarity','Date','Year'],axis=1)
|
23 |
+
return data
|
24 |
+
iface = gr.Interface(
|
25 |
+
closest_lyrics,inputs=["text"],
|
26 |
+
outputs=["dataframe"],
|
27 |
+
examples=[["Romantic"],["Sad"],["workout "],["The Hello Katy "],["Freshness"]],
|
28 |
+
theme="seafoam",
|
29 |
+
#css="https://www.w3schools.com/cssref/playit.asp?filename=playcss_background-color",
|
30 |
+
title='Songify',
|
31 |
+
description="Songify is a software tool designed to suggest personalized music playlists to users based on their preference.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. ")
|
32 |
+
iface.launch(inline=True)
|