AI_DL_Assignment / 29. BONUS - Create a Computer Vision API & Web App Using Flask and AWS /9. Running your CV API on EC2.html
| <h4><strong>Running your CV API on EC2</strong></h4><p><br>Postman is an extremely useful app used to test APIs. We'll be using it to demonstrate our CV API </p><p><br></p><p><strong>Step 1: Install Postman</strong></p><p>Windows/Mac Users - <a href="https://www.getpostman.com/downloads/" rel="noopener noreferrer" target="_blank">https://www.getpostman.com/downloads/</a></p><p>Ubuntu - Open Ubuntu Software, search for Postman and install </p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_06-06-41-8ce224de735c72f9cee7fd145abcbab4.JPG"></figure><p><br></p><p><strong>Step 2: </strong>Setting up Postman for testing your EC2 API</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_06-12-53-d966f3cbf2ec41dac34a0b3e943572bc.jpg"></figure><p><strong>Using Postman (see image above and the corresponding numbered steps below:</strong></p><ol><li><p>Change the protocol to POST</p></li><li><p>Enter the Public IP Address of your EC2 Instance: <strong>http://18.224.96.38</strong></p></li><li><p>Change Tab to Body</p></li><li><p>Select the form-data radio button</p></li><li><p>From the drop down, select Key type to be file</p></li><li><p>For Value, select one of our test images</p></li><li><p>Click send to send our image to our API</p></li><li><p>Our response will be shown in the window below.</p></li></ol><p><strong>The output is JSON file containing:</strong></p><pre class="prettyprint linenums">{ | |
| "MainColor": "Red", | |
| "catOrDog": "Cat" | |
| }</pre><p>The cool thing about using Postman is that we can generate the code to call this API in several different languages:</p><p>See blue box to bring up the <strong>code </strong>box:</p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_06-15-21-9b7592ec57e8a4769ac2d8d8d649580c.jpg"></figure><p><strong>Code Generator</strong></p><figure><img src="https://udemy-images.s3.amazonaws.com:443/redactor/raw/2019-04-23_00-55-22-1aaeea8249c6c70d464a1ece0466b273.JPG"></figure><p><strong>Note</strong>: To keep our API running constantly launch the python code using this instead:</p><p><code>sudo nohup python3 forms.py & screen</code></p><p><br></p><h4><strong>Conclusion</strong></h4><p><br></p><p>So you've just successfully deployed a Computer Vision Web App and API that can be used by users anywhere in the world! This facilitates many possibilities from developing Mobile Apps, startup products and research tools. However, it should be noted there are many improvements that can be made:</p><ul><li><p>Saving our uploaded image to as S3 Bucket. We don't want to store all these images on our API server and it wasn't designed for mass storage. It's quite easy to configure and S3 bucket and store all uploaded images there. If privacy is a concern we can forget that entirely and use Python to delete the image after it's been processed.</p></li><li><p>Using Nginx or Gunicorn or something similar to be the main server for our API</p></li><li><p>Using a more scalable design (this far from my expertise, but if you ever wanted to support simultaneous users, you'll need to make some adjustments. </p></li></ul><p><br></p> |