<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Deepan Adak on Medium]]></title>
        <description><![CDATA[Stories by Deepan Adak on Medium]]></description>
        <link>https://medium.com/@deepuadak?source=rss-6316be7e9891------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8yzC1ttTKCP408jpAE-ICQ.jpeg</url>
            <title>Stories by Deepan Adak on Medium</title>
            <link>https://medium.com/@deepuadak?source=rss-6316be7e9891------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 19:55:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deepuadak/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Unlocking ML Potential: Deploying Flask Rest API for Machine Learning Models on Microsoft Azure]]></title>
            <link>https://medium.com/@deepuadak/unlocking-ml-potential-deploying-flask-rest-api-for-machine-learning-models-on-microsoft-azure-bc5235a81261?source=rss-6316be7e9891------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc5235a81261</guid>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Deepan Adak]]></dc:creator>
            <pubDate>Sat, 24 Jun 2023 12:34:26 GMT</pubDate>
            <atom:updated>2023-06-24T12:34:26.960Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are a data scientist or machine learning engineer, chances are that you have built a number of machine learning models in your career. These models can provide valuable insights and predictions, but what good are they if they remain confined to your local environment?</p><p>Deploying your machine learning model to a web service can help you to share your work with the world, and make it accessible to a wider audience. One popular way to do this is by creating a Flask REST API service, which can be used to expose your machine learning model to the public.</p><p>Flask is a popular Python web framework that allows you to easily create web applications and APIs.</p><p>Deploying your machine learning model to a web service using Flask can be a powerful way to share your work with the world. So once you have created a flask application, what next?</p><p>You need to deploy your flask app to some cloud service and one of the best place would be Microsoft Azure.</p><p>Microsoft Azure provides a range of services that can help you to deploy, manage and build scalable web apps.</p><p>Read on to learn about deploying your machine learning model using Flask to Microsoft Azure.</p><h3><strong>Create a machine Learning Model</strong></h3><p>Train your machine learning model of your choice and save the weights of your model in .h5 format. You can use the jupyter notebook in my git repository for your reference (<a href="https://github.com/mr-prometheus/DeepLearningRestAPIService/blob/main/Fruits.ipynb"><em>Link here</em></a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*Z6PlHrqZ6aP7MIW23Om10w.png" /><figcaption>Save Your ML Model</figcaption></figure><h3><strong>Create a Flask Rest API Service</strong></h3><p>Let’s begin by using Flask to create a Rest API service, which will serve as our starting point.</p><p>By leveraging Flask’s simplicity and flexibility, we can rapidly develop Rest APIs that cater to various development needs</p><p>Getting started with flask app<br>Below is a basic snippet how to start with a flask app</p><pre>From flask importFlask<br>app=Flask(__name__)<br>@app.route(&quot;/&quot;)<br>def index():<br>return&quot;&lt;h1&gt;Hello Azure!&lt;/h1&gt;&quot;</pre><p>You can clone the repository (<a href="https://github.com/mr-prometheus/DeepLearningRestAPIService"><em>refer to to github repo</em></a>) to access a sample template for a Flask app that includes a machine learning model prediction script. The implementation mentioned here is based on that repository. <br>You can customize the script according to your specific requirements and incorporate your own machine learning model implementation.</p><p>After completing the creation of a basic Flask app, it is necessary to define a route that serves as an API endpoint to invoke our service. Below is a snippet of the API endpoint which will serve our purpose (this snippet is same from the git repository).</p><pre>@app.route(&#39;/predict&#39;, methods=[&#39;GET&#39;, &#39;POST&#39;])<br>@cross_origin(allow_headers=[&#39;Content-Type&#39;])<br>def upload():<br>    if request.method == &#39;POST&#39;:<br><br>        &quot;&quot;&quot;testing purpose&quot;&quot;&quot;<br>        filestr = request.files[&#39;file&#39;].read()<br>        file_bytes = np.frombuffer(filestr, np.uint8)<br>        img = cv2.imdecode(file_bytes, cv2.IMREAD_UNCHANGED)<br>        img = cv2.resize(img,(224,224))<br>        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)<br>        x = img_to_array(img)<br>        x = preprocess_input(x)<br><br>   <br>        prediction = model.predict(x.reshape(1,224,224,3))<br>        output = np.argmax(prediction)<br>        predicted_class = CLASS_NAMES[output]<br>        max_prob = np.max(prediction)<br>        if max_prob &gt;0.75:<br>            return {<br>            &#39;class&#39; : predicted_class,<br>            &#39;confidence&#39; : float(max_prob)<br>        }<br>        else:<br>            return NONE<br>    return None</pre><p>After loading our saved model, we process incoming user requests to generate predictions, which are then sent back as responses. This enables us to provide real-time predictions to users based on their input data.</p><p>Let’s Run the Flask App and test it out by making a POST call using a picture through postman.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*ft0sIMAxDR-S9b6hkyhCgQ.png" /><figcaption>Flask App Run</figcaption></figure><p>Our Flask App is up and running.<br>Lets test our API endpoint in Postman.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kqaaswQvPY858AhVuoKTNg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/157/1*LKpRsXPZLQw2h-p-Rd_1Ig.png" /><figcaption>Input Image</figcaption></figure><p>Send a post request and see whether it’s returning the json response or not</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*u48PKP9J2sWadwt6BPkXIA.png" /><figcaption>API Response</figcaption></figure><p>The Flask app is functioning smoothly and is providing a satisfactory response.</p><h3>Deploying Machine Learning Model using Flask API to Microsoft Azure</h3><p><em>This is where the fun begins :)</em></p><p>We will be using Microsoft Azure’s web app service to deploy our Flask REST API, taking advantage of its capabilities for seamless hosting and scalability.</p><p>Let me walk you through the steps</p><p>1. Log in to the <a href="https://portal.azure.com/">https://portal.azure.com/</a></p><p>2. Create a resource</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*fA30vZJUf-K615PtYlC6GQ.png" /></figure><p>3. Create a new web app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*-5FS_CgNPuXIUQ8mNP25qw.png" /></figure><p>4. Fill in the following details as per your requirement Create a new resource group if you don’t have a Resource Group. (You can look more into what is a Resource Group. <a href="https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/manage-resource-groups-portal">Link</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*q8_YVvcNf9Du-LVlpYdX3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*qUhdhI0-y0Kh_hyRukhB4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*ea5z48_-2rmquAyaKqGY_g.png" /></figure><p>5. Click on Review + Create</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*M4FBUAmnLvPHlJqM3WY2Cw.png" /></figure><p>6. Wait while your deployment gets ready</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*TqNMZ1zjZRMy_NY_x3sfSw.png" /></figure><p>7. Navigate to ‘Go to Resource’</p><p>8. In the left pane of your Resource, you would see a section for Deployment. Click on Deployment Center</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*b-r2W2tN-2EbOiiPR39lMQ.png" /></figure><p>9. You can now link your deployment to your github account or any other cloud based service shown in the drop down</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4_MM5IcQJmnT7vsK_HzHOw.png" /></figure><p>10. Fill up your account details and hit save</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*vjeAJm8i3FGyXFR_2Ni_WA.png" /></figure><p>11. In the overview you will be able to see your default Domain</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*2DgqGhR0mq1m_PfrkKJrCQ.png" /></figure><p>12. You can also see your workflow process in the actions of your Github repository which you linked to your deployment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kATql2AEUsO7uw_WBE_uQg.png" /></figure><p>13. Remember what route we set for our prediction. It was /predict. So go over to your postman and use this default domain to test out our Rest API endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ypsizlJH8FtnQTI6qSy0Xg.png" /></figure><p>Voila. Our API endpoint is up and running.</p><p>14. Utilize this API endpoint in your web app or any other suitable context to showcase its capabilities to the world and make the predictions accessible to a broader audience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*iqCM0ECFtSjf_sNMPEQZ-A.png" /><figcaption>Prediction response in webapp</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*3m_ItkxXDyr9Lu1PcmOc7w.png" /></figure><p>Thank you for exploring my article documenting the deployment of machine learning models using Flask API on Microsoft Azure. I hope it equips you to showcase your models to the world and leverage the power of Azure’s infrastructure. Happy Learning!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc5235a81261" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>