carterwward commited on
Commit
5d900fa
·
1 Parent(s): e9d85b7
Files changed (2) hide show
  1. app.py +3 -2
  2. src/evolutionary_alrogithm.py +2 -2
app.py CHANGED
@@ -3,7 +3,7 @@ from src.playlist_builder import SEED_OPTIONS, CROSSOVER_OPTIONS, MUTATION_OPTIO
3
  set_crossover_option, set_mutation_option, update_mutation_size, change_seed_option, search_for_seed, set_pop_seed ,set_track_state, get_next_generation, add_playlist_to_spotify, \
4
  generate_population_direction_tracking_viz
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
7
 
8
  NUM_SONGS = 9
9
  DEFAULT_MUTATION_SIZE = 0.25
@@ -23,7 +23,8 @@ def initialize_playlist_builder():
23
  # Initialize app attributes
24
  do_crossover = gr.State(False)
25
  do_mutation = gr.State(False)
26
- population = Population(NUM_SONGS, DEFAULT_MUTATION_SIZE, mutation_function=simple_mutation, crossover_function=simple_crossover)
 
27
  population_state = gr.State(population)
28
 
29
  # Generate blank traversal visualization.
 
3
  set_crossover_option, set_mutation_option, update_mutation_size, change_seed_option, search_for_seed, set_pop_seed ,set_track_state, get_next_generation, add_playlist_to_spotify, \
4
  generate_population_direction_tracking_viz
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, get_sp_client
7
 
8
  NUM_SONGS = 9
9
  DEFAULT_MUTATION_SIZE = 0.25
 
23
  # Initialize app attributes
24
  do_crossover = gr.State(False)
25
  do_mutation = gr.State(False)
26
+ sp_client = get_sp_client()
27
+ population = Population(sp_client, NUM_SONGS, DEFAULT_MUTATION_SIZE, mutation_function=simple_mutation, crossover_function=simple_crossover)
28
  population_state = gr.State(population)
29
 
30
  # Generate blank traversal visualization.
src/evolutionary_alrogithm.py CHANGED
@@ -109,7 +109,7 @@ class Individual:
109
  class Population:
110
  """ Population of tracks to be evolved through interaction with a user in an effort to build a curated playlist.
111
  """
112
- def __init__(self, num_songs:int, mutation_size:float, crossover_function=None, mutation_function=None):
113
  """ Constructor of the population initializing all the tracks in the first generation.
114
 
115
  Args:
@@ -119,9 +119,9 @@ class Population:
119
  mutation_function (function, optional): Function to perform mutation with. Defaults to None.
120
  """
121
  self.seed_track = None
122
- self.sp_client = get_sp_client()
123
  self.size = num_songs
124
  self.init_inds = np.random.choice(sample_inds, self.size)
 
125
  self.pop = [Individual(self.sp_client, ind) for ind in self.init_inds]
126
  self.search_results = None
127
  self.search_seed = None
 
109
  class Population:
110
  """ Population of tracks to be evolved through interaction with a user in an effort to build a curated playlist.
111
  """
112
+ def __init__(self, sp_client, num_songs:int, mutation_size:float, crossover_function=None, mutation_function=None):
113
  """ Constructor of the population initializing all the tracks in the first generation.
114
 
115
  Args:
 
119
  mutation_function (function, optional): Function to perform mutation with. Defaults to None.
120
  """
121
  self.seed_track = None
 
122
  self.size = num_songs
123
  self.init_inds = np.random.choice(sample_inds, self.size)
124
+ self.sp_client = sp_client
125
  self.pop = [Individual(self.sp_client, ind) for ind in self.init_inds]
126
  self.search_results = None
127
  self.search_seed = None