Python3 compatibility

This commit is contained in:
Tetsuyasu Yamada 2018-10-23 17:41:04 +09:00
parent c17aa14601
commit 363b9b3a46

View File

@ -22,7 +22,7 @@ import sys
if sys.version_info.major <= 2: if sys.version_info.major <= 2:
from cStringIO import StringIO from cStringIO import StringIO
else: else:
from io import StringIO from io import BytesIO
import time import time
import json import json
@ -34,7 +34,10 @@ app = Flask(__name__, static_url_path='', static_folder=os.path.abspath('../stat
def predict(): def predict():
now = time.time() now = time.time()
values = json.loads(request.data) values = json.loads(request.data)
midi_data = pretty_midi.PrettyMIDI(StringIO(''.join(chr(v) for v in values))) if sys.version_info.major <= 2:
midi_data = pretty_midi.PrettyMIDI(StringIO(''.join(chr(v) for v in values)))
else:
midi_data = pretty_midi.PrettyMIDI(BytesIO(b''.join([v.to_bytes(1,'big') for v in values])))
duration = float(request.args.get('duration')) duration = float(request.args.get('duration'))
ret_midi = generate_midi(midi_data, duration) ret_midi = generate_midi(midi_data, duration)
return send_file(ret_midi, attachment_filename='return.mid', return send_file(ret_midi, attachment_filename='return.mid',