This project demonstrates an end-to-end MLOps pipeline using GitHub Actions for CI/CD to build and deploy a FastAPI application that leverages Hugging Face’s GPT-2 model for sentence completion. The deployment target is Azure Container Apps, with Docker images managed via Azure Container Registry (ACR).
- Tech Stack: Python, FastAPI, Hugging Face Transformers (GPT-2), Docker, Azure Container Registry, Azure Container Apps, GitHub Actions (CI/CD)
- Use case: Sentence completion using GPT-2 via a production-ready, scalable REST API
- Automated CI/CD pipeline with GitHub Actions
- Dockerized FastAPI service for serving Hugging Face GPT-2
- Seamless deployment to Azure Container Apps from ACR
- Secure Azure authentication using repository secrets
- MLOps best practices for model deployment
- Azure subscription with permissions to create resources
- Docker (for local builds/tests)
- Python 3.8+
- Azure CLI
git clone https://github.com/Muhammadyousafrana/huggingface-azure-acr.git
cd huggingface-azure-acrTo deploy via GitHub Actions, create AZURE_CREDENTIALS:
-
Open Azure Cloud Shell and run:
az login
-
Create a service principal:
az ad sp create-for-rbac \ --name gha-deploy \ --role contributor \ --scopes /subscriptions/<subscription ID> \ --sdk-auth
- Replace
<subscription ID>with your Azure Subscription ID. - Copy the JSON output.
- Replace
-
In your GitHub repo, go to Settings > Secrets and variables > Actions, add a new secret named
AZURE_CREDENTIALS, and paste the JSON output.
- On each push to
main, GitHub Actions will:- Build the Docker image with FastAPI and GPT-2
- Push to Azure Container Registry
- Deploy to Azure Container Apps
You can monitor the deployment status via the GitHub Actions tab.
After deployment, view logs using Azure CLI:
az containerapp logs show \
--name <container-app-name> \
--resource-group <resource-group-name>The deployed FastAPI service exposes a REST API for sentence completion using GPT-2.
Example request:
curl -X POST "https://<your-app-url>/complete" -H "Content-Type: application/json" -d '{"prompt": "Once upon a time"}'Response:
{
"completion": "Once upon a time, there was a..."
}Contributions are welcome! Please open issues or submit pull requests for improvements.
For questions, open an issue or contact the repo owner.