Magenta developed a cool website to play piano with an AI in your browser. Discussing with @ghalestrilo we realized it might be useful to develop easier ways to interact with this technology programatically so I made this simple REST API.
You need to provide general details like tempo and length of the prediction to the AI, also the previous notes you want the machine to continue (if any).
Note: If you use the free public endpoint it might take a few seconds to start (it goes to sleep during inactivity) after that it should have a good time response.
{'pitches': [60, 60, 61, 62], 'start_times': [0, 1, 2, 3], 'durations': [1, 1, 1, 2], 'tempo': 120, 'length': 10}
{'pitches': [60, 60, 61, 62, 64, 60, 60, 62], 'start_times': [0.0, 1.0, 2.0, 3.0, 6.0, 7.0, 8.0, 9.0], 'durations': [1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0]}
curl --header "Content-Type: application/json" --request POST --data '{"pitches": [60, 60, 61, 62], "start_times": [0, 1, 2, 3], "durations": [1, 1, 1, 2], "tempo": 120, "length": 10}' https://ai-duet-ilfqxfroaq-uc.a.run.app/predict
python client.py
pip install -r requirements.txt
python server.py