From 363b9b3a4626720e92ee051b3c2e74863f6f6304 Mon Sep 17 00:00:00 2001 From: Tetsuyasu Yamada Date: Tue, 23 Oct 2018 17:41:04 +0900 Subject: [PATCH] Python3 compatibility --- server/server.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/server.py b/server/server.py index cb31fe8..bce6385 100644 --- a/server/server.py +++ b/server/server.py @@ -22,7 +22,7 @@ import sys if sys.version_info.major <= 2: from cStringIO import StringIO else: - from io import StringIO + from io import BytesIO import time import json @@ -34,7 +34,10 @@ app = Flask(__name__, static_url_path='', static_folder=os.path.abspath('../stat def predict(): now = time.time() 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')) ret_midi = generate_midi(midi_data, duration) return send_file(ret_midi, attachment_filename='return.mid',