Spaces:
Runtime error
Runtime error
VenkateshRoshan
commited on
Commit
·
2c38e04
1
Parent(s):
67d5dc2
flask ping code updated
Browse files- .github/workflows/deploy.yml +12 -12
- app.py +16 -0
- src/deploy_sagemaker.py +5 -1
.github/workflows/deploy.yml
CHANGED
|
@@ -36,18 +36,18 @@ jobs:
|
|
| 36 |
id: login-ecr
|
| 37 |
uses: aws-actions/amazon-ecr-login@v1
|
| 38 |
|
| 39 |
-
- name: Build and push Docker image
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
- name: Deploy model to SageMaker
|
| 53 |
run: |
|
|
|
|
| 36 |
id: login-ecr
|
| 37 |
uses: aws-actions/amazon-ecr-login@v1
|
| 38 |
|
| 39 |
+
# - name: Build and push Docker image
|
| 40 |
+
# env:
|
| 41 |
+
# ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
|
| 42 |
+
# ECR_REPOSITORY: customer-support-chatbot
|
| 43 |
+
# IMAGE_TAG: latest
|
| 44 |
+
# run: |
|
| 45 |
+
# docker build \
|
| 46 |
+
# --build-arg AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} \
|
| 47 |
+
# --build-arg AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} \
|
| 48 |
+
# --build-arg AWS_DEFAULT_REGION=${{ secrets.AWS_REGION }} \
|
| 49 |
+
# -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
|
| 50 |
+
# docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
| 51 |
|
| 52 |
- name: Deploy model to SageMaker
|
| 53 |
run: |
|
app.py
CHANGED
|
@@ -169,6 +169,22 @@ def create_chat_interface():
|
|
| 169 |
|
| 170 |
return interface
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
if __name__ == "__main__":
|
| 173 |
demo = create_chat_interface()
|
| 174 |
print("Starting Gradient server...")
|
|
|
|
| 169 |
|
| 170 |
return interface
|
| 171 |
|
| 172 |
+
from flask import Flask, jsonify
|
| 173 |
+
import threading
|
| 174 |
+
|
| 175 |
+
app = Flask(__name__)
|
| 176 |
+
|
| 177 |
+
# Health check endpoint for SageMaker
|
| 178 |
+
@app.route("/ping", methods=["GET"])
|
| 179 |
+
def ping():
|
| 180 |
+
return jsonify({"status": "ok"}), 200
|
| 181 |
+
|
| 182 |
+
# Start Flask app on a separate thread
|
| 183 |
+
def run_flask():
|
| 184 |
+
app.run(host="0.0.0.0", port=8081) # Different port for Flask
|
| 185 |
+
|
| 186 |
+
threading.Thread(target=run_flask).start()
|
| 187 |
+
|
| 188 |
if __name__ == "__main__":
|
| 189 |
demo = create_chat_interface()
|
| 190 |
print("Starting Gradient server...")
|
src/deploy_sagemaker.py
CHANGED
|
@@ -95,7 +95,11 @@ def deploy_app(acc_id, region_name, role_arn, ecr_repo_name, endpoint_name="cust
|
|
| 95 |
logger.info(f"Deploying model to endpoint: {endpoint_name}")
|
| 96 |
logger.info(f"Deployment configuration: {deployment_config}")
|
| 97 |
|
| 98 |
-
predictor = model.deploy(**deployment_config
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
logger.info(f"Successfully deployed to endpoint: {endpoint_name}")
|
| 101 |
return predictor
|
|
|
|
| 95 |
logger.info(f"Deploying model to endpoint: {endpoint_name}")
|
| 96 |
logger.info(f"Deployment configuration: {deployment_config}")
|
| 97 |
|
| 98 |
+
predictor = model.deploy(**deployment_config,health_check_timeout_seconds=180, # Optionally, increase the timeout
|
| 99 |
+
environment={
|
| 100 |
+
"SAGEMAKER_CONTAINER_PORT": "8080",
|
| 101 |
+
"FLASK_HEALTHCHECK_PORT": "8081",
|
| 102 |
+
})
|
| 103 |
|
| 104 |
logger.info(f"Successfully deployed to endpoint: {endpoint_name}")
|
| 105 |
return predictor
|