co42 HF staff commited on
Commit
6868ece
1 Parent(s): 84104ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -7,6 +7,7 @@ import gradio as gr
7
  import uvicorn
8
  from fastapi.responses import HTMLResponse
9
  from fastapi.responses import RedirectResponse
 
10
 
11
  import spotipy
12
  from spotipy import oauth2
@@ -55,6 +56,29 @@ def scatter_plot_fn(request: gr.Request):
55
  value=iris,
56
  )
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  ##########
60
  def get_started():
 
7
  import uvicorn
8
  from fastapi.responses import HTMLResponse
9
  from fastapi.responses import RedirectResponse
10
+ import pandas as pd
11
 
12
  import spotipy
13
  from spotipy import oauth2
 
56
  value=iris,
57
  )
58
 
59
+ def get_features(spotify):
60
+ features = []
61
+ for index in range(0, 10):
62
+ results = spotify.current_user_saved_tracks(offset=index*50, limit=50)
63
+ track_ids = [item['track']['id'] for item in results['items']]
64
+ features.extend(spotify.audio_features(track_ids))
65
+
66
+ df = pd.DataFrame(data=features)
67
+ names = [
68
+ 'danceability',
69
+ 'energy',
70
+ 'loudness',
71
+ 'speechiness',
72
+ 'acousticness',
73
+ 'instrumentalness',
74
+ 'liveness',
75
+ 'valence',
76
+ 'tempo',
77
+ ]
78
+ features_means = df[names].mean()
79
+ # print (features_means.to_json())
80
+ return features_means
81
+
82
 
83
  ##########
84
  def get_started():