Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arabic Diacritizer - AWS Lambda Deployment

A serverless Arabic text diacritization API powered by ONNX Runtime, deployed on AWS Lambda with a FastAPI interface

Project Structure

├── app/
│ ├── infer.py # ONNX model inference
│ ├── init.py # Python package marker
│ ├── main.py # FastAPI application & Lambda handler
│ └── model/
│ ├── arabic_diacritizer.onnx # ONNX model graph
│ └── arabic_diacritizer.onnx.data # Externalized model weights (39.7 MB)
├── Dockerfile # Container configuration for Lambda
├── event.json # Sample Lambda invocation event
├── requirements.txt # Python dependencies
└── README.md #

Local Development

Prerequisites

  • Python 3.12+
  • Docker
  • AWS CLI

Setup Virtual Environment

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Run FastAPI Server Locally

uvicorn app.main:app --reload

Health check

curl -X GET http://127.0.0.1:8000/

Diacritization request

curl -X POST http://127.0.0.1:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "بسم الله الرحمن الرحيم"}'

Example response

{
  "warning": null,
  "diacritized_text": "بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم"
}

Docker Testing (Lambda Simulation)

docker build --no-cache -t arabic-diacritizer-lambda .

Run Lambda Locally with Runtime Interface Emulator (RIE)

docker run -p 9000:8080 arabic-diacritizer-lambda:latest

Invoke the Lambda Function locally

curl -X POST "http://localhost:9000/2015-03-31/functions/function/invocations" \
  -d @event.json

AWS Deployment

Prerequisites

  • AWS account with appropriate permissions
  • AWS CLI configured (aws configure)

Create ECR Repository (one time only)

aws ecr create-repository \
  --repository-name arabic-diacritizer-lambda \
  --region $REGION

Build and Push Docker Image

export REGION="us-east-1"
export ACCOUNT_ID="your_account_id"

aws ecr get-login-password --region=$REGION | docker login \
  --username AWS \
  --password-stdin $ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com

docker build --no-cache -t arabic-diacritizer-lambda:latest .

docker tag arabic-diacritizer-lambda:latest \
  $ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/arabic-diacritizer-lambda:latest

docker push $ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/arabic-diacritizer-lambda:latest

Update Lambda Function

aws lambda update-function-code \
  --function-name arabic-diacritizer-lambda \
  --image-uri $ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/arabic-diacritizer-lambda:latest \
  --region $REGION

Test Deployment

curl -X POST https://your-lambda-url.lambda-url.us-east-1.on.aws/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "السلام عليكم"}'

Lambda Configuration

  • Runtime: Python 3.12 (Container Image)
  • Architecture: x86
  • Memory: 1024 MB
  • Timeout: 10 seconds
  • Handler: app.main.lambda_handler
  • Function URL: Enabled with CORS

About

A serverless Arabic text diacritization API powered by ONNX Runtime, deployed on AWS Lambda with a FastAPI interface

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages