ccolas commited on
Commit
d0826bc
·
1 Parent(s): 337e77a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import streamlit as st
 
2
  from PIL import Image
3
  import spotipy.util as util
4
  import pickle
@@ -110,7 +111,6 @@ def setup_streamlite():
110
  setup_credentials()
111
  image = Image.open(dir_path + '/image.png')
112
  st.image(image)
113
-
114
  st.markdown("This app let's you quickly build playlists in a customized way: ")
115
  st.markdown("* **It's easy**: you won't have to add songs one by one,\n"
116
  "* **You're in control**: you provide a source of candidate songs, select a list of genres and choose the mood for the playlist.")
@@ -234,18 +234,26 @@ def setup_streamlite():
234
 
235
  selected_tracks_indexes = genre_selected_indexes[min_dist_indexes[:playlist_length]]
236
  selected_tracks_uris = all_tracks_uris[selected_tracks_indexes]
237
-
238
  playlist_name = st.text_input('Playlist name', value='Mood Playlist')
239
  if playlist_name == '':
240
  st.warning('Please enter a playlist name.')
241
  else:
242
- generation_button = st.button('Generate playlist')
243
  if generation_button:
244
  description = f'Emotion Playlist for Valence: {valence}, Energy: {energy}, Danceability: {danceability}). ' \
245
  f'Playlist generated by the EmotionPlaylist app: https://huggingface.co/spaces/ccolas/EmotionPlaylist.'
246
  playlist_info = sp.user_playlist_create(user_id, playlist_name, public=True, collaborative=False, description=description)
247
  playlist_uri = playlist_info['uri'].split(':')[-1]
248
  sp.playlist_add_items(playlist_uri, selected_tracks_uris)
 
 
 
 
 
 
 
 
249
 
250
  st.success(f'The playlist has been generated, find it [here](https://open.spotify.com/playlist/{playlist_uri}).')
251
 
 
1
  import streamlit as st
2
+ import streamlit.components.v1 as components
3
  from PIL import Image
4
  import spotipy.util as util
5
  import pickle
 
111
  setup_credentials()
112
  image = Image.open(dir_path + '/image.png')
113
  st.image(image)
 
114
  st.markdown("This app let's you quickly build playlists in a customized way: ")
115
  st.markdown("* **It's easy**: you won't have to add songs one by one,\n"
116
  "* **You're in control**: you provide a source of candidate songs, select a list of genres and choose the mood for the playlist.")
 
234
 
235
  selected_tracks_indexes = genre_selected_indexes[min_dist_indexes[:playlist_length]]
236
  selected_tracks_uris = all_tracks_uris[selected_tracks_indexes]
237
+ np.random.shuffle(selected_tracks_uris)
238
  playlist_name = st.text_input('Playlist name', value='Mood Playlist')
239
  if playlist_name == '':
240
  st.warning('Please enter a playlist name.')
241
  else:
242
+ generation_button = centered_button(st.button, 'Generate playlist', n_columns=5)
243
  if generation_button:
244
  description = f'Emotion Playlist for Valence: {valence}, Energy: {energy}, Danceability: {danceability}). ' \
245
  f'Playlist generated by the EmotionPlaylist app: https://huggingface.co/spaces/ccolas/EmotionPlaylist.'
246
  playlist_info = sp.user_playlist_create(user_id, playlist_name, public=True, collaborative=False, description=description)
247
  playlist_uri = playlist_info['uri'].split(':')[-1]
248
  sp.playlist_add_items(playlist_uri, selected_tracks_uris)
249
+ st.write(
250
+ f"""
251
+ <html>
252
+ <body>
253
+ <center>
254
+ <iframe style = "border-radius:12px" src="https://open.spotify.com/embed/playlist/{playlist_uri}" allowtransparency="true"
255
+ allow="encrypted-media" width="80%" height="580" frameborder="0"></iframe></center></body></html>
256
+ """, unsafe_allow_html=True)
257
 
258
  st.success(f'The playlist has been generated, find it [here](https://open.spotify.com/playlist/{playlist_uri}).')
259