|
|
|
|
|
|
|
|
|
import requests |
|
import json |
|
import gradio as gr |
|
import requests |
|
import base64 |
|
import json |
|
import sys |
|
from fetchPlaylistTrackUris import * |
|
import re |
|
import asyncio |
|
|
|
import pickle |
|
import sklearn.preprocessing as pp |
|
from scipy.sparse import csr_matrix |
|
import numpy as np |
|
import pandas as pd |
|
import os |
|
from scipy.sparse import vstack |
|
from recommender import * |
|
import huggingface_hub |
|
from huggingface_hub import Repository |
|
|
|
HF_TOKEN = os.environ.get("HF_TOKEN") |
|
DATASET_REPO_URL_TRAIN = "https://huggingface.co/datasets/nandovallec/df_ps_train_extra" |
|
DATA_FILENAME_TRAIN = "df_ps_train_extra.hdf" |
|
DATA_FILE_TRAIN = os.path.join("data_train", DATA_FILENAME_TRAIN) |
|
|
|
DATASET_REPO_URL_MAT = "https://huggingface.co/datasets/nandovallec/giantMatrix_extra" |
|
DATA_FILENAME_MAT = "giantMatrix_extra.pickle" |
|
DATA_FILE_MAT = os.path.join("data_mat", DATA_FILENAME_MAT) |
|
|
|
repo_train = Repository( |
|
local_dir="data_train", clone_from=DATASET_REPO_URL_TRAIN, use_auth_token=HF_TOKEN |
|
) |
|
|
|
repo_mat = Repository( |
|
local_dir="data_mat", clone_from=DATASET_REPO_URL_MAT, use_auth_token=HF_TOKEN |
|
) |
|
|
|
def test(playlist_url, n_rec): |
|
n_rec = int(n_rec) |
|
|
|
|
|
playlist_uri = playlist_url.split('/')[-1] |
|
|
|
list_uri = get_playlist_track_uris(playlist_uri) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uri_links = inference_from_uri(list_uri, MAX_tid=n_rec) |
|
commit_url = repo_train.push_to_hub() |
|
commit_url = repo_mat.push_to_hub() |
|
|
|
|
|
frames = "" |
|
for uri_link in uri_links: |
|
uri_id = uri_link.split(':')[-1] |
|
frames = f'{frames}<iframe id="inlineFrameExample" title="Inline Frame Map" style="width:100%; height: 250px;" src="https://open.spotify.com/embed/track/{uri_id}?utm_source=generator&theme=0"></iframe>' |
|
return frames |
|
|
|
|
|
|
|
with gr.Blocks() as app: |
|
|
|
|
|
url = gr.Textbox(label="Link to playlist") |
|
n_rec = gr.Number(value=5,label="Number of recommendations") |
|
|
|
btn = gr.Button(value="Submit") |
|
|
|
ifr = gr.HTML() |
|
|
|
btn.click(test, inputs=[url, n_rec], outputs=[ifr]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
demo = gr.TabbedInterface([app], ["Playlist continuation"]) |
|
demo.launch() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|