mclemcrew commited on
Commit
c05e838
·
1 Parent(s): b883db8

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +16 -16
model.py CHANGED
@@ -157,7 +157,7 @@ def playlist_model(url, model, max_gen=3, same_art=5):
157
  log.append('Model run successfully')
158
  return Fresult, log
159
 
160
- lendf=len(pd.read_csv('../data/streamlit.csv',usecols=['track_uri']))
161
  dtypes = {'track_uri': 'object', 'artist_uri': 'object', 'album_uri': 'object', 'danceability': 'float16', 'energy': 'float16', 'key': 'float16',
162
  'loudness': 'float16', 'mode': 'float16', 'speechiness': 'float16', 'acousticness': 'float16', 'instrumentalness': 'float16',
163
  'liveness': 'float16', 'valence': 'float16', 'tempo': 'float16', 'duration_ms': 'float32', 'time_signature': 'float16',
@@ -292,7 +292,7 @@ def playlist_model(url, model, max_gen=3, same_art=5):
292
  x = 1
293
  for i in range(int(lendf/2), lendf+1, int(lendf/2)):
294
  try:
295
- df = pd.read_csv('../data/streamlit.csv',names= col_name,dtype=dtypes,skiprows=x,nrows=i)
296
  log.append('reading data frame chunks from {} to {}'.format(x,i))
297
  except Exception as e:
298
  log.append('Failed to load grow')
@@ -315,7 +315,7 @@ def playlist_model(url, model, max_gen=3, same_art=5):
315
  log.append('genre|unknown not found')
316
  log.append('Scaling the data .....')
317
  if x == 1:
318
- sc = pickle.load(open('../data/sc.sav','rb'))
319
  df.iloc[:, 3:19] = sc.transform(df.iloc[:, 3:19])
320
  test.iloc[:, 3:19] = sc.transform(test.iloc[:, 3:19])
321
  log.append("Creating playlist vector")
@@ -359,13 +359,13 @@ def playlist_model(url, model, max_gen=3, same_art=5):
359
  log.append('{} New Tracks Found'.format(len(grow)))
360
  if(len(grow)>=1):
361
  try:
362
- new=pd.read_csv('../data/new_tracks.csv',dtype=dtypes)
363
  new=pd.concat([new, grow], axis=0)
364
  new=new[new.Track_pop >0]
365
  new.drop_duplicates(subset=['track_uri'], inplace=True,keep='last')
366
- new.to_csv('../data/new_tracks.csv',index=False)
367
  except:
368
- grow.to_csv('../data/new_tracks.csv', index=False)
369
  log.append('Model run successfully')
370
  except Exception as e:
371
  log.append("Model Failed")
@@ -437,7 +437,7 @@ def song_model(url, model, max_gen=3, same_art=5):
437
  Fresult.append(aa['tracks'][i]['id'])
438
  log.append('Model run successfully')
439
  return Fresult, log
440
- lendf=len(pd.read_csv('../data/streamlit.csv',usecols=['track_uri']))
441
  dtypes = {'track_uri': 'object', 'artist_uri': 'object', 'album_uri': 'object', 'danceability': 'float16', 'energy': 'float16', 'key': 'float16',
442
  'loudness': 'float16', 'mode': 'float16', 'speechiness': 'float16', 'acousticness': 'float16', 'instrumentalness': 'float16',
443
  'liveness': 'float16', 'valence': 'float16', 'tempo': 'float16', 'duration_ms': 'float32', 'time_signature': 'float16',
@@ -504,7 +504,7 @@ def song_model(url, model, max_gen=3, same_art=5):
504
  x = 1
505
  for i in range(int(lendf/2), lendf+1, int(lendf/2)):
506
  try:
507
- df = pd.read_csv('../data/streamlit.csv',names= col_name,dtype=dtypes,skiprows=x,nrows=i)
508
  log.append('reading data frame chunks from {} to {}'.format(x,i))
509
  except Exception as e:
510
  log.append('Failed to load grow')
@@ -527,7 +527,7 @@ def song_model(url, model, max_gen=3, same_art=5):
527
  log.append('genre|unknown not found')
528
  log.append('Scaling the data .....')
529
  if x == 1:
530
- sc = pickle.load(open('../data/sc.sav','rb'))
531
  df.iloc[:, 3:19] = sc.transform(df.iloc[:, 3:19])
532
  test.iloc[:, 3:19] = sc.transform(test.iloc[:, 3:19])
533
  log.append("Creating playlist vector")
@@ -571,13 +571,13 @@ def song_model(url, model, max_gen=3, same_art=5):
571
  log.append('{} New Tracks Found'.format(len(grow)))
572
  if(len(grow)>=1):
573
  try:
574
- new=pd.read_csv('../data/new_tracks.csv',dtype=dtypes)
575
  new=pd.concat([new, grow], axis=0)
576
  new=new[new.Track_pop >0]
577
  new.drop_duplicates(subset=['track_uri'], inplace=True,keep='last')
578
- new.to_csv('../data/new_tracks.csv',index=False)
579
  except:
580
- grow.to_csv('../data/new_tracks.csv', index=False)
581
  log.append('Model run successfully')
582
  except Exception as e:
583
  log.append("Model Failed")
@@ -593,14 +593,14 @@ def update_dataset():
593
  'loudness': 'float16', 'mode': 'float16', 'speechiness': 'float16', 'acousticness': 'float16', 'instrumentalness': 'float16',
594
  'liveness': 'float16', 'valence': 'float16', 'tempo': 'float16', 'duration_ms': 'float32', 'time_signature': 'float16',
595
  'Track_release_date': 'int8', 'Track_pop': 'int8', 'Artist_pop': 'int8', 'Artist_genres': 'object'}
596
- df = pd.read_csv('../data/streamlit.csv',dtype=dtypes)
597
- grow = pd.read_csv('../data/new_tracks.csv',dtype=dtypes)
598
  cur = len(df)
599
  df=pd.concat([df,grow],axis=0)
600
  grow=pd.DataFrame(columns=col_name)
601
- grow.to_csv('../data/new_tracks.csv',index=False)
602
  df=df[df.Track_pop >0]
603
  df.drop_duplicates(subset=['track_uri'],inplace=True,keep='last')
604
  df.dropna(axis=0,inplace=True)
605
- df.to_csv('../data/streamlit.csv',index=False)
606
  return (len(df)-cur)
 
157
  log.append('Model run successfully')
158
  return Fresult, log
159
 
160
+ lendf=len(pd.read_csv('data/streamlit.csv',usecols=['track_uri']))
161
  dtypes = {'track_uri': 'object', 'artist_uri': 'object', 'album_uri': 'object', 'danceability': 'float16', 'energy': 'float16', 'key': 'float16',
162
  'loudness': 'float16', 'mode': 'float16', 'speechiness': 'float16', 'acousticness': 'float16', 'instrumentalness': 'float16',
163
  'liveness': 'float16', 'valence': 'float16', 'tempo': 'float16', 'duration_ms': 'float32', 'time_signature': 'float16',
 
292
  x = 1
293
  for i in range(int(lendf/2), lendf+1, int(lendf/2)):
294
  try:
295
+ df = pd.read_csv('data/streamlit.csv',names= col_name,dtype=dtypes,skiprows=x,nrows=i)
296
  log.append('reading data frame chunks from {} to {}'.format(x,i))
297
  except Exception as e:
298
  log.append('Failed to load grow')
 
315
  log.append('genre|unknown not found')
316
  log.append('Scaling the data .....')
317
  if x == 1:
318
+ sc = pickle.load(open('data/sc.sav','rb'))
319
  df.iloc[:, 3:19] = sc.transform(df.iloc[:, 3:19])
320
  test.iloc[:, 3:19] = sc.transform(test.iloc[:, 3:19])
321
  log.append("Creating playlist vector")
 
359
  log.append('{} New Tracks Found'.format(len(grow)))
360
  if(len(grow)>=1):
361
  try:
362
+ new=pd.read_csv('data/new_tracks.csv',dtype=dtypes)
363
  new=pd.concat([new, grow], axis=0)
364
  new=new[new.Track_pop >0]
365
  new.drop_duplicates(subset=['track_uri'], inplace=True,keep='last')
366
+ new.to_csv('data/new_tracks.csv',index=False)
367
  except:
368
+ grow.to_csv('data/new_tracks.csv', index=False)
369
  log.append('Model run successfully')
370
  except Exception as e:
371
  log.append("Model Failed")
 
437
  Fresult.append(aa['tracks'][i]['id'])
438
  log.append('Model run successfully')
439
  return Fresult, log
440
+ lendf=len(pd.read_csv('data/streamlit.csv',usecols=['track_uri']))
441
  dtypes = {'track_uri': 'object', 'artist_uri': 'object', 'album_uri': 'object', 'danceability': 'float16', 'energy': 'float16', 'key': 'float16',
442
  'loudness': 'float16', 'mode': 'float16', 'speechiness': 'float16', 'acousticness': 'float16', 'instrumentalness': 'float16',
443
  'liveness': 'float16', 'valence': 'float16', 'tempo': 'float16', 'duration_ms': 'float32', 'time_signature': 'float16',
 
504
  x = 1
505
  for i in range(int(lendf/2), lendf+1, int(lendf/2)):
506
  try:
507
+ df = pd.read_csv('data/streamlit.csv',names= col_name,dtype=dtypes,skiprows=x,nrows=i)
508
  log.append('reading data frame chunks from {} to {}'.format(x,i))
509
  except Exception as e:
510
  log.append('Failed to load grow')
 
527
  log.append('genre|unknown not found')
528
  log.append('Scaling the data .....')
529
  if x == 1:
530
+ sc = pickle.load(open('data/sc.sav','rb'))
531
  df.iloc[:, 3:19] = sc.transform(df.iloc[:, 3:19])
532
  test.iloc[:, 3:19] = sc.transform(test.iloc[:, 3:19])
533
  log.append("Creating playlist vector")
 
571
  log.append('{} New Tracks Found'.format(len(grow)))
572
  if(len(grow)>=1):
573
  try:
574
+ new=pd.read_csv('data/new_tracks.csv',dtype=dtypes)
575
  new=pd.concat([new, grow], axis=0)
576
  new=new[new.Track_pop >0]
577
  new.drop_duplicates(subset=['track_uri'], inplace=True,keep='last')
578
+ new.to_csv('data/new_tracks.csv',index=False)
579
  except:
580
+ grow.to_csv('data/new_tracks.csv', index=False)
581
  log.append('Model run successfully')
582
  except Exception as e:
583
  log.append("Model Failed")
 
593
  'loudness': 'float16', 'mode': 'float16', 'speechiness': 'float16', 'acousticness': 'float16', 'instrumentalness': 'float16',
594
  'liveness': 'float16', 'valence': 'float16', 'tempo': 'float16', 'duration_ms': 'float32', 'time_signature': 'float16',
595
  'Track_release_date': 'int8', 'Track_pop': 'int8', 'Artist_pop': 'int8', 'Artist_genres': 'object'}
596
+ df = pd.read_csv('data/streamlit.csv',dtype=dtypes)
597
+ grow = pd.read_csv('data/new_tracks.csv',dtype=dtypes)
598
  cur = len(df)
599
  df=pd.concat([df,grow],axis=0)
600
  grow=pd.DataFrame(columns=col_name)
601
+ grow.to_csv('data/new_tracks.csv',index=False)
602
  df=df[df.Track_pop >0]
603
  df.drop_duplicates(subset=['track_uri'],inplace=True,keep='last')
604
  df.dropna(axis=0,inplace=True)
605
+ df.to_csv('data/streamlit.csv',index=False)
606
  return (len(df)-cur)