Skip to content

Commit 45cb968

Browse files
committed
module 19 demo remove verify jon
1 parent 8040298 commit 45cb968

4 files changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Deploy and Verify
2+
3+
on:
4+
push:
5+
branches: [content]
6+
7+
env:
8+
ECR_REPOSITORY: ner-api
9+
TASK_DEFINITION: ner-api
10+
CONTAINER_NAME: ner-api
11+
ECS_SERVICE: ner-api-service
12+
ECS_CLUSTER: ner-api-cluster
13+
14+
jobs:
15+
deploy:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Configure AWS credentials
19+
uses: aws-actions/configure-aws-credentials@v4
20+
with:
21+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
22+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23+
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
24+
aws-region: ${{ secrets.AWS_REGION }}
25+
26+
- name: Download current task definition
27+
run: |
28+
aws ecs describe-task-definition \
29+
--task-definition ${{ env.TASK_DEFINITION }} \
30+
--query taskDefinition > task-definition.json
31+
32+
- name: Render ECS task definition with latest image
33+
id: task-def
34+
uses: aws-actions/amazon-ecs-render-task-definition@v1
35+
with:
36+
task-definition: task-definition.json
37+
container-name: ${{ env.CONTAINER_NAME }}
38+
image: ${{ secrets.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest
39+
40+
- name: Deploy to ECS
41+
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
42+
with:
43+
task-definition: ${{ steps.task-def.outputs.task-definition }}
44+
service: ${{ env.ECS_SERVICE }}
45+
cluster: ${{ env.ECS_CLUSTER }}
46+
wait-for-service-stability: true
47+
48+

module-19-ci-cd/demo/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt .
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY main.py .
9+
10+
EXPOSE 8000
11+
12+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

module-19-ci-cd/demo/main.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from fastapi import FastAPI, HTTPException
2+
from pydantic import BaseModel
3+
from transformers import pipeline
4+
5+
app = FastAPI()
6+
7+
# Load the model
8+
MODEL_NAME = "elastic/distilbert-base-cased-finetuned-conll03-english"
9+
classifier = pipeline("ner", model=MODEL_NAME, aggregation_strategy="simple")
10+
11+
12+
class TextRequest(BaseModel):
13+
text: str
14+
15+
16+
@app.post("/predict")
17+
async def predict(request: TextRequest):
18+
if not request.text.strip():
19+
raise HTTPException(status_code=400, detail="Text cannot be empty")
20+
21+
# Run NER inference
22+
entities = classifier(request.text)
23+
24+
# Transformers returns objects that aren't always JSON-serializable
25+
# (like numpy floats), so we clean them up
26+
results = []
27+
for entity in entities:
28+
results.append(
29+
{
30+
"entity_group": entity["entity_group"],
31+
"score": float(entity["score"]),
32+
"word": entity["word"],
33+
"start": entity["start"],
34+
"end": entity["end"],
35+
}
36+
)
37+
38+
return {"entities": results}
39+
40+
41+
if __name__ == "__main__":
42+
import uvicorn
43+
44+
uvicorn.run(app, host="0.0.0.0", port=8000)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fastapi==0.110.0
2+
uvicorn==0.27.1
3+
transformers>=4.44.0
4+
torch>=2.4.0
5+
pillow==10.2.0
6+
python-multipart==0.0.9

0 commit comments

Comments
 (0)