Spaces:
Runtime error
Runtime error
| from flask import Flask, render_template, jsonify, request | |
| import json | |
| import subprocess | |
| app = Flask(__name__) | |
| def index(): | |
| return render_template('index.html') | |
| 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}) | |
| 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!") | |
| 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) | |