🇮🇩 Part of Bangkit 2022
🛑 Please use it wisely! Remeber Bangkit 2022 Code of Conduct! Use it as reference only!
- 🤖 Tensorflow 2.9
- 🍾 Flask 2.10
- ⚡️ Cloud Run
- 🐍 Python 3
- 🐳 Docker
- 🚦 Any IDE you like
- Clone this repositroy
- Run
python install -r requirements.txt
- Open the
retention-prediction.ipynb
Please ignore the
expressjs
folder. It's my failure 🥲
- Clone this repositroy
- Open flask folder
- Run
python install -r requirements.txt
- Create
.env
file in root folder with this specifications
Variables | Function | Example |
---|---|---|
PORT | your_API_port | 8081 |
MODEL_LAYER | your_model_layer_path | model.json |
MODEL_WEIGHTS | your_model_weights_path | weights.h5 |
STANDARD_SCALER | your_standard_scaler_path (opt) | sc.pkl |
- Run
docker build -t retention-pred:v1.0 .
- Run
export PORT=your_API_port
change to match API port - Run
docker run --name retention-prediction -p 0.0.0.0:$PORT:$PORT -d retention-pred:v1.0
- Test with Postman or CLI
🚨 This still in development. Please jump to the second step
- Run
export PROJECT_ID=$(gcloud config get-value project)
- Run
export SA=retention-prediction
- Run this to create
retention-prediction
service account
gcloud iam service-accounts create $SA \
--description="retention-prediction SA" \
--display-name="retention-prediction"
- Run this to bind service account with
Storage Admin
role
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:$SA@$PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/storage.admin"
- Run this to get service account key as
key.json
gcloud iam service-accounts keys create key.json \
--iam-account=$SA@$PROJECT_ID.iam.gserviceaccount.com
- Add
s
into the.env
file
Variables | Function | Example |
---|---|---|
GOOGLE_APPLICATION_CREDENTIALS | your_service_account_path | ./key.json |
- 🚨 Keep it secret okay. Don't push your service account key into the github!
- Run
docker build -t gcr.io/$PROJECT_ID/retention-pred:v1.0 .
- Run
gcloud auth configure-docker
and pressY
- Run
docker push gcr.io/$PROJECT_ID/retention-pred:v1.0
- Run
gcloud run deploy --image gcr.io/$PROJECT_ID/retention-pred:v1.0 --platform managed
- Check your GCP Console > Cloud Run
- If you encounter error below, run
sudo apt install python3-tk
ModuleNotFoundError: No module named 'tkinter'
[2] https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-python-service