File size: 2,478 Bytes
0fe6ac0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4da8e4d
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
# 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 *


# gmaps_api_key = os.environ["GMAPS_API"]
# transl_api_key= os.environ["TRANS_API"]
# gmaps.configure(api_key=gmaps_api_key)
# mode = "walking"



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