Skip to content

mathigatti/magenta-piano-duet-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magenta Piano Duet API

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.

How do I use it?

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.

The input data should look like this

{'pitches': [60, 60, 61, 62], 'start_times': [0, 1, 2, 3], 'durations': [1, 1, 1, 2], 'tempo': 120, 'length': 10}

The predicted value you get as output will looks like this

{'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]}

Usage examples

Using CURL

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

Using Python

python client.py

How do I run the server locally?

1. Install requirements

pip install -r requirements.txt

2. Run server

python server.py