- Install Google Cloud CLI and authenticate following the link here and here.
- Build the docker image using the file:
Dockerfile
docker build .
- Provide name and tag to the docker image following the instructions here:
docker tag <image_id> <name>:<tag>
- Push to the Google Container Registry
docker push <name>:<tag>
5. In the Cloud Run console, select
Edit and Deploy new revision
- Find the link to the image that we pushed in the Google container registry and provide it in the
Container Image URL
- Set Container port to
5000
. Flask app will use 5000 port for communication. - Set the Memory and CPU capacity as per requirement. I used the Memory as 2GiB and CPU as 1.
- Change other parameters as required and deploy the app.
- Find the deployment URL after the deployment.
Python
import requests
url = "<deployment_url>"
payload={}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
cURL
curl --location --request GET '<deployment_url>'
Response Sample:
Welcome to MobileNet Flask App! OS Project 2022.
cURL
curl --location --request POST '<deployment_url>' \
--header 'x-api-key: 1234' \
--form 'image=@"<image_path>"'
Python
import requests
url = "<deployment_url>/predict"
payload={}
files=[
('image',('car.jpg',open('<image_path>','rb'),'image/jpeg'))
]
headers = {
'x-api-key': '1234'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
OR
cURL
curl --location --request POST '<deployment_url>' \
--header 'x-api-key: 1234' \
--form 'image="<image_url>"'
Python
import requests
url = "<deployment_url>/predict"
payload={'image': '<image_url>'}
files=[
]
headers = {
'x-api-key': '1234'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
Response Sample:
{
"Prediction": "sports car",
"message": "Success"
}
https://github.com/pranjal1/ML_Deploy/blob/main/results/cloud_run.ipynb