File size: 3,134 Bytes
0fe6ac0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4da8e4d
0fe6ac0
85cbd4b
1ab13ba
0fe6ac0
1ab13ba
 
 
 
0fe6ac0
1ab13ba
 
 
0fe6ac0
1ab13ba
 
 
0fe6ac0
1ab13ba
 
 
0fe6ac0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ab13ba
 
 
0fe6ac0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
beb43c8
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# 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)

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_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)
    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()