ToDo:
- [x]
This guide provides step-by-step instructions to deploy ML models through an API using a virtual machine in a cloud provider. It assumes a general cloud provider setup and covers the following steps:
-
Research and select a cloud provider that best suits for you. Popular options include AWS, Azure, and Google Cloud Platform. In this repo we use the free-tier account from each considered provider. However, this limits the computational resources to work on.
-
Sign up for an account on the chosen cloud provider and follow the instructions to enable the free-tier access.
-
Navigate to the cloud provider's management console.
-
Create a new virtual machine instance with the desired specifications (CPU, RAM, storage, ...). Ensure that you select the free-tier option if available.
-
Set up the virtual machine with the required operating system and configurations.
-
Note down the IP address or hostname of the virtual machine for future reference.
- Generate your SSH keys
ssh-keygen -t rsa -f ~/.ssh/my-key
- Add your public ssh key (my-key.pub) into your cloud provider's allowed keys.
- Connect to the VM using your private key and the public IP (X.X.X.X) of the VM
ssh -i ~/.ssh/my-key [email protected]
-
Install Git on the virtual machine if it's not already installed.
-
Clone the GitHub repository containing the ML model and API code using the following command:
git clone https://github.com/fjdurlop/deploy-GAISSA.git
- Install the necessary dependencies and packages required for running the API.
. ./scripts/setenv.sh
python3 -m pip install -r requirements.txt
-
Change into the cloned repository directory on the virtual machine.
-
Start the API server:
uvicorn app.api:app \ --host 0.0.0.0 \ --port 5000 \ --reload \ --reload-dir app \ --reload-dir models
Or
uvicorn app.api:app --host 0.0.0.0 --port 8000 --reload --reload-dir app
-
Create SSH tunnel to access endpoints, forwards traffic from my local port XXXX to the remote server's port XXXX
ssh -L 8000:localhost:8000 [email protected]
-
Open a web browser (http://localhost:8000/) or use a tool like cURL or Postman to make HTTP requests to the API endpoints.
-
Send requests to the API with the required input data and parameters to obtain predictions.