A serverless Arabic text diacritization API powered by ONNX Runtime, deployed on AWS Lambda with a FastAPI interface
├── 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 #
- Python 3.12+
- Docker
- AWS CLI
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtuvicorn app.main:app --reloadcurl -X GET http://127.0.0.1:8000/curl -X POST http://127.0.0.1:8000/predict \
-H "Content-Type: application/json" \
-d '{"text": "بسم الله الرحمن الرحيم"}'Example response
{
"warning": null,
"diacritized_text": "بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم"
}
docker build --no-cache -t arabic-diacritizer-lambda .docker run -p 9000:8080 arabic-diacritizer-lambda:latestcurl -X POST "http://localhost:9000/2015-03-31/functions/function/invocations" \
-d @event.json- AWS account with appropriate permissions
- AWS CLI configured (aws configure)
aws ecr create-repository \
--repository-name arabic-diacritizer-lambda \
--region $REGIONexport 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:latestaws lambda update-function-code \
--function-name arabic-diacritizer-lambda \
--image-uri $ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/arabic-diacritizer-lambda:latest \
--region $REGIONcurl -X POST https://your-lambda-url.lambda-url.us-east-1.on.aws/predict \
-H "Content-Type: application/json" \
-d '{"text": "السلام عليكم"}'- Runtime: Python 3.12 (Container Image)
- Architecture: x86
- Memory: 1024 MB
- Timeout: 10 seconds
- Handler: app.main.lambda_handler
- Function URL: Enabled with CORS
