Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,19 +2,12 @@ from PIL import Image
|
|
2 |
from utils import *
|
3 |
from app_utils import *
|
4 |
import time
|
|
|
5 |
|
6 |
|
7 |
-
debug =
|
8 |
dir_path = os.path.dirname(os.path.realpath(__file__))
|
9 |
-
|
10 |
-
# if debug: os.environ['FLASK_ENV'] = 'development'
|
11 |
-
#
|
12 |
-
#
|
13 |
-
# app = Flask(__name__)
|
14 |
-
# app.config['SECRET_KEY'] = os.urandom(64)
|
15 |
-
# app.config['SESSION_TYPE'] = 'filesystem'
|
16 |
-
# app.config['SESSION_FILE_DIR'] = './.flask_session/'
|
17 |
-
# Session(app)
|
18 |
st.set_page_config(
|
19 |
page_title="EmotionPlaylist",
|
20 |
page_icon="🎧",
|
@@ -25,11 +18,20 @@ st.title('Customize Emotional Playlists')
|
|
25 |
def log_to_spotify():
|
26 |
st.subheader("Step 1: Connect to your Spotify app")
|
27 |
st.markdown("Log into your Spotify account to let the app create the custom playlist.")
|
28 |
-
if 'login' not in st.session_state:
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
30 |
if sp != None:
|
31 |
legit_genres = sp.recommendation_genre_seeds()['genres']
|
32 |
st.session_state['login'] = (sp, user_id, legit_genres)
|
|
|
|
|
|
|
|
|
33 |
|
34 |
|
35 |
@st.cache(suppress_st_warning=True)
|
@@ -227,6 +229,8 @@ def find_best_songs_for_mood(all_tracks_audio_features, genre_selected_indexes,
|
|
227 |
|
228 |
|
229 |
def run_app():
|
|
|
|
|
230 |
setup_credentials()
|
231 |
|
232 |
image = Image.open(dir_path + '/image.png')
|
@@ -236,17 +240,13 @@ def run_app():
|
|
236 |
"* **You're in control**: you provide a source of candidate songs, select a list of genres and choose the mood for the playlist.")
|
237 |
fake = centered_button(st.button, "Let's go", n_columns=7, disabled=True)
|
238 |
|
239 |
-
log_to_spotify()
|
240 |
|
241 |
if 'login' in st.session_state or debug:
|
242 |
-
global sp
|
243 |
-
if not debug: sp, user_id, legit_genres = st.session_state['login']
|
244 |
-
st.success('You are logged in.')
|
245 |
-
|
246 |
all_tracks_uris, all_tracks_audio_features, genres, genres_labels = select_songs(legit_genres)
|
|
|
247 |
if all_tracks_uris is not None:
|
248 |
target_mood = customize_widgets(genres_labels)
|
249 |
-
|
250 |
custom_button = centered_button(st.button, 'Run customization', n_columns=5)
|
251 |
if custom_button or 'run_custom' in st.session_state.keys():
|
252 |
st.session_state['run_custom'] = True
|
|
|
2 |
from utils import *
|
3 |
from app_utils import *
|
4 |
import time
|
5 |
+
from spotipy.oauth2 import SpotifyClientCredentials
|
6 |
|
7 |
|
8 |
+
debug = True
|
9 |
dir_path = os.path.dirname(os.path.realpath(__file__))
|
10 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
st.set_page_config(
|
12 |
page_title="EmotionPlaylist",
|
13 |
page_icon="🎧",
|
|
|
18 |
def log_to_spotify():
|
19 |
st.subheader("Step 1: Connect to your Spotify app")
|
20 |
st.markdown("Log into your Spotify account to let the app create the custom playlist.")
|
21 |
+
if 'login' not in st.session_state or debug:
|
22 |
+
if debug:
|
23 |
+
client_credentials_manager = SpotifyClientCredentials()
|
24 |
+
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
25 |
+
user_id = None
|
26 |
+
else:
|
27 |
+
sp, user_id = new_get_client(session=st.session_state)
|
28 |
if sp != None:
|
29 |
legit_genres = sp.recommendation_genre_seeds()['genres']
|
30 |
st.session_state['login'] = (sp, user_id, legit_genres)
|
31 |
+
else:
|
32 |
+
sp, user_id, legit_genres = st.session_state['login']
|
33 |
+
st.success('You are logged in.')
|
34 |
+
return sp, user_id, legit_genres
|
35 |
|
36 |
|
37 |
@st.cache(suppress_st_warning=True)
|
|
|
229 |
|
230 |
|
231 |
def run_app():
|
232 |
+
global sp
|
233 |
+
|
234 |
setup_credentials()
|
235 |
|
236 |
image = Image.open(dir_path + '/image.png')
|
|
|
240 |
"* **You're in control**: you provide a source of candidate songs, select a list of genres and choose the mood for the playlist.")
|
241 |
fake = centered_button(st.button, "Let's go", n_columns=7, disabled=True)
|
242 |
|
243 |
+
sp, user_id, legit_genres = log_to_spotify()
|
244 |
|
245 |
if 'login' in st.session_state or debug:
|
|
|
|
|
|
|
|
|
246 |
all_tracks_uris, all_tracks_audio_features, genres, genres_labels = select_songs(legit_genres)
|
247 |
+
|
248 |
if all_tracks_uris is not None:
|
249 |
target_mood = customize_widgets(genres_labels)
|
|
|
250 |
custom_button = centered_button(st.button, 'Run customization', n_columns=5)
|
251 |
if custom_button or 'run_custom' in st.session_state.keys():
|
252 |
st.session_state['run_custom'] = True
|