-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyApp.py
135 lines (106 loc) · 4.31 KB
/
MyApp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import dash
import dash_table
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import pandas as pd
#df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv')
df = pd.read_csv('data.csv')
net_df = pd.read_csv('net_preds.csv')
df_pred = pd.read_csv('predicted_genera.csv')
df_pred.drop(['genera','Unnamed: 0'], inplace=True, axis=1)
net_df.drop(['genera','Unnamed: 0'], inplace=True, axis=1)
df_lab = pd.read_csv("labeled_genera.csv")
df = df_pred.copy()
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server
app.title='Music'
app.layout = html.Div([
html.H4(children='Music'),
dcc.Input(id="art_text", type="text", value="Kanye", placeholder='Artist'),
dcc.Input(id="song_text", type="text", value="", placeholder='Song'),
#dash_table.DataTable(
#id='data-table',
#columns=[{"name": i, "id": i} for i in df.columns],
#data=[]),
dcc.Graph(id='graph-with-slider'),
dcc.Graph(id='net-graph'),
dcc.Dropdown(
id='y-slider',
options=[{'label': i, 'value': i} for i in df.columns],
value='popularity'
),
dcc.Dropdown(
id='x-slider',
options=[{'label': i, 'value': i} for i in df.columns],
value='year'),
html.P("This app was made by George Mazzeo, Ryan Powell, Anastasios Glaros")
])
@app.callback(
Output('graph-with-slider', 'figure'),
Output('net-graph', 'figure'),
Input('y-slider', 'value'),
Input('x-slider', 'value'),
#Input('c-slider', 'value'),
Input('art_text', 'value'),
Input('song_text', 'value'))
def update_figure(selected_y, selected_x,art,song_name):
#filtered_df = df[df.year == selected_year]
filtered_df = df.copy()[0:0]
f_net = net_df.copy()[0:0]
if art != '':
art = art.split(',')
filtered_df = df[df.artists.str.contains(art[0])]
f_net = net_df[net_df.artists.str.contains(art[0])]
for i in range(0,len(art)):
filtered_df = filtered_df.append(df[df.artists.str.lower().str.contains(art[i].lower())])
f_net = f_net.append(net_df[net_df.artists.str.lower().str.contains(art[i].lower())])
if song_name != "":
filtered_df = filtered_df[filtered_df.name.str.lower().str.contains(song_name.lower())]
f_net = f_net[f_net.name.str.lower().str.contains(song_name.lower())]
elif song_name != "" and art == None:
if song_name != "":
filtered_df = df[df.name.str.lower().str.contains(song_name.lower())]
f_net = net_df[net_df.name.str.lower().str.contains(song_name.lower())]
elif art == None or art == '' and song_name =='':
#art = 'Bob Dylan'
filtered_df = df#[df.artists.str.contains(art)]
f_net = net_df#[df.artists.str.contains(art)]
color_dict = {
'hip-hop':'#636EFA',
'jazz':'#EF553B',
'rock':'#00CC96',
'classical':'#AB63FA',
'metal':'#FFA15A',
'reggae':'#19D3F3'
}
#print(filtered_df.columns)
size = f_net[["jazz", "classical", "rock", "hip-hop", "reggae", "metal"]].max(axis=1)
size_norm = []
for element in size:
if element > 0.5:
size_norm.append((element - 0.5) * 2)
else:
size_norm.append(0.1)
fig = px.scatter(
filtered_df, y=selected_y, x=selected_x, color='pred',
color_discrete_map=color_dict, hover_data=["name","artists"],opacity=0.7,
title='Random Forest'
)
fig_net = px.scatter(f_net, y=selected_y, x=selected_x, hover_data=[
"name","artists", "jazz", "classical", "rock", "hip-hop", "reggae", "metal"
],opacity=1, color_discrete_map=color_dict,color=f_net[["jazz", "classical", "rock", "hip-hop", "reggae", "metal"]].idxmax(axis=1),
#size=size_norm,
title ="Neural Network")
fig.update_layout(transition_duration=500)
fig_net.update_layout(transition_duration=500)
#return filtered_df.to_dict('records'),fig
#print(filtered_df.columns)
return fig, fig_net
if __name__ == '__main__':
app.run_server(debug=True)#,host='192.168.86.57',port=8052)
#192.168.86.57