From 9b98c18239a08fd66334ec0e1607df1b7411a6de Mon Sep 17 00:00:00 2001 From: DataRaid Date: Wed, 26 May 2021 15:10:10 -0400 Subject: [PATCH] Added Prediction page slider --- .idea/dataSources.xml | 12 ++ __pycache__/app.cpython-39.pyc | Bin 566 -> 766 bytes __pycache__/models.cpython-39.pyc | Bin 0 -> 1303 bytes pages/__pycache__/__init__.cpython-39.pyc | Bin 170 -> 152 bytes pages/__pycache__/index.cpython-39.pyc | Bin 1214 -> 1196 bytes pages/__pycache__/insights.cpython-39.pyc | Bin 524 -> 506 bytes pages/__pycache__/predictions.cpython-39.pyc | Bin 649 -> 4144 bytes pages/__pycache__/process.cpython-39.pyc | Bin 522 -> 504 bytes pages/predictions.py | 205 ++++++++++++++++--- 9 files changed, 184 insertions(+), 33 deletions(-) create mode 100644 .idea/dataSources.xml create mode 100644 __pycache__/models.cpython-39.pyc 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 11dd665e438b7275f563bf9fe7979fcceb957703..6680745a5c7bee2a317d823baa7f026784d00c42 100644 GIT binary patch delta 434 zcmYjL%Syvg5WRDo-p2HisE7z6f+%)j3koiz2(iA3)?!-`?*J6L*-19a5eUiiivLNDqOlNSq$jFoCK_+{JiOsF-w8R$BC6(#lAz zb6setJ1LPY5Rv*r=>kCo^(){88c)5bKaYd7FrNCJ3CIvNlFfW}@@-@x(rTOQrn`TH z&DO*9>-NP^aOO5boXh9)fp;1<4qCacGQ$Tur|ZSlrSguoXx7aIv$kYyRZGi!U z%qc7>taF&s8Kc-z8M4?@IZ|0u*;3egnWH#U*i$*PxZ=4}I8r&|d4O!*DBcvtUo2{Lswo^3~xAwq= zCqPJWtc2Pe*ha9Nyn9lC| zw=a1*W}@zU#v^5ELdE0}lg6ccsr9-%TmV}zRTqSYGn_X2Lq>OqgV&7n0+I%$%yRt; z$q2j}aq(<0E(9BlS*i;u3Q0IqgPl4Z6Df9NF#)?8sIt)6emxKcWn8V7wedAmdckgJ zcSer1`ju17Z)V3qh#~Aygk9!Me3$`ssQcB$;S~RfsQ1&MJ`KPY&wLhUxHFHLt}k8_ z)1BMGd7hCpXo9{0XTN)p z-5Z`n8y|sk&mUbln~=-TiD34v7~lWTAQ?lfiIYUKQYOh`Kr>F9^k&Cf|F<~oKeV1U zQIeQWk^rG9ZuM@G99D!+S0r>9GT~OiE0LS%O|IF<@;;*`+|@wgk?dKIV4D|2n?+hl zqO&4TgfcNZE_s$_8b?IxOlgI?l5s{9ODNF{cPYtJM)oqE=^EIVGdZe_2e*b}UQ{$^ zN*UiW9WSbqv2>hS6Yi3t%acJp~avJ!ciBmD9J?uRLxOHSEWx zx6g?>NYo)G(|?GxZ7OZOrESXQhMS%>!8_a3P2_b4G4aN(^n C{|w>) diff --git a/pages/__pycache__/insights.cpython-39.pyc b/pages/__pycache__/insights.cpython-39.pyc index 80eb837d61ecb859a67717cd639353e82088a6e0..1fa9fb272fcb4d0294617a1fbbe771050d1be7ed 100644 GIT binary patch delta 48 zcmeBS`Nhne$ji&c00hb%>k?Qt^0qKC+D@Lts5AKjqb@%S4+{$u3nSBi5M<#4029p% Aga7~l delta 66 zcmeyx+{40~$ji&c00a}H*Ca4+ diff --git a/pages/__pycache__/predictions.cpython-39.pyc b/pages/__pycache__/predictions.cpython-39.pyc index c7d02e5ef8d81525a2bb07a28d532040d51cb277..cf243d378531a7431fc359bc9f615c19f03f1715 100644 GIT binary patch literal 4144 zcmd5;%WvGq87H|9uU?K`cKr7A6?;`_CHa}Su5HjUT^0qXu{$X)GvlS@zKVn1@eZ@zE7 z_k7;e)VPJ`FTeiu$GhF?yPMwXJ?L8pUpqF`tTU7Jhxe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zcmY*VF-rq67)^5NwcPb;9XhB>pi`k*60dm+%Q8w?W3E&;dalg(kWt>6CTQdCcGo5&sAr3CpprUtx&Ku;5+84fg+|= W;I!&i6=Q@U`ZDFBcYChj*!~7yfpYTz diff --git a/pages/__pycache__/process.cpython-39.pyc b/pages/__pycache__/process.cpython-39.pyc index ea16b98e680208507e9ba4215b24c58179b3a12c..bb427282f2a4caa45023700098c6a879fd5977ac 100644 GIT binary patch delta 30 kcmeBT`N7Pc$ji&c00hb%>o#(?GBVmsp2(;(`8=aF0B{=z;Q#;t delta 48 zcmeyt+{MD3$ji&c00a}H*KFi&Wn}c5JdsgHFtMOOKP9m^L$@R~w;(66Bz5v0MjHS* CcMgdF diff --git a/pages/predictions.py b/pages/predictions.py index fbc4cd7..c388d50 100644 --- a/pages/predictions.py +++ b/pages/predictions.py @@ -1,58 +1,197 @@ -# 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 -from tensorflow.keras.models import load_model -import numpy as np -from app import db, server, app -from models import spotify +import plotly.graph_objs as go import matplotlib.pyplot as plt +from plotly.tools import mpl_to_plotly -encodings = joblib.load(r'assets\encoded_data.joblib') -knn = joblib.load(r'assets\knn.joblib') -model = load_model(r'assets\ae4') +from app import app +column1 = dbc.Col( + [ + 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)}, -def recommend(index: int, n: int=5) -> 'tuple[np.ndarray]': - ''' - ### Parameters - index: index of song - n: number of recommendations to pull + ), + 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)}, - returns: (dist, ind), array of distances, array of indeces for recommended songs. Includes - original song. - ''' - return knn.kneighbors([encodings[index]], n_neighbors=5) + ), + 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)}, -def get_songs(indeces: 'list[int]') -> list: - ''' - Uses SQLAlchemy queries to return track data from their indeces - ''' - data = [spotify.query.filter(spotify.id == x).one() for x in indeces] - return data + ), + 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)}, + + ), + 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)}, -# 2 column layout. 1st column width = 4/12 -# https://dash-bootstrap-components.opensource.faculty.ai/l/components/layout -column1 = dbc.Col( - [ - dcc.Markdown( ), - # toy tests with no meaning other than seeing what works - F"{get_songs([0, 0])}" + + 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( [ + # 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]) \ No newline at end of file