Spaces:
Runtime error
Runtime error
nandovallec
commited on
Commit
•
0fe6ac0
1
Parent(s):
51245ea
App
Browse files
app.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# from transformers import pipeline
|
2 |
+
# import gradio as gr
|
3 |
+
# AIzaSyDeT8V0nRlVEgmb0fMK4uc0ci8fAcS0Olg
|
4 |
+
# pipe = pipeline(model="sanchit-gandhi/whisper-small-hi") # change to "your-username/the-name-you-picked"
|
5 |
+
import requests
|
6 |
+
import json
|
7 |
+
import gradio as gr
|
8 |
+
import streamlit as st
|
9 |
+
import requests
|
10 |
+
import base64
|
11 |
+
import json
|
12 |
+
import sys
|
13 |
+
from fetchPlaylistTrackUris import *
|
14 |
+
import re
|
15 |
+
import asyncio
|
16 |
+
# import streamlit.components.v1 as components
|
17 |
+
import pickle
|
18 |
+
import sklearn.preprocessing as pp
|
19 |
+
from scipy.sparse import csr_matrix
|
20 |
+
import numpy as np
|
21 |
+
import pandas as pd
|
22 |
+
import os
|
23 |
+
from recommender import *
|
24 |
+
|
25 |
+
|
26 |
+
# gmaps_api_key = os.environ["GMAPS_API"]
|
27 |
+
# transl_api_key= os.environ["TRANS_API"]
|
28 |
+
# gmaps.configure(api_key=gmaps_api_key)
|
29 |
+
# mode = "walking"
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
def test(playlist_url, n_rec):
|
34 |
+
n_rec = int(n_rec)
|
35 |
+
|
36 |
+
# playlist_url = "https://open.spotify.com/playlist/7HkaNKWr0GCEznuFSEE67i"
|
37 |
+
playlist_uri = playlist_url.split('/')[-1]
|
38 |
+
|
39 |
+
list_uri = get_playlist_track_uris(playlist_uri)
|
40 |
+
|
41 |
+
# uri = "spotify:track:5bjWdBx64POBYiUny759hy"
|
42 |
+
# uri_link = "https://open.spotify.com/embed/track/" + uri + "?utm_source=generator&theme=0"
|
43 |
+
# uri_link = "https://open.spotify.com/embed/track/5bjWdBx64POBYiUny759hy?utm_source=generator&theme=0"
|
44 |
+
# components.iframe(uri_link, height=80)
|
45 |
+
# i += 1
|
46 |
+
# if i % 5 == 0:
|
47 |
+
# time.sleep(1)
|
48 |
+
uri_links = inference_from_uri(list_uri, MAX_tid=n_rec)
|
49 |
+
# uri_links = []
|
50 |
+
frames = ""
|
51 |
+
for uri_link in uri_links:
|
52 |
+
uri_id = uri_link.split(':')[-1]
|
53 |
+
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>'
|
54 |
+
return frames
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
with gr.Blocks() as app:
|
59 |
+
# global mode
|
60 |
+
|
61 |
+
url = gr.Textbox(label="Link to playlist")
|
62 |
+
n_rec = gr.Number(value=5,label="Number of recommendations")
|
63 |
+
|
64 |
+
btn = gr.Button(value="Submit")
|
65 |
+
|
66 |
+
ifr = gr.HTML()
|
67 |
+
|
68 |
+
btn.click(test, inputs=[url, n_rec], outputs=[ifr])
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
demo = gr.TabbedInterface([app], ["Playlist continuation"])
|
78 |
+
demo.launch()
|
79 |
+
|
80 |
+
# def main():
|
81 |
+
# spr_sidebar()
|
82 |
+
# if st.session_state.app_mode == 'Home':
|
83 |
+
# home_page()
|
84 |
+
# if st.session_state.app_mode == 'Result':
|
85 |
+
# result_page()
|
86 |
+
# if st.session_state.app_mode == 'About' :
|
87 |
+
# About_page()
|
88 |
+
# if st.session_state.app_mode == 'Log':
|
89 |
+
# Log_page()
|
90 |
+
# # Run main()
|
91 |
+
# if __name__ == '__main__':
|
92 |
+
# main()
|