-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
additional clustering, webapp development
- Loading branch information
1 parent
3d10216
commit ead281e
Showing
15 changed files
with
2,134 additions
and
37 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import pandas as pd | ||
import pickle as pkl | ||
import numpy as np | ||
from scipy.spatial.distance import pdist | ||
|
||
tsne = pd.read_csv('tsne_df_v1.csv') | ||
|
||
with open('web_features.pkl', 'rb') as f: | ||
artist_features = pkl.load(f) | ||
|
||
with open('scaled_df_v1.pkl', 'rb') as f: | ||
data = pkl.load(f) | ||
|
||
def show_stats(artist): | ||
return artist_features.loc[artist] | ||
|
||
def recommend(artist, n_recs=5): | ||
""" | ||
calculate n_recs closest artists in data by euclidean distance | ||
""" | ||
distances = [] | ||
target = data.loc[artist].to_numpy() | ||
artist_list = list(data.index) | ||
artist_list.remove(artist) | ||
|
||
for name in artist_list: | ||
comparison = data.loc[name].to_numpy() | ||
stack = np.vstack((target, comparison)) | ||
dist = pdist(stack) | ||
# dist = pairwise_distances(target, comparison) | ||
distances.append(dist[0]) | ||
|
||
top_n_ind = np.argsort(distances)[0:n_recs] | ||
|
||
return [artist_list[i] for i in top_n_ind] | ||
|
||
# def show_pic(artist): | ||
|
||
# def show_songs(artist): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import flask | ||
from flask import request | ||
from predictor_api import show_stats, recommend | ||
|
||
import pickle as pkl | ||
|
||
with open('all_artist_urls.pkl', 'rb') as f: | ||
links = pkl.load(f) | ||
|
||
app = flask.Flask(__name__) | ||
|
||
|
||
|
||
@app.route("/", methods=["GET", "POST"]) | ||
def landing(): | ||
return flask.render_template('landing.html') | ||
|
||
@app.route("/profile", methods=["GET", "POST"]) | ||
def get_artist_profile(): | ||
""" | ||
load rapper picture, stats, songs | ||
""" | ||
|
||
# look for the name searched from the landing page | ||
artist = request.form['artist'] | ||
query = request.args.to_dict() | ||
|
||
if query == {}: | ||
query = artist | ||
else: | ||
query = query['artist'] | ||
|
||
stats = show_stats(query) | ||
|
||
return flask.render_template('profile.html', | ||
stats = stats, | ||
artist = artist) | ||
|
||
@app.route("/recommend", methods=["GET", "POST"]) | ||
def get_recs(): | ||
""" | ||
generate recommendations | ||
""" | ||
artist = request.form['artist'] | ||
query = request.args.to_dict() | ||
|
||
if query == {}: | ||
query = artist | ||
else: | ||
query = query['artist'] | ||
|
||
recs = recommend(artist) | ||
stats = [show_stats(rec) for rec in recs] | ||
|
||
return flask.render_template('recommender.html', | ||
recs = recs, | ||
stats = stats, | ||
links = links, | ||
artist = artist) | ||
|
||
if __name__=='__main__': | ||
app.run(debug=True) | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
|
||
<head> | ||
</head> | ||
|
||
<body style="background-color:#b997e0;"> | ||
<div class='tableauPlaceholder' id='viz1597813392758' style='position: relative'><noscript><a href='#'><img alt=' ' src='https://public.tableau.com/static/images/ta/tab_viz_v1/Dashboard1/1_rss.png' style='border: none' /></a> | ||
</noscript><object class='tableauViz' style='display:none;'> | ||
<param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' /> | ||
<param name='embed_code_version' value='3' /> | ||
<param name='site_root' value='' /> | ||
<param name='name' value='tab_viz_v1/Dashboard1' /> | ||
<param name='tabs' value='no' /> | ||
<param name='toolbar' value='yes' /> | ||
<param name='static_image' value='https://public.tableau.com/static/images/ta/tab_viz_v1/Dashboard1/1.png' /> | ||
<param name='animate_transition' value='yes' /><param name='display_static_image' value='yes' /> | ||
<param name='display_spinner' value='yes' /> | ||
<param name='display_overlay' value='yes' /> | ||
<param name='display_count' value='yes' /> | ||
<param name='language' value='en' /> | ||
<param name='filter' value='publish=yes' /></object> | ||
</div> | ||
<script type='text/javascript'> var divElement = document.getElementById('viz1597813392758'); var vizElement = divElement.getElementsByTagName('object')[0]; if ( divElement.offsetWidth > 800 ) { vizElement.style.width='1366px';vizElement.style.height='795px';} else if ( divElement.offsetWidth > 500 ) { vizElement.style.width='1366px';vizElement.style.height='795px';} else { vizElement.style.width='100%';vizElement.style.height='977px';} var scriptElement = document.createElement('script'); scriptElement.src = 'https://public.tableau.com/javascripts/api/viz_v1.js'; vizElement.parentNode.insertBefore(scriptElement, vizElement); </script> | ||
<p> | ||
RAP GEO v1 | ||
<form action='/profile' method="POST"> | ||
<input type="text" name="artist"> | ||
<input type="submit" value="Check Profile"> | ||
</form> | ||
<form action='/recommend' method="POST"> | ||
<input type="text" name="artist"> | ||
<input type="submit" value="Get Recommendations"> | ||
</form> | ||
</p> | ||
|
||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
|
||
<head> | ||
</head> | ||
|
||
<body style="background-color:#b997e0;"> | ||
|
||
<p> | ||
<b>Artist</b>:<br> | ||
<b>{{ artist }}</b> <br> | ||
<br> | ||
|
||
<b>Lyrical Content</b>:<br> | ||
{{ stats['Lyrical/Misc'].round(3) }} Misc. Lyricism <br> | ||
{{ stats['Bragging/Combative'].round(3) }} Flexing & Threats<br> | ||
{{ stats['Money/Party'].round(3) }} Money & Partying <br> | ||
{{ stats['Romance/Sex'].round(3) }} Sex & Romance<br> | ||
<br> | ||
|
||
<b>Flow Statistics</b>:<br> | ||
{{ (stats['unique_word_rate'] * 100).round(1) }}% Word Uniqueness <br> | ||
{{ stats['syllables_per_line'].round(1) }} Syllables/Line<br> | ||
<br> | ||
|
||
<b>Style</b><br> | ||
{{ stats['cluster'] }} <br> | ||
|
||
<form action="/recommend" method="POST"> | ||
<input type="hidden" name="artist" value="{{ artist }}"> | ||
<input type="submit" value="Get Recommendations"> | ||
</form> | ||
<br> | ||
|
||
<form action='/profile' method="POST"> | ||
<input type="text" name="artist"> | ||
<input type="submit" value="Find Another Artist"> | ||
</form> | ||
|
||
<form action='/' method="POST"> | ||
<input type="submit" value="Return to Dashboard"> | ||
</form> | ||
|
||
</p> | ||
</body> | ||
</html> | ||
|
Oops, something went wrong.