carterwward commited on
Commit ·
f5799c1
1
Parent(s): 9211333
remove flask import
Browse files- app.py +4 -1
- src/spotipy_utils.py +13 -13
app.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from src.playlist_builder import SEED_OPTIONS, CROSSOVER_OPTIONS, MUTATION_OPTIONS, ADDED_TO_PLAYLIST, \
|
| 3 |
set_crossover_option, set_mutation_option, update_mutation_size, change_seed_option, search_for_seed, set_track_state, get_next_generation, add_playlist_to_spotify
|
| 4 |
from src.evolutionary_alrogithm import Population, simple_mutation, simple_crossover, THUMBS_UP, THUMBS_DOWN, ADD_TO_PLAYLIST
|
| 5 |
-
from src.spotipy_utils import get_auth_manager
|
| 6 |
|
| 7 |
NUM_SONGS = 9
|
| 8 |
DEFAULT_MUTATION_SIZE = 0.25 # NOTE: This could be turned into a parameter which is set by a slider.
|
|
@@ -16,6 +17,8 @@ PLAYLIST_HEADER = """## Current Playlist"""
|
|
| 16 |
|
| 17 |
|
| 18 |
def initialize_playlist_builder():
|
|
|
|
|
|
|
| 19 |
demo = gr.Blocks()
|
| 20 |
with demo:
|
| 21 |
gr.Markdown(APP_HEADER)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import spotipy.util as util
|
| 3 |
from src.playlist_builder import SEED_OPTIONS, CROSSOVER_OPTIONS, MUTATION_OPTIONS, ADDED_TO_PLAYLIST, \
|
| 4 |
set_crossover_option, set_mutation_option, update_mutation_size, change_seed_option, search_for_seed, set_track_state, get_next_generation, add_playlist_to_spotify
|
| 5 |
from src.evolutionary_alrogithm import Population, simple_mutation, simple_crossover, THUMBS_UP, THUMBS_DOWN, ADD_TO_PLAYLIST
|
| 6 |
+
from src.spotipy_utils import get_auth_manager, CLIENT_ID, CLIENT_SECRET, REDIRECT_URL, PLAYLIST_SCOPE
|
| 7 |
|
| 8 |
NUM_SONGS = 9
|
| 9 |
DEFAULT_MUTATION_SIZE = 0.25 # NOTE: This could be turned into a parameter which is set by a slider.
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
def initialize_playlist_builder():
|
| 20 |
+
user_token = util.prompt_for_user_token(client_id=CLIENT_ID, redirect_uri=REDIRECT_URL, client_secret=CLIENT_SECRET, scope=PLAYLIST_SCOPE, show_dialog=False)
|
| 21 |
+
|
| 22 |
demo = gr.Blocks()
|
| 23 |
with demo:
|
| 24 |
gr.Markdown(APP_HEADER)
|
src/spotipy_utils.py
CHANGED
|
@@ -66,24 +66,24 @@ def add_tracks_to_playlist(playlist_id:str, tracks:List) -> bool:
|
|
| 66 |
Returns:
|
| 67 |
bool: Flag indicating whether or not the playlist was added to the library succesfully.
|
| 68 |
"""
|
| 69 |
-
|
| 70 |
# try:
|
| 71 |
# auth_manager.get_access_token(code)
|
| 72 |
# except spotipy.oauth2.SpotifyOauthError as e:
|
| 73 |
# print(e)
|
| 74 |
# return False
|
| 75 |
|
| 76 |
-
user_client = spotipy.Spotify(user_token)
|
| 77 |
-
username = user_client.current_user()["id"]
|
| 78 |
|
| 79 |
-
try:
|
| 80 |
-
|
| 81 |
-
except spotipy.exceptions.SpotifyException as e:
|
| 82 |
-
|
| 83 |
-
|
| 84 |
|
| 85 |
-
playlist_id = playlist_result["id"]
|
| 86 |
-
tracks_to_add = ["spotify:track:" + track.get_track_id() for track in tracks]
|
| 87 |
-
if tracks_to_add:
|
| 88 |
-
|
| 89 |
-
return True
|
|
|
|
| 66 |
Returns:
|
| 67 |
bool: Flag indicating whether or not the playlist was added to the library succesfully.
|
| 68 |
"""
|
| 69 |
+
pass
|
| 70 |
# try:
|
| 71 |
# auth_manager.get_access_token(code)
|
| 72 |
# except spotipy.oauth2.SpotifyOauthError as e:
|
| 73 |
# print(e)
|
| 74 |
# return False
|
| 75 |
|
| 76 |
+
# user_client = spotipy.Spotify(user_token)
|
| 77 |
+
# username = user_client.current_user()["id"]
|
| 78 |
|
| 79 |
+
# try:
|
| 80 |
+
# playlist_result = user_client.user_playlist_create(username, playlist_id, public=True)
|
| 81 |
+
# except spotipy.exceptions.SpotifyException as e:
|
| 82 |
+
# print(e)
|
| 83 |
+
# return False
|
| 84 |
|
| 85 |
+
# playlist_id = playlist_result["id"]
|
| 86 |
+
# tracks_to_add = ["spotify:track:" + track.get_track_id() for track in tracks]
|
| 87 |
+
# if tracks_to_add:
|
| 88 |
+
# user_client.user_playlist_add_tracks(username, playlist_id, tracks_to_add)
|
| 89 |
+
# return True
|