Deploying Models with Azure Web Application and Azure DevOps

Niranjainjain
4 min readNov 30, 2022

--

This image is copied from Google. It is a close representation of what are we going to achieve.

Making machine learning models is no big deal, the challenge is to deploy it or to put it out in production. So if you are looking out for a way to deploy your model as a web application using Azure DevOps, Azure Web Apps and FastAPI, then you are on the right page.

I recently worked on a Fraud Detection POC. I would be using the model I trained for that POC.

1. Get your Azure Repo Ready

So first things first, lets get the repo ready with the code.

The above directory has:
bestmodel.pkl: That is our random forest model
features.txt: That stores the features names
main.py: Our FastAPI Script
requirements.txt: To install all libraries and dependencies

Here is the git link for the same: https://github.com/niranjainjain022/fraud

I have commented the main.py in way any one can understand the script. So, let’s jump to the Azure Section

2. Create Azure Web APP

I won’t be elaborating more on the account creation part. If you are new to Azure then there are a plenty of tutorial in which they guide you how to make an account. If you are a student then, Azure gives $100 credit when you create your free account. There is no credit card needed and 12 months of free Azure services.

  1. Now, once you are done with the account creation, go to the Azure portal using this link: https://portal.azure.com/#home
Create resource by clicking on the highlighted button

2. Once you click on create a resource, go ahead and select the create button (highlighted in the blue box in image below) to create a web app.

3. To create a we need a subscription plan, so configure your subscription accordingly and choose it here. If you have an existing resource group then you can use it, else you can create a new resource group as shown:

4. Here is how you can configure the other details:

Use the Free F1 plan to avoid extra charges.

Once configured, directly click on review + create.

You should get something like this:

Click on the blue Go to resource button -> under settings find and select configuration -> on the right hand side head over to General Settings and give startup command as python main.py. Look at the figure below:

3. Linking Web Application with the CI/CD pipeline

Now head to Azure Repos in Azure Devops -> Go to Set up build and follow the steps shown below:

You will get the interface shown in the image. Make sure to change the python version as highlighted:

Save and run the pipeline. You will get a page showing build and deployment stage:

This process usually takes a while to run (approx. 20 mins to 30 mins). I don’t know how to slow it down, if you know then let me know in the comments. Meanwhile, you can check out my:

GitHub: github.com/niranjainjain022
LinkedIn: https://www.linkedin.com/in/niranjan-jain-548711172/

Once you are done, you will get something like this:

You are done with linking your Azure Web Application with Azure DevOps CI/CD Pipeline.

Head on to your azure web application page:
https://<your-webapp-name>.azurewebsites.net/

In my case I have named my application as fraudprediction so the link would be like:

https://fraudprediction.azurewebsites.net/

Here is the view:

After adding “/docs” extension to the URL:

Just click on drop down option on post method -> Click on Try it out -> Fill up the parameter values as shown below:

After clicking on execute we get something like:

That’s it! I know I might have skipped on some details, feel free to ping me on LinkedIn for any queries pertaining to this.

Note: I’ll be deleting the web application I created to avoid charges.

Thank you for reading.

--

--

No responses yet