<?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 Aakar Mutha on Medium]]></title>
        <description><![CDATA[Stories by Aakar Mutha on Medium]]></description>
        <link>https://medium.com/@aakar-mutha18?source=rss-745ad71599b4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xsopEY3L0p6scFuI</url>
            <title>Stories by Aakar Mutha on Medium</title>
            <link>https://medium.com/@aakar-mutha18?source=rss-745ad71599b4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 21:38:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aakar-mutha18/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[Building a Heroku application to Compress Images]]></title>
            <link>https://aakar-mutha18.medium.com/building-a-heroku-application-to-compress-images-9294310db44?source=rss-745ad71599b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/9294310db44</guid>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Aakar Mutha]]></dc:creator>
            <pubDate>Sun, 09 May 2021 10:53:13 GMT</pubDate>
            <atom:updated>2021-05-09T11:04:25.701Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F4KXPIl8Fm0mPGY587yeSQ.png" /></figure><p>Hey! So a couple of days ago I wanted to make something to compress images and that I can use it in real world without much of a hassle. As I was searching the web to find some solution I stumbled upon an AWS lambda repository that seem to do the job but I couldn’t easily deploy it since I am a noobie to SAM templates and repositories. So I thought I’ll make one of my own using AWS lambda. But then I realised the limitations that there was no easy way to install packages to lambda directly from the console. You have to make a containerised copy of the code and then deploy it to lambda. I thought it was too much of a hassle to make one. So I set to build my own using flask and deploy it to Heroku. In this story I’ll show how you can make your own using python flask and Pillow along with how to use firebase as storage and deploy it to heroku. We update the realtime database with the public URL of the images so that you can directly use it in a android/web/ios application without much of an hassle. I will also be adding the original and compressed file size to the realtime database. Let’s get started!!</p><p>You can refer to the entire source code here :</p><p><a href="https://github.com/aakar-mutha/heroku-compress">aakar-mutha/heroku-compress</a></p><h3>Part 1 : Firebase Setup</h3><p>Lets first set up the firebase project which we will be using for storage as well as</p><p><a href="https://firebase.google.com/">Firebase | Google&#39;s Mobile and Web App Development Platform</a></p><p>Head over to the console and click create project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*exiVZBTWJVj5Mdo-49IURA.png" /></figure><p>After the project is created. Go to realtime database and create a realtime database and start it in test mode and enable it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*xLlpVTforiViuuQt2HH8tg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*M4xeGFqtNFdliGST7Cl-3g.png" /></figure><p>Next go to storage and create a storage that acts as the storage to your files since we cannot store new files in Heroku.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*E4fwpQ7RyKwm92kZgu0k2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*Y4_mBnBcRbSXJmR6xjhUAg.png" /></figure><p>Since the storage is multi regional it will ensure availability from anywhere in the world.</p><p>In order to access the database and the realtime database with python, we need a key.json file. We can download it from the<a href="https://console.cloud.google.com/iam-admin/serviceaccounts"> IAM &amp; Admin Console of Google Cloud.</a> Click the hyperlink to open. Once you are on the console click select project in the top right. Go to all and Select the project you just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*D9E7v2r-BCMNopkWiygMpg.png" /></figure><p>image-compression-heroku in my case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*LO-18j6nRriAbHewIwvX0Q.png" /></figure><p>Once you are on this page, hit the 3 dots next to firebase-adminsdk and open the manage keys menu. From here, create a new key of JSON format and download it as key.json</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*KMetULCLmD4E93QC6GLErg.png" /></figure><p>Now that we are all set lets get to part 2.</p><h3>Part 2 : Coding and testing the app locally.</h3><p>By now, you have the key.json file in a folder. To setup the project you will be required to install pillow, flask, gunicorn and firebase_admin packages. Run these commands in the terminal.</p><pre>pip install flask</pre><pre>pip install firebase_admin</pre><pre>pip install pillow</pre><pre>pip install gunicorn</pre><p>After you are done with all these installations lets create a virtual environment and get to coding.</p><p>To install virtual environment use the following command.</p><pre>pip install virtualenv</pre><p>Now go to the folder where you will have the code in. Create a virtual environment name venv in it and activate it.</p><pre>virtualenv venv/<br>source venv/bin/activate</pre><p>Once the virtual environment starts open your favourite IDE and lets start coding.</p><pre>.<br>├── images<br>│   ├── compressed<br>│   └── original<br>├── key.json<br>├── static<br>│   ├── css<br>│   └── js<br>├── templates<br>└── venv</pre><p>We have to Create a directory structure like the one above. To do so create the folder images. Inside images create 2 folders named compressed and original. We will be storing the compressed and the original images in these folders temporarily. Create a folder named static inside which there are 2 more folders which will host our CSS and JS files. Lastly the templates folder. This will have out landing page HTML code.</p><p>Create a file called index.html in templates</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efc24ef4ed301931cefd8ac80de1ff87/href">https://medium.com/media/efc24ef4ed301931cefd8ac80de1ff87/href</a></iframe><p>Create a file called style.css in static/css folder and copy the contents to that file. I copied the styling from codepen and made a few changes. As you can guess I’m not so great at beautifying web pages.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fb8fa5a29ac3a7ef4faa8493035248e/href">https://medium.com/media/1fb8fa5a29ac3a7ef4faa8493035248e/href</a></iframe><p>Now lets create the the main app.py file in the root directory. This is the main file of the project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/289fdeb6a61eeb6776a9bbbdf60dda44/href">https://medium.com/media/289fdeb6a61eeb6776a9bbbdf60dda44/href</a></iframe><h3><strong>Explanation of the code. Skip if you find it boring</strong></h3><p>First step is to import all the libraries that we will be using. Next we will creating a reference of the database by calling the db.referance function and initialise the storage bucket. We next initialise the flask app and give the root url path. As we have given /success in the form we will create an app route /success. The methods that /success deals with is POST. The path stores the path to the original folder where we will save the image temporarily. It is then uploaded to the storage bucket. the file is then compressed according to the value given or taking the default value and uploaded to the storage bucket. Finally the links of the 2 images are set in the realtime database and the page is redirected to the compressed file URL.</p><p><strong>Now our directory structure will look something like this</strong></p><pre>.<br>├── app.py<br>├── images<br>│   ├── compressed<br>│   └── original<br>├── key.json<br>├── static<br>│   ├── css<br>│   │   └── style.css<br>│   └── js<br>│       └── function.js<br>├── templates<br>│   └── index.html<br>└── venv</pre><p>Lets now set the rules of the realtime database as well as the storage. We will be keeping it in the test environment that is we do not require authentication to access the files but in an ideal scenario it should be in production mode.</p><p>To edit the rules of storage first go to storage tab and then rules tab. Once you are on this screen paste the rules below to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*Erxi2VCB8jZhXrDRGkCQMA.png" /></figure><pre>rules_version = &#39;2&#39;;<br>service firebase.storage {<br>  match /b/{bucket}/o {<br>    match /{allPaths=**} {<br>      allow read, write: if true;<br>    }<br>  }<br>}</pre><p><strong>While you are here copy the name of the storage and paste it in app.py line 7 after removing gs://.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*NTtSCtU4VY15jRt0x9Tmxw.png" /></figure><p>To edit the rules of realtime database first open the realtime database tab and select rules tab. Change the rules as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ve65oxalhgI9Tl2MnSvIFg.png" /></figure><pre>{<br>  &quot;rules&quot;: {<br>    &quot;.read&quot;: true,<br>    &quot;.write&quot;: true<br>  }<br>}</pre><p><strong>While you are here go to the Data tab and copy the database URL and paste it in the app.py line 8.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*NJ1IyEydkX5_Kcprt1a9Iw.png" /></figure><p><strong>Since we are in the virtual environment, we need to install all the python packages we installed earlier again. Run the pip commands from the start of part 2 again.</strong></p><p>Now run the app.py file as you would any python file and open the link that is printed in the console. It should display this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RjjePCfnBrJYx3jiUhvMPw.png" /></figure><p>Try testing it and seeing the results. It should redirect you to the compressed image URL if you try it.</p><h3>Part 3 : Deployment to heroku</h3><p>Now lets freeze the requirements.txt file. To freeze it run the following command. Make sure you have the virtual environment activated.</p><pre>pip3 freeze &gt; requirements.txt</pre><p>After running that command you should see a requirements.txt file in the directory. Lets now create a Procfile. A Procfile is a mechanism for declaring what commands are run by your application’s containers. To make the file run the command below in the terminal with the current directory open.</p><pre>touch Procfile</pre><p>Now open the Procfile and copy the following line to it. This will tell heroku that you have to app from the app.py file.</p><pre>web: gunicorn app:app</pre><p>Now lets commit the changes to a github repository and get to deployment.</p><p><strong>NOTE : YOU SHOULD HAVE AT LEAST ONE IMAGE IN COMPRESSED AND ORIGINAL FOLDERS.</strong></p><p>To deploy to heroku first go to the heroku console and create a new app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*_QUX2TGgGvWgxPwXN4Y_pQ.png" /></figure><p>After creating and application choose to deploy from github and search for your repo and press connect next to it’s name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YYfvggyxhUWuvGpWkEBpDA.png" /></figure><p>Enable automatic deploys(optional) and select your branch. Wait for it to get deployed and open the app from the button at the top of the page and voila you are done!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUZ2jbvKHckzFDSV67JQgQ.png" /></figure><p>Your app should look this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*udZ9BV8yZKYXdj4Z86GCcw.png" /></figure><p>Lets check out the firebase storage as well as realtime database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aDv61EcVWHwIq-bPu-eHDA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nIuMMfZdvF96rPjA5s18UQ.png" /></figure><p>The image outside is the original image and the image inside the folder is the compressed image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*oUTEs9_ChtKlt7PxWUq_TQ.png" /></figure><p>Realtime database with the links and the file sizes.</p><h3>References</h3><ul><li><a href="https://medium.com/@preveenraj/image-upload-to-firebase-storage-with-python-ebf18c615f34">Image Upload to Firebase Storage with Python</a></li><li><a href="https://medium.com/@gitaumoses4/deploying-a-flask-application-on-heroku-e509e5c76524">Deploying a Flask application on Heroku</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9294310db44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to Machine Learning]]></title>
            <link>https://medium.com/iothincvit/an-introduction-to-machine-learning-bd68541e853f?source=rss-745ad71599b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd68541e853f</guid>
            <category><![CDATA[technical-writing]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Aakar Mutha]]></dc:creator>
            <pubDate>Fri, 17 Apr 2020 12:52:56 GMT</pubDate>
            <atom:updated>2020-04-19T14:33:17.928Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e2EZ8fWihw6W8kAp.jpeg" /></figure><p>Assume you have been given a simple task of recognizing different shapes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*4OsVw6XhEP3c-jMIU17icQ.png" /></figure><p>You can easily be able to tell that one these shapes is a square, one of them, a circle and one, a triangle. Did you ever think about how you knew which shape was what? Since childhood, you have been taught to call a particular shape a particular name, and just like this, your computer can be taught in a similar way, by training it to do a particular task. This training of the computer is called Machine Learning.</p><h3><strong>Starting with the A B C’s of Machine Learning</strong></h3><p>In order to teach a computer how to solve a task, different algorithms are used.</p><p>There are 2 methods of making a machine learn:</p><h4><strong>Supervised Learning</strong></h4><p>In supervised learning, we give the input and result in pairs. Using different algorithms, the machine can then correlate the input and output. We use a labeled dataset for training the algorithm.</p><h4><strong>Unsupervised Learning</strong></h4><p>In unsupervised learning, there is no feature that is labeled explicitly. It creates clusters, and on the basis of that, the different properties are extracted.</p><p>In this article, the basics of supervised learning that is Regression, will be covered.</p><p>Regression is the most basic algorithm that is used in Machine Learning, when you want to fit a best fit function in the data. The equation of regression is :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FkY58TK0S_Kg4EaD" /></figure><p>If there is only one independent variable, we use Linear Regression, otherwise, if we have multiple variables, we use Logistic regression.</p><p>We will be using scikit learn to access the different Machine Learning models. The entire code will be written in Python. Use jupyter notebook or Google Colab for coding.</p><h3>Let’s take an example of Linear Regression</h3><p>Predicting the brain size if the weight of the brain is given.</p><p><strong>Dataset :</strong></p><p><a href="https://www.kaggle.com/jemishdonda/headbrain/version/1#headbrain.csv">https://www.kaggle.com/jemishdonda/headbrain/version/1#headbrain.csv</a></p><p><strong>Code:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03533488e5f6853cba052e6f5419fcc8/href">https://medium.com/media/03533488e5f6853cba052e6f5419fcc8/href</a></iframe><p>NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.</p><p>In computer programming, pandas is a software library written for the Python programming language for data manipulation and analysis.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0827aeb536572e6b5b3312a338921448/href">https://medium.com/media/0827aeb536572e6b5b3312a338921448/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/0*B7W89A1SSwZANlig" /></figure><p>pd. read_csv( )function reads the csv file and assigns the data of the file to the variable ‘data’</p><p>data.head() prints the first 5 lines in the dataset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9245713303363a624059def87eaa3206/href">https://medium.com/media/9245713303363a624059def87eaa3206/href</a></iframe><p>data.info() this function gives us the information about the dataset like the column headings, number of non-null objects in each column and the data type of objects in each column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/0*F6bslkxvvOiZvi8O" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/121344d2c1e7b1eb7f637b2e05e81fe9/href">https://medium.com/media/121344d2c1e7b1eb7f637b2e05e81fe9/href</a></iframe><p>This is for assigning the data in the columns to the variables. We cannot give a 2-D array having one row and n columns. We need the input as n rows and one column. So, we are using the reshape function to find the transpose of that matrix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cba790bfa8893ecf03c99d9df489c60/href">https://medium.com/media/2cba790bfa8893ecf03c99d9df489c60/href</a></iframe><p>Here, we are importing the function of linear regression and train_test_split from the Scikit learn library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11ab4e695ed606513324a1cab19b6aa6/href">https://medium.com/media/11ab4e695ed606513324a1cab19b6aa6/href</a></iframe><p>We are splitting the data into training dataset and testing dataset. The testing dataset size is 33% of the entire data. We get 4 arrays after using this function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fb51908b6bcd5e3bc9478955ee00dc0/href">https://medium.com/media/8fb51908b6bcd5e3bc9478955ee00dc0/href</a></iframe><p>Importing the Linear regression model as a model. The fit function assigns a best fit line through all the data points.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95c364c96a45d8ba0efb655a14fc1fd6/href">https://medium.com/media/95c364c96a45d8ba0efb655a14fc1fd6/href</a></iframe><p>As we had split the data points above, we use the X_test array to make prediction based on the model that we just built using the fit function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58c33b33d4e430cae57885700ae87542/href">https://medium.com/media/58c33b33d4e430cae57885700ae87542/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/0*Yi-0yYAS9FTjAo0R" /></figure><p>This function tells us how accurately our model can predict the size of the brain. As you can see, the model is capable of predictions with 100% accuracy.</p><p>Hope this article has helped you get a good understanding of what Machine Learning is and how to start with it.</p><p>The link to the Google Colab notebook:</p><p>https://colab.research.google.com/drive/1d1l9ZM26XAOHSfPowdJnkSIAfQ7DsSMt</p><p>Happy Learning!</p><p><strong>Author: Aakar Mutha</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd68541e853f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/iothincvit/an-introduction-to-machine-learning-bd68541e853f">An Introduction to Machine Learning</a> was originally published in <a href="https://medium.com/iothincvit">The Internet of Things Community — VIT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>