nandovallec
Fix
9d7b9e6
raw
history blame
3.27 kB
# from transformers import pipeline
# import gradio as gr
# AIzaSyDeT8V0nRlVEgmb0fMK4uc0ci8fAcS0Olg
# pipe = pipeline(model="sanchit-gandhi/whisper-small-hi") # change to "your-username/the-name-you-picked"
import requests
import json
import gradio as gr
import requests
import base64
import json
import sys
from fetchPlaylistTrackUris import *
import re
import asyncio
# import streamlit.components.v1 as components
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)
def get_repo_train():
repo_train = Repository(
local_dir="data_train", clone_from=DATASET_REPO_URL_TRAIN, use_auth_token=HF_TOKEN
)
def get_repo_mat():
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_url = "https://open.spotify.com/playlist/7HkaNKWr0GCEznuFSEE67i"
playlist_uri = playlist_url.split('/')[-1]
list_uri = get_playlist_track_uris(playlist_uri)
# uri = "spotify:track:5bjWdBx64POBYiUny759hy"
# uri_link = "https://open.spotify.com/embed/track/" + uri + "?utm_source=generator&theme=0"
# uri_link = "https://open.spotify.com/embed/track/5bjWdBx64POBYiUny759hy?utm_source=generator&theme=0"
# components.iframe(uri_link, height=80)
# i += 1
# if i % 5 == 0:
# time.sleep(1)
repo_train = get_repo_train()
repo_mat = get_repo_mat()
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()
# uri_links = []
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:
# global mode
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()
# def main():
# spr_sidebar()
# if st.session_state.app_mode == 'Home':
# home_page()
# if st.session_state.app_mode == 'Result':
# result_page()
# if st.session_state.app_mode == 'About' :
# About_page()
# if st.session_state.app_mode == 'Log':
# Log_page()
# # Run main()
# if __name__ == '__main__':
# main()