Spaces:
Sleeping
Sleeping
Clement Vachet
commited on
Commit
·
3c92d07
1
Parent(s):
d3f1938
docs: add menu and collapsed sections
Browse files
README.md
CHANGED
@@ -14,26 +14,34 @@ short_description: IRIS Classification Lambda
|
|
14 |
|
15 |
Workflow: use of AWS lambda function for deployment
|
16 |
|
17 |
-
## Local development
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
bash
|
22 |
> python train.py
|
23 |
|
24 |
-
###
|
|
|
|
|
25 |
|
26 |
bash
|
27 |
> docker build -t iris-classification-lambda .
|
28 |
|
29 |
-
|
30 |
|
31 |
bash
|
32 |
|
33 |
> docker run --name iris-classification-lambda-cont -p 8080:8080 iris-classification-lambda
|
34 |
|
35 |
|
36 |
-
###
|
37 |
|
38 |
Example of a prediction request
|
39 |
|
@@ -44,9 +52,24 @@ python
|
|
44 |
> python3 inference_api.py --url http://localhost:8080/2015-03-31/functions/function/invocations -d '{"features": [[6.5, 3.0, 5.8, 2.2], [6.1, 2.8, 4.7, 1.2]]}'
|
45 |
|
46 |
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
50 |
|
51 |
Steps:
|
52 |
- Create new ECR Repository via aws console
|
@@ -66,9 +89,13 @@ Example: ```iris-classification-lambda```
|
|
66 |
- Push docker image to ECR
|
67 |
> docker push <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/iris-classification-lambda:latest
|
68 |
|
69 |
-
|
70 |
|
71 |
-
|
|
|
|
|
|
|
|
|
72 |
|
73 |
<b>Steps</b>:
|
74 |
- Create function from container image
|
@@ -89,9 +116,11 @@ Advanced notes:
|
|
89 |
- Steps to update the Lambda function with latest container via aws cli:
|
90 |
> aws lambda update-function-code --function-name iris-classification --image-uri <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/iris-classification-lambda:latest
|
91 |
|
|
|
92 |
|
93 |
-
### Creating an API via API Gateway
|
94 |
|
|
|
95 |
|
96 |
<b>Steps</b>:
|
97 |
- Create a new ```Rest API``` (e.g. ```iris-classification-api```)
|
@@ -101,5 +130,18 @@ Advanced notes:
|
|
101 |
- Notes: using proxy integration option unchecked
|
102 |
- Deploy API with a specific stage (e.g. ```test``` stage)
|
103 |
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
Workflow: use of AWS lambda function for deployment
|
16 |
|
|
|
17 |
|
18 |
+
<b>Menu: </b>
|
19 |
+
- [Local development](#1-local-development)
|
20 |
+
- [AWS deployment](#2-deployment-to-aws)
|
21 |
+
|
22 |
+
|
23 |
+
## 1. Local development
|
24 |
+
|
25 |
+
### 1.1 Training the ML model
|
26 |
|
27 |
bash
|
28 |
> python train.py
|
29 |
|
30 |
+
### 1.2. Docker container
|
31 |
+
|
32 |
+
- Building the docker image
|
33 |
|
34 |
bash
|
35 |
> docker build -t iris-classification-lambda .
|
36 |
|
37 |
+
- Running the docker container
|
38 |
|
39 |
bash
|
40 |
|
41 |
> docker run --name iris-classification-lambda-cont -p 8080:8080 iris-classification-lambda
|
42 |
|
43 |
|
44 |
+
### 1.3. Execution via command line
|
45 |
|
46 |
Example of a prediction request
|
47 |
|
|
|
52 |
> python3 inference_api.py --url http://localhost:8080/2015-03-31/functions/function/invocations -d '{"features": [[6.5, 3.0, 5.8, 2.2], [6.1, 2.8, 4.7, 1.2]]}'
|
53 |
|
54 |
|
55 |
+
### 1.4. Execution via user interface
|
56 |
+
|
57 |
+
Use of Gradio library for web interface
|
58 |
+
|
59 |
+
<b>Note:</b> The environment variable ```AWS_API``` should point to the local container
|
60 |
+
> export AWS_API=http://localhost:8080
|
61 |
+
|
62 |
+
Command line for execution:
|
63 |
+
> python3 app.py
|
64 |
+
|
65 |
+
The Gradio web application should now be accessible at http://localhost:7860
|
66 |
+
|
67 |
+
|
68 |
+
## 2. Deployment to AWS
|
69 |
+
|
70 |
+
### 2.1. Pushing the docker container to AWS ECR
|
71 |
|
72 |
+
<details>
|
73 |
|
74 |
Steps:
|
75 |
- Create new ECR Repository via aws console
|
|
|
89 |
- Push docker image to ECR
|
90 |
> docker push <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/iris-classification-lambda:latest
|
91 |
|
92 |
+
</details>
|
93 |
|
94 |
+
[Link to AWS ECR Documention](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html)
|
95 |
+
|
96 |
+
### 2.2. Creating and testing a Lambda function
|
97 |
+
|
98 |
+
<details>
|
99 |
|
100 |
<b>Steps</b>:
|
101 |
- Create function from container image
|
|
|
116 |
- Steps to update the Lambda function with latest container via aws cli:
|
117 |
> aws lambda update-function-code --function-name iris-classification --image-uri <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/iris-classification-lambda:latest
|
118 |
|
119 |
+
</details>
|
120 |
|
121 |
+
### 2.3. Creating an API via API Gateway
|
122 |
|
123 |
+
<details>
|
124 |
|
125 |
<b>Steps</b>:
|
126 |
- Create a new ```Rest API``` (e.g. ```iris-classification-api```)
|
|
|
130 |
- Notes: using proxy integration option unchecked
|
131 |
- Deploy API with a specific stage (e.g. ```test``` stage)
|
132 |
|
133 |
+
</details>
|
134 |
+
|
135 |
+
Example AWS API Endpoint:
|
136 |
+
```https://<api_id>.execute-api.<aws_region>.amazonaws.com/test/classify```
|
137 |
+
|
138 |
+
|
139 |
+
### 2.4. Execution for deployed model
|
140 |
+
|
141 |
+
Example of a prediction request
|
142 |
+
|
143 |
+
bash
|
144 |
+
> curl -X POST "https://<api_id>.execute-api.<aws_region>.amazonaws.com/test/classify" -H "Content-Type: application/json" -d '{"features": [[6.5, 3.0, 5.8, 2.2], [6.1, 2.8, 4.7, 1.2]]}'
|
145 |
+
|
146 |
+
python
|
147 |
+
> python3 inference_api.py --url https://<api_id>.execute-api.<aws_region>.amazonaws.com/test/classify -d '{"features": [[6.5, 3.0, 5.8, 2.2], [6.1, 2.8, 4.7, 1.2]]}'
|