-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
35 lines (27 loc) · 868 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
from flask import Flask, render_template, Response
import functions
import composer
import os
app = Flask(__name__)
@app.route('/')
def main_page():
return render_template('index.html')
@app.route('/compose/<search>', methods=['POST', 'GET'])
def compose(search):
def generate(tweet, mood):
melodyList = composer.melodize(tweet, mood)
midi = composer.midFile(melodyList)
yield midi
tweet = functions.searchTweets(search)
if tweet is None:
return None
#Scale will default to minor because minor scales are cooler
mood = 1
if ":)" in search:
mood = 0
resp = Response(generate(tweet, mood), mimetype='audio/midi')
resp.set_cookie('tweet', tweet)
return resp
if __name__ == '__main__':
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port, debug="true")