-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.py
63 lines (52 loc) · 2.11 KB
/
app.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
from flask import Flask, render_template, redirect, jsonify, request
import spotify
# Create an instance of Flask
app = Flask(__name__)
# Route to render index.html
@app.route("/")
def home():
return render_template("index.html", item='home')
@app.route("/home")
def home2():
return render_template("index.html", item='home')
# Route for hit_flop
@app.route('/hit_flop', methods = ['POST'])
def hit_flop():
track = request.form["song"]
artist = request.form["artist"]
print(track, artist)
response = spotify.hit_flop(track, artist)
try:
print(response)
# hit_predict, hit_score = spotify.hit_flop(track, artist)
if len(response) == 3:
hit_predict = response[0]
hit_score = response[1]
feature_table = response[2]
track = f'{track} by {artist}'
if hit_predict[0] == 1:
result = 'Looks like a hit!'
score = f"There's a {round(hit_score[0][1]*100,0)}% chance it'll be a hit"
else:
result = 'It could be a flop'
score = f"There's a {round(hit_score[0][0]*100,0)}% chance it'll be a flop =("
return render_template("index.html", result=result, score=score, feature_table=feature_table, song=track)
else:
error = response[0]
return render_template("index.html", score=error, item='home')
except Exception as inst:
return render_template("index.html", score=inst, item='home')
print("#################################################")
print(type(inst)) # the exception instance
print(inst.args) # arguments stored in .args
print(inst) # __str__ allows args to be printed directly,
# but may be overridden in exception subclasses
# unpack args
@app.route("/about/")
def about():
return render_template("about.html", item='about')
@app.route("/historical/")
def historical():
return render_template("historical.html", item='historical')
if __name__ == "__main__":
app.run(debug=True)