Commit
·
9baeb63
1
Parent(s):
f7e616d
plots
Browse files
app.py
CHANGED
@@ -198,14 +198,31 @@ from vega_datasets import data
|
|
198 |
iris = data.iris()
|
199 |
|
200 |
|
201 |
-
def
|
|
|
202 |
token = request.request.session.get('token')
|
203 |
if token:
|
204 |
sp = spotipy.Spotify(token)
|
205 |
results = sp.current_user()
|
206 |
print(results)
|
|
|
207 |
return gr.ScatterPlot(
|
208 |
-
value=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
)
|
210 |
|
211 |
def heatmap_plot_fn(request: gr.Request):
|
@@ -213,7 +230,7 @@ def heatmap_plot_fn(request: gr.Request):
|
|
213 |
if token:
|
214 |
sp = spotipy.Spotify(token)
|
215 |
data = heatmap.build_heatmap(heatmap.fetch_recent_songs(sp))
|
216 |
-
fig,
|
217 |
return fig
|
218 |
|
219 |
|
@@ -236,9 +253,9 @@ def get_features(spotify):
|
|
236 |
'valence',
|
237 |
'tempo',
|
238 |
]
|
239 |
-
|
240 |
# print (features_means.to_json())
|
241 |
-
return
|
242 |
|
243 |
|
244 |
##########
|
@@ -258,14 +275,13 @@ with gr.Blocks() as demo:
|
|
258 |
with gr.Column():
|
259 |
with gr.Row():
|
260 |
with gr.Column():
|
261 |
-
|
262 |
-
with gr.Column():
|
263 |
-
plot = gr.ScatterPlot(show_label=False).style(container=True)
|
264 |
-
with gr.Row():
|
265 |
-
with gr.Column():
|
266 |
-
plot = gr.ScatterPlot(show_label=False).style(container=True)
|
267 |
with gr.Column():
|
268 |
-
|
|
|
|
|
|
|
|
|
269 |
with gr.Row():
|
270 |
gr.Markdown(" ### We have recommendations for you!")
|
271 |
with gr.Row():
|
@@ -275,9 +291,10 @@ with gr.Blocks() as demo:
|
|
275 |
label="Reccomended Songs",
|
276 |
value=[["something", "something", "something"], ["something", "something", "something"]] # TODO: replace with actual reccomendations once get_started() is implemeted.
|
277 |
)
|
278 |
-
|
279 |
-
demo.load(fn=heatmap_plot_fn,
|
280 |
-
demo.load(fn=
|
|
|
281 |
|
282 |
|
283 |
gradio_app = gr.mount_gradio_app(app, demo, "/gradio")
|
|
|
198 |
iris = data.iris()
|
199 |
|
200 |
|
201 |
+
def scatter_plot_fn_energy(request: gr.Request):
|
202 |
+
|
203 |
token = request.request.session.get('token')
|
204 |
if token:
|
205 |
sp = spotipy.Spotify(token)
|
206 |
results = sp.current_user()
|
207 |
print(results)
|
208 |
+
df = get_features(sp)
|
209 |
return gr.ScatterPlot(
|
210 |
+
value=df,
|
211 |
+
x="danceability",
|
212 |
+
y="energy"
|
213 |
+
)
|
214 |
+
|
215 |
+
def scatter_plot_fn_liveness(request: gr.Request):
|
216 |
+
token = request.request.session.get('token')
|
217 |
+
if token:
|
218 |
+
sp = spotipy.Spotify(token)
|
219 |
+
results = sp.current_user()
|
220 |
+
print(results)
|
221 |
+
df = get_features(sp)
|
222 |
+
return gr.ScatterPlot(
|
223 |
+
value=df,
|
224 |
+
x="acousticness",
|
225 |
+
y="liveness"
|
226 |
)
|
227 |
|
228 |
def heatmap_plot_fn(request: gr.Request):
|
|
|
230 |
if token:
|
231 |
sp = spotipy.Spotify(token)
|
232 |
data = heatmap.build_heatmap(heatmap.fetch_recent_songs(sp))
|
233 |
+
fig, ax = heatmap.plot(data)
|
234 |
return fig
|
235 |
|
236 |
|
|
|
253 |
'valence',
|
254 |
'tempo',
|
255 |
]
|
256 |
+
|
257 |
# print (features_means.to_json())
|
258 |
+
return df
|
259 |
|
260 |
|
261 |
##########
|
|
|
275 |
with gr.Column():
|
276 |
with gr.Row():
|
277 |
with gr.Column():
|
278 |
+
energy_plot = gr.ScatterPlot(show_label=False).style(container=True)
|
|
|
|
|
|
|
|
|
|
|
279 |
with gr.Column():
|
280 |
+
liveness_plot = gr.ScatterPlot(show_label=False).style(container=True)
|
281 |
+
with gr.Row():
|
282 |
+
gr.Markdown(" ### We have recommendations for you!")
|
283 |
+
with gr.Row():
|
284 |
+
heatmap_plot = gr.Plot()
|
285 |
with gr.Row():
|
286 |
gr.Markdown(" ### We have recommendations for you!")
|
287 |
with gr.Row():
|
|
|
291 |
label="Reccomended Songs",
|
292 |
value=[["something", "something", "something"], ["something", "something", "something"]] # 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")
|