polyphemus / app.py
EmanueleCosenza's picture
Working version
d896bd4
raw
history blame
1.24 kB
from flask import Flask, render_template, jsonify, request
import json
import subprocess
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/generate_midi', methods=['POST'])
def generate_midi():
data = request.json
keep_tonality = data.get('keepTonality', False)
use_grid = data.get('useGrid', True)
arguments = ['python3', 'generate.py', 'models/LMD2/', 'static/',
'--n', '1', '--no_audio']
if keep_tonality:
arguments.extend(['--z_file', 'static/0/z'])
if use_grid:
arguments.extend(['--s_file', 'static/0/structure.json'])
subprocess.run(arguments, capture_output=True, text=True)
filename = "generated.mid"
return jsonify({"filename": filename})
@app.route('/save_json', methods=['POST'])
def save_json():
data = request.json
filepath = 'static/0/structure.json'
with open(filepath, 'w') as file:
json.dump(data, file)
return jsonify(message="JSON saved successfully!")
@app.route('/load_grid')
def load_grid():
with open('static/0/structure.json', 'r') as file:
data = json.load(file)
return jsonify(data)
if __name__ == '__main__':
app.run(debug=True)