Skip to content

ariessa/Melofy-API

Repository files navigation

Melofy API

An API in Python for generating melody from supplied audio file link.


Prerequisites

In order to run this API, you need to install the following software first:


API Endpoints

  • /

    A route to the homepage


    Example using curl command to send GET request in Windows CMD

    curl http://melofyapi.ap.ngrok.io
    

  • /generate

    A route to generate melody from supplied audio file link


    Example using curl command to send POST request in Windows CMD

    curl -i -X POST -H "Content-Type:application/json" -d "{\"audio_file_link\": \"https://melofyapi.blob.core.windows.net/melofy-api-input/twinkle_twinkle_little_star.wav\" }" http://melofyapi.ap.ngrok.io/generate
    

Deploy


Deploy Flask app locally


  1. Clone GitHub repository
git clone https://github.com/ariessa/melofy-api.git
  1. Create new conda environment named snakes that contains Python 3.7
conda create -n snakes python=3.7
  1. Activate new environment
conda activate snakes
  1. Use pip to install packages
pip install audio-to-midi azure-storage-blob flask google-cloud-storage gunicorn magenta timidity
  1. Run flask app
flask run

Congratulations, you just run the Flask app locally!


Expose Local Flask App to the Internet


  1. Enable incoming traffic for port 5000. This is done by navigating to Control Panel> System and Security > Windows Defender Firewall > Advanced Settings

Advanced Settings


  1. In Advanced Settings, click on Inbound Rules

  1. After clicking Inbound Rules, click on New Rules in the Action column

Inbound Rules


  1. In New Inbound Rule Wizard, select Rule Type as Port and click Next

New Inbound Rule Wizard


  1. In New Inbound Rule Wizard, apply rule to TCP and set specific local port to 5000 and click Next

Protocol and Ports


  1. In New Inbound Rule Wizard, specify action to Allow the connection and click Next

Action


  1. In New Inbound Rule Wizard, specify profile for which rule applies to Private

Profile


  1. Still in New Inbound Rule Wizard, specify name to Melofy API Port 500 and description to Allow inbound connection to local port 5000 using private connection and click Finish

Name


  1. Check New Inbound Rule in the list of Inbound Rules

Check New Inbound Rule

Congratulations, you just exposed local port 5000 to the Internet!


Start Ngrok


Basic Command


Expose a web server on port 5000 of your local machine to the Internet

ngrok http 5000

Advanced Commands


Expose a web server on port 5000 of your local machine to the Internet, set region to Asia Pasific, and subdomain to melofyapi

ngrok http -region=ap -hostname=melofyapi.ap.ngrok.io 5000

Congratulations, you can now access the API at http://melofyapi.ap.ngrok.io!



Examples of Azure Blob Storage Usage

About

An API in Python for generating melody from supplied audio file link.

Topics

Resources

License

Stars

Watchers

Forks

Languages