diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..7cc6c7a --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/spotify.sqlite3 + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/__pycache__/app.cpython-39.pyc b/__pycache__/app.cpython-39.pyc index 11dd665..6680745 100644 Binary files a/__pycache__/app.cpython-39.pyc and b/__pycache__/app.cpython-39.pyc differ diff --git a/__pycache__/models.cpython-39.pyc b/__pycache__/models.cpython-39.pyc new file mode 100644 index 0000000..8097bef Binary files /dev/null and b/__pycache__/models.cpython-39.pyc differ diff --git a/pages/__pycache__/__init__.cpython-39.pyc b/pages/__pycache__/__init__.cpython-39.pyc index c582af7..8b0795d 100644 Binary files a/pages/__pycache__/__init__.cpython-39.pyc and b/pages/__pycache__/__init__.cpython-39.pyc differ diff --git a/pages/__pycache__/index.cpython-39.pyc b/pages/__pycache__/index.cpython-39.pyc index fe76d26..20de876 100644 Binary files a/pages/__pycache__/index.cpython-39.pyc and b/pages/__pycache__/index.cpython-39.pyc differ diff --git a/pages/__pycache__/insights.cpython-39.pyc b/pages/__pycache__/insights.cpython-39.pyc index 80eb837..1fa9fb2 100644 Binary files a/pages/__pycache__/insights.cpython-39.pyc and b/pages/__pycache__/insights.cpython-39.pyc differ diff --git a/pages/__pycache__/predictions.cpython-39.pyc b/pages/__pycache__/predictions.cpython-39.pyc index c7d02e5..cf243d3 100644 Binary files a/pages/__pycache__/predictions.cpython-39.pyc and b/pages/__pycache__/predictions.cpython-39.pyc differ diff --git a/pages/__pycache__/process.cpython-39.pyc b/pages/__pycache__/process.cpython-39.pyc index ea16b98..bb42728 100644 Binary files a/pages/__pycache__/process.cpython-39.pyc and b/pages/__pycache__/process.cpython-39.pyc differ diff --git a/pages/predictions.py b/pages/predictions.py index 7c45845..7562688 100644 --- a/pages/predictions.py +++ b/pages/predictions.py @@ -1,10 +1,11 @@ -# 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 @@ -12,13 +13,13 @@ 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 @@ -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] @@ -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])