Skip to content

Commit

Permalink
ID-Based Return Fuctionality, Spotify Embeds added, File Restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
vijay-jaisankar committed Sep 6, 2021
1 parent c5e2928 commit 22a12a9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 53 deletions.
16 changes: 7 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@

songDataLoader = SongData(creds.CLIENT_ID,creds.CLIENT_SECRET)

NUM_SONGS_SHOW = 10


app = Flask(
__name__,
template_folder="templates",
static_folder="static"
)

@app.route("/")
def index():
return render_template("index.html")

@app.route("/predict/", methods = ["GET","POST"])
@app.route("/", methods = ["GET","POST"])
def predict():
if request.method == "POST":

Expand All @@ -31,13 +29,13 @@ def predict():

label = getLabel(model,
song_features)
songsList = getSongsWithLabel(label,4)

print(songsList)
return render_template("predict.html",label = str(label), displayForm = False, songsList = songsList)

indexListRet = getSongsWithLabel(label,NUM_SONGS_SHOW)
return render_template("index.html",label = str(label), displayForm = False, indexList = indexListRet)

else:
return render_template("predict.html", label = "", displayForm = True, songsList = [])
return render_template("index.html", label = "", displayForm = True, indexListRet = [])

if __name__ == "__main__":
app.run(debug=True)
1 change: 0 additions & 1 deletion creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@

CLIENT_ID = ""
CLIENT_SECRET = ""

18 changes: 18 additions & 0 deletions displaysongdetails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Class to describe how songs are displayed in the webapp
"""

class DisplaySong():

def __init__(self, name, id):
self.name = name
self.id = id
self.iframe = self.getIFrameLink()

def setIFrameLink(self):
return format('<iframe src="https://open.spotify.com/embed/track/{self.id}}" width="300" height="80" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>')

def getIFrameLink(self):
return self.iframe


3 changes: 2 additions & 1 deletion helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def getLabel(model, inputValues):
def getSongsWithLabel(label,numSongs=5):
label = int(label)
label_df = df[df["label"] == label]
return (label_df.sample(numSongs)["name"])[:numSongs]

return label_df.sample(numSongs)["id"][:numSongs]



36 changes: 33 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,40 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../static/styles.css">
<title>Spotifynd</title>
<link rel="stylesheet" href="../static/predict.css">
<title>Predictions</title>
</head>
<body>
<h1>Welcome to spotifynd.</h1>


{% if displayForm %}

<form action="{{ url_for('predict')}}" method="post">

<label for="song_id">song_id:</label>
<input type="text" id="song_id" name="song_id" placeholder="song_id">


<button type="submit">Get Songs!</button>

</form>

{% endif %}



{% for i in indexList %}

<iframe src="https://open.spotify.com/embed/track/{{i}}" width="100%" height="80" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>

<br>


{% endfor %}

{% if not displayForm %}
<a href="{{ url_for('predict')}}"> Try Again!</a>
{% endif %}

</body>
</html>
39 changes: 0 additions & 39 deletions templates/predict.html

This file was deleted.

0 comments on commit 22a12a9

Please sign in to comment.