-
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.
Browse files
Browse the repository at this point in the history
This reverts commit 2572cb8.
- Loading branch information
1 parent
2572cb8
commit 33b8a3c
Showing
11 changed files
with
203 additions
and
109 deletions.
There are no files selected for viewing
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,27 @@ | ||
secret_key = "highscore" | ||
|
||
|
||
class Highscore: | ||
def __init__(self, request): | ||
self.session = request.session | ||
scores = self.session.get(secret_key) | ||
|
||
if not scores: | ||
# save an empty scores dict in the session | ||
scores = self.session[secret_key] = {} | ||
|
||
self.scores = scores | ||
|
||
def add_score(self, id, song, artist, prediction): | ||
if id not in self.scores: | ||
self.scores[id] = { | ||
"song": song, | ||
"artist": artist, | ||
"prediction": prediction, | ||
} | ||
|
||
def get_highscore(self): | ||
highscore = sorted( | ||
self.scores.values(), key=lambda x: x["prediction"], reverse=True | ||
)[:5] | ||
return highscore |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<div class="container-fluid my-5 mx-5" style="height: 18em;" id="songForm"> | ||
|
||
<h3 class="text-left display-5">Let's predict the number of streams for a song</h3> | ||
|
||
<div class="text-danger font-weight-bold"> | ||
{% for error in errors %} | ||
<li>{{error}}</li> | ||
{% endfor %} | ||
</div> | ||
|
||
|
||
<h4 class="text-left display-7">Choose a song!</h4> | ||
|
||
|
||
|
||
<form id="myForm" action="/search_song" method="POST" hx-boost="true" hx-trigger="submit" hx-swap="outerHTML" | ||
hx-target="#songForm"> | ||
|
||
<div class="mb-3"> | ||
<input type="text" required placeholder="Choose an artist e.g Queen" name="artist" value="{{artist}}" | ||
class="form-control"> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<input type="text" required placeholder="Choose a song e.g Don't stop me now" name="song" value="{{song}}" | ||
class="form-control"> | ||
</div> | ||
|
||
<div class="class text-center"> | ||
<button type="submit" hx-trigger="submit">Search</button> | ||
<!-- <button type="submit" hx-trigger="click" hx-get="/success_endpoint" hx-target="#songForm" | ||
hx-swap="innerHTML">Search</button> --> | ||
</div> | ||
|
||
|
||
</form> | ||
|
||
<!-- <div hx-target="#songForm" hx-trigger="submit" hx-swap="innerHTML"></div> --> | ||
|
||
|
||
</div> |
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,38 @@ | ||
<div class="container-fluid my-5 mx-5" style="height: 18em;" id="songOutput"> | ||
|
||
|
||
<!-- <h2 class="text-center display-7">{{header}}</h2> --> | ||
<h3 class="text-left display-5">{{header}}</h3> | ||
|
||
<hr style="border-bottom: 1px solid #888"> | ||
|
||
Number of streams: {{prediction["prediction"]}} | ||
Message: {{prediction["message"]["text"]}} {{prediction["message"]["emoji"]}} | ||
|
||
<!-- <h4 class="text-left display-10">{{prediction["features"]}}</h4> --> | ||
|
||
|
||
|
||
|
||
|
||
{% for key, value in prediction["song_metadata"].items() %} | ||
{{key}}: {{ value }} | ||
{% endfor %} | ||
|
||
|
||
{% if prediction["preview_url"] is not none %} | ||
<div class="container-audio"> | ||
<audio controls> | ||
<source src={{prediction["preview_url"]}} /> | ||
</audio> | ||
</div> | ||
{% endif %} | ||
|
||
<div class="class text-center"> | ||
<a href="/"><button type="submit">Try it again!</button></a> | ||
|
||
</div> | ||
|
||
|
||
|
||
</div> |
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
This file was deleted.
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
Oops, something went wrong.