Giter Site home page Giter Site logo

mlip-api-lab's Introduction

Lab 1: Calling, Building, and Securing APIs

In homework I1 you will use third-party machine learning APIs and in the group project you will develop your own APIs. In this lab, you will experiment with both, connecting to the Azure Vision API and providing your own API endpoint. To receive credit for this lab, show your work to the TA during recitation.

Deliverables

  • Create an account and connect to the Azure Vision API
  • Explain to the TA why hard-coding credentials is a bad idea. Commit your code to GitHub without committing your credentials.
  • Run the API endpoint with the starter code and demonstrate that it works with an example invocation (e.g., using curl).

Getting started

Clone the starter code from this Git repository

The code implements a flask web application that receives API requests to analyze an image and return information about the image, including the text contained within. To identify the text, the OCR feature of the Azure Vision API [documentation, response format] can be used by adjusting the API endpoint and credentials in the code. We use the Azure’s provided libraries to abstract from low-level protocol details.

Install the dependencies in the requirements.txt file with pip or similar. To set up the flask server, just run python3 app.py. The system should try to analyze an example image and report the results when you go to http://localhost:3000/

Connecting to the Azure Vision API

  1. Sign up for the a student account for Microsoft Azure: https://azure.microsoft.com/en-us/free/students/ – no credit card required

  2. Create an instance of the Computer Vision service and get an API endpoint of your instance of the service.

  3. Get a subscription key to authorize your script to call the Computer Vision API.

  4. Update the code with the endpoint and key and test it.

Secure your Credentials

The starter code hardcodes credentials in the code. This is a bad practice.

Research and discuss best practices, such as never hard-code credentials, never commit credentials to Git, rotate secrets regularly, encrypt your secrets at rest/in-transit if possible, practice least-access privilege on machines where your credentials are stored as environment variables or within local files.

Rewrite the code to load credentials from a file or an environment variable and commit the code without the credentials to GitHub.

Calling your own API

The starter code comes with a flask server that serves the website at http://localhost:3000/ but also exposes an own API at http://localhost:3000/api/v1/analysis/ accepting a GET request with a JSON object with a single field “uri” pointing to an image to analyze.

Identify how to call your own API with a tool like curl or Postman.

Optionally extend the API or document it with Swagger.

Additional resources

mlip-api-lab's People

Contributors

eshetty avatar nikitaagarwala16 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.