Spaces:
Runtime error
Runtime error
NimaBoscarino
commited on
Commit
β’
3d738ec
1
Parent(s):
043d857
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,21 @@
|
|
1 |
from sentence_transformers import SentenceTransformer, util
|
2 |
from huggingface_hub import hf_hub_download
|
|
|
3 |
import pickle
|
4 |
import pandas as pd
|
5 |
import gradio as gr
|
6 |
|
7 |
pd.options.mode.chained_assignment = None # Turn off SettingWithCopyWarning
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
13 |
|
14 |
embedder = SentenceTransformer('msmarco-MiniLM-L-6-v3')
|
15 |
|
16 |
-
|
17 |
corpus_embeddings = pickled["embeddings"]
|
18 |
|
19 |
|
@@ -23,10 +25,10 @@ def generate_playlist(prompt):
|
|
23 |
hits = pd.DataFrame(hits[0], columns=['corpus_id', 'score'])
|
24 |
|
25 |
verse_match = verses.iloc[hits['corpus_id']]
|
26 |
-
verse_match = verse_match.drop_duplicates(subset=["
|
27 |
-
song_match = songs[songs["
|
28 |
-
song_match.
|
29 |
-
song_match = song_match.sort_values("
|
30 |
song_match = song_match[0:9] # Only grab the top 9
|
31 |
|
32 |
song_names = list(song_match["full_title"])
|
@@ -40,7 +42,7 @@ def generate_playlist(prompt):
|
|
40 |
|
41 |
|
42 |
def set_lyrics(full_title):
|
43 |
-
lyrics_text = lyrics[lyrics["
|
44 |
return gr.Textbox.update(value=lyrics_text)
|
45 |
|
46 |
|
|
|
1 |
from sentence_transformers import SentenceTransformer, util
|
2 |
from huggingface_hub import hf_hub_download
|
3 |
+
import os
|
4 |
import pickle
|
5 |
import pandas as pd
|
6 |
import gradio as gr
|
7 |
|
8 |
pd.options.mode.chained_assignment = None # Turn off SettingWithCopyWarning
|
9 |
|
10 |
+
auth_token = os.environ.get("TOKEN_FROM_SECRET") or True
|
11 |
+
pickled = pickle.load(open(hf_hub_download("NimaBoscarino/playlist-generator", repo_type="dataset", filename="clean-large_embeddings_msmarco-MiniLM-L-6-v3.pkl"), "rb"))
|
12 |
+
songs = pd.read_csv(hf_hub_download("NimaBoscarino/playlist-generator", repo_type="dataset", filename="songs_new.csv"))
|
13 |
+
verses = pd.read_csv(hf_hub_download("NimaBoscarino/playlist-generator-private", repo_type="dataset", filename="verses.csv", use_auth_token=True))
|
14 |
+
lyrics = pd.read_csv(hf_hub_download("NimaBoscarino/playlist-generator-private", repo_type="dataset", filename="lyrics_new.csv", use_auth_token=True))
|
15 |
|
16 |
embedder = SentenceTransformer('msmarco-MiniLM-L-6-v3')
|
17 |
|
18 |
+
song_ids = pickled["song_ids"]
|
19 |
corpus_embeddings = pickled["embeddings"]
|
20 |
|
21 |
|
|
|
25 |
hits = pd.DataFrame(hits[0], columns=['corpus_id', 'score'])
|
26 |
|
27 |
verse_match = verses.iloc[hits['corpus_id']]
|
28 |
+
verse_match = verse_match.drop_duplicates(subset=["song_id"])
|
29 |
+
song_match = songs[songs["song_id"].isin(verse_match["song_id"].values)]
|
30 |
+
song_match.song_id = pd.Categorical(song_match.song_id, categories=verse_match["song_id"].values)
|
31 |
+
song_match = song_match.sort_values("song_id")
|
32 |
song_match = song_match[0:9] # Only grab the top 9
|
33 |
|
34 |
song_names = list(song_match["full_title"])
|
|
|
42 |
|
43 |
|
44 |
def set_lyrics(full_title):
|
45 |
+
lyrics_text = lyrics[lyrics["song_id"].isin(songs[songs["full_title"] == full_title]["song_id"])]["text"].iloc[0]
|
46 |
return gr.Textbox.update(value=lyrics_text)
|
47 |
|
48 |
|