-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathapp.py
38 lines (32 loc) · 1000 Bytes
/
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
import flask, flask.views
from flask import request
from algorithmia import get_playlist
from algorithmia import get_emotion_grid
import numpy as np
from PIL import Image
import re
from io import BytesIO
import base64
app = flask.Flask(__name__)
app.secret_key = "bacon"
@app.route('/')
def index():
return flask.render_template("musi.html", songs=[])
@app.route('/hook', methods=['POST'])
def get_image():
#convert base64 image
image_b64 = request.values['imageBase64']
image_data = re.sub('^data:image/.+;base64,', '', image_b64)
image_PIL = Image.open(BytesIO(base64.b64decode(image_data)))
image_PIL.save("snapshots/pic.png", mode='RGB')
songs = get_playlist()
print(songs)
return flask.render_template("musi.html", songs=songs)
@app.route('/graph')
def get_graph():
#draw emotion grid
get_emotion_grid()
songs = get_playlist()
return flask.render_template("musi.html", songs=songs)
if __name__ == '__main__':
app.run(debug=True)