Update app.py
Browse files
app.py
CHANGED
@@ -219,6 +219,7 @@ def scatter_plot_fn_liveness(request: gr.Request):
|
|
219 |
results = sp.current_user()
|
220 |
print(results)
|
221 |
df = get_features(sp)
|
|
|
222 |
return gr.ScatterPlot(
|
223 |
value=df,
|
224 |
x="acousticness",
|
@@ -258,6 +259,30 @@ def get_features(spotify):
|
|
258 |
return df
|
259 |
|
260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
##########
|
262 |
def get_started():
|
263 |
# redirects to spotify and comes back
|
@@ -271,13 +296,13 @@ with gr.Blocks() as demo:
|
|
271 |
get_started_btn = gr.Button("Get Started")
|
272 |
with gr.Row():
|
273 |
spider_plot = gr.Plot()
|
274 |
-
with gr.Row():
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
with gr.Row():
|
282 |
gr.Markdown(" ### We have recommendations for you!")
|
283 |
with gr.Row():
|
@@ -289,12 +314,13 @@ with gr.Blocks() as demo:
|
|
289 |
headers=["Song", "Album", "Artist"],
|
290 |
datatype=["str", "str", "str"],
|
291 |
label="Reccomended Songs",
|
292 |
-
value=[["Fired Up", "Fired Up", "Randy Houser"], ["Something Just Like This", "Memories...Do Not Open", "The Chainsmokers"]] # TODO: replace with actual reccomendations once get_started() is implemeted.
|
293 |
)
|
294 |
-
|
|
|
295 |
demo.load(fn=heatmap_plot_fn, outputs = heatmap_plot)
|
296 |
-
demo.load(fn=scatter_plot_fn_energy, outputs = energy_plot)
|
297 |
-
demo.load(fn=scatter_plot_fn_liveness, outputs = liveness_plot)
|
298 |
|
299 |
|
300 |
gradio_app = gr.mount_gradio_app(app, demo, "/gradio")
|
|
|
219 |
results = sp.current_user()
|
220 |
print(results)
|
221 |
df = get_features(sp)
|
222 |
+
print(df)
|
223 |
return gr.ScatterPlot(
|
224 |
value=df,
|
225 |
x="acousticness",
|
|
|
259 |
return df
|
260 |
|
261 |
|
262 |
+
def get_features(spotify):
|
263 |
+
features = []
|
264 |
+
for index in range(0, 10):
|
265 |
+
results = spotify.current_user_saved_tracks(offset=index*50, limit=50)
|
266 |
+
track_ids = [item['track']['id'] for item in results['items']]
|
267 |
+
features.extend(spotify.audio_features(track_ids))
|
268 |
+
|
269 |
+
df = pd.DataFrame(data=features)
|
270 |
+
names = [
|
271 |
+
'danceability',
|
272 |
+
'energy',
|
273 |
+
'loudness',
|
274 |
+
'speechiness',
|
275 |
+
'acousticness',
|
276 |
+
'instrumentalness',
|
277 |
+
'liveness',
|
278 |
+
'valence',
|
279 |
+
'tempo',
|
280 |
+
]
|
281 |
+
features_means = df[names].mean()
|
282 |
+
# print (features_means.to_json())
|
283 |
+
return features_means
|
284 |
+
|
285 |
+
|
286 |
##########
|
287 |
def get_started():
|
288 |
# redirects to spotify and comes back
|
|
|
296 |
get_started_btn = gr.Button("Get Started")
|
297 |
with gr.Row():
|
298 |
spider_plot = gr.Plot()
|
299 |
+
# with gr.Row():
|
300 |
+
# with gr.Column():
|
301 |
+
# with gr.Row():
|
302 |
+
# with gr.Column():
|
303 |
+
# energy_plot = gr.ScatterPlot(show_label=False).style(container=True)
|
304 |
+
# with gr.Column():
|
305 |
+
# liveness_plot = gr.ScatterPlot(show_label=False).style(container=True)
|
306 |
with gr.Row():
|
307 |
gr.Markdown(" ### We have recommendations for you!")
|
308 |
with gr.Row():
|
|
|
314 |
headers=["Song", "Album", "Artist"],
|
315 |
datatype=["str", "str", "str"],
|
316 |
label="Reccomended Songs",
|
317 |
+
value=[["Fired Up", "Fired Up", "Randy Houser"], ["Something Just Like This", "Memories... Do Not Open", "The Chainsmokers"]] # TODO: replace with actual reccomendations once get_started() is implemeted.
|
318 |
)
|
319 |
+
|
320 |
+
demo.load(fn=get_spider_plot, outputs = spider_plot)
|
321 |
demo.load(fn=heatmap_plot_fn, outputs = heatmap_plot)
|
322 |
+
# demo.load(fn=scatter_plot_fn_energy, outputs = energy_plot)
|
323 |
+
# demo.load(fn=scatter_plot_fn_liveness, outputs = liveness_plot)
|
324 |
|
325 |
|
326 |
gradio_app = gr.mount_gradio_app(app, demo, "/gradio")
|