Skip to content

Commit

Permalink
Merge branch 'main' into visuals
Browse files Browse the repository at this point in the history
  • Loading branch information
rhiag authored May 27, 2021
2 parents c0af886 + 82f4a63 commit 7fc02b3
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 7 deletions.
12 changes: 12 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified __pycache__/app.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file modified pages/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified pages/__pycache__/index.cpython-39.pyc
Binary file not shown.
Binary file modified pages/__pycache__/insights.cpython-39.pyc
Binary file not shown.
Binary file modified pages/__pycache__/predictions.cpython-39.pyc
Binary file not shown.
Binary file modified pages/__pycache__/process.cpython-39.pyc
Binary file not shown.
193 changes: 186 additions & 7 deletions pages/predictions.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# Imports from 3rd party libraries
import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import joblib
import plotly.graph_objs as go
import matplotlib.pyplot as plt
from plotly.tools import mpl_to_plotly
from tensorflow.keras.models import load_model
import numpy as np
from tensorflow.python.training.tracking.util import list_objects
from app import db, server, app
from models import spotify
import matplotlib.pyplot as plt
import plotly.express as px
import joblib


encodings = joblib.load(r'assets/encoded_data.joblib')
knn = joblib.load(r'assets/knn.joblib')
model = load_model(r'assets/ae4')



def recommend(index: int, n: int=5) -> 'tuple[np.ndarray]':
'''
### Parameters
Expand All @@ -38,6 +39,7 @@ def get_songs(indeces: 'list[int]') -> list:
data = [spotify.query.filter(spotify.id == x).one() for x in indeces]
return data


def plot_graph(data:list):
g_name = [(x.name) for x in data]
g_popularity = [(x.popularity) for x in data]
Expand Down Expand Up @@ -68,21 +70,198 @@ def plot_graph(data:list):

column1 = dbc.Col(
[
dcc.Markdown(

html.Br(),
html.Br(),
html.H6('Duration'),
dcc.Slider(
id='slider-1',
min=90,
max=100,
value=45,
step=.1,
# marks={i:str(i) for i in range(90,101)},

),
html.H6('Explicit'),
dcc.Slider(
id='slider-2',
min=0,
max=1,
step=1,
value=0,
# marks={i:str(i) for i in range(1,11)},

),
html.H6('Loudness'),
dcc.Slider(
id='slider-3',
min=.01,
max=1,
step=.01,
value=.5,
# marks={i:str(i) for i in range(1,11)},

),
html.H6('Danceability'),
dcc.Slider(
id='slider-4',
min=0.01,
max=1,
step=0.01,
value=.5,
# marks={i:str(i) for i in range(0,2)},

),
html.H6('Accousticness'),
dcc.Slider(
id='slider-5',
min=0.01,
max=38,
step=0.01,
value=19,
# marks={i:str(i) for i in range(0,39)},

),
html.H6('Energy'),
dcc.Slider(
id='slider-6',
min=0.01,
max=1,
step=0.01,
value=.5,
# marks={i:str(i) for i in range(1,11)},

),
html.H6('Instrumentalness'),
dcc.Slider(
id='slider-7',
min=0.01,
max=1,
step=0.01,
value=.5,
# marks={i:str(i) for i in range(0,1)},

),

# toy tests with no meaning other than seeing what works
F"{get_songs([0, 1,2,3])}"


html.H6('Liveness'),
dcc.Slider(
id='slider-8',
min=0.01,
max=1,
step=0.01,
value=.5,
# marks={i:str(i) for i in range(1,9)},

),
html.H6('Popularity'),
dcc.Slider(
id='slider-9',
min=0.01,
max=1,
step=0.01,
value=.5,
# marks={i:str(i) for i in range(1,9)},

),
html.H6('Speechiness'),
dcc.Slider(
id='slider-10',
min=0.1,
max=1,
step=0.01,
value=.5,
# marks={i:str(i) for i in range(1,9)},

),
html.H6('Tempo'),
dcc.Slider(
id='slider-11',
min=60,
max=240,
step=5,
value=92,
marks={i: str(i) for i in range(60, 241, 20)},

),
html.Br(),
html.Br(),
html.H6('Release_date'),
dcc.Slider(
id='slider-0',
min=1960,
max=2020,
step=1,
value=1990,
marks={i: str(i) for i in range(1960, 2021, 10)},

),

html.Br(),
html.Br(),
html.Br(),

],
md=4
md=4,
)



column2 = dbc.Col(
[html.Br(),
html.Div(id='prediction-text1', children='output will go here', style={'color': 'green', 'fontSize': 16}),
html.Br(),
html.Div(id='prediction-text2', children='output will go here', style={'fontSize': 16}),
html.Br(),
html.Div(id='prediction-text3', children='output will go here', style={'color': 'green', 'fontSize': 16}),
html.Div(id='prediction-text4', children='output will go here', style={'color': 'green', 'fontSize': 16}),
html.Div(id='prediction-text5', children='output will go here', style={'color': 'green', 'fontSize': 16}),
html.Br(),
html.Div(id='prediction-text6', children='output will go here', style={'fontSize': 16}),
html.Div(id='prediction-text7', children='output will go here', style={'color': 'green', 'fontSize': 16}),

],
md=3,

)

column3 = dbc.Col(
[

#Sanity Test
dcc.Graph(figure=plot_graph(data=get_songs([0,6,1609,34455])))


# html.Div(id='prediction-text',children='output will go here'),
dcc.Markdown(
"""
**Instructions**: Adjust the attribute sliders. Your prediction outcome will update dynamically.
Attribute Definitions:
* **Duration** - Length of the song in ms
* ** Explicit** - Has curse words or language or art that is sexual, violent, or offensive in nature. Left for none and right for has.
* **Loudness** -How loud the songs are in dB ranging from -60 to 0
* **Danceability** - Danceability describes how suitable a track is for dancing based on a combination of musical elements including tempo, rhythm stability, beat strength, and overall regularity. A value of 0.0 is least danceable and 1.0 is most danceable.
* **Acousticness** -Whether the tracks of artist are acoustic
* **Energy** - Energy is a measure from 0.0 to 1.0 and represents a perceptual measure of intensity and activity.
* **Instrumentalness** - Predicts whether a track contains no vocals. The closer the instrumentalness value is to 1.0, the greater likelihood the track contains no vocal content.
* **Liveness** - how present audience are in artists songs
* **US Popularity Level** - Highest point on Billboard
* **Speechiness** - Speechiness detects the presence of spoken words in a track. The more exclusively speech-like the recording (e.g. talk show, audio book, poetry), the closer to 1.0 the attribute value.
* **Tempo** - The overall estimated tempo of a track in beats per minute (BPM). In musical terminology, tempo is the speed or pace of a given piece and derives directly from the average beat duration.
* **Year of Release** - Year the track was released
"""
),
# html.Div(id='shapley',children='output will go here'),
# dcc.Graph(id='my-graph-name', figure=plotly_figure)


]

)

layout = dbc.Row([column1, column2])
layout = dbc.Row([column1, column2, column3])

0 comments on commit 7fc02b3

Please sign in to comment.