Giter VIP home page Giter VIP logo

flaskrml's Introduction

Serving ML Model via Flask

Flaskrml

Demonstrating how to serve ML models via REST using flask

Setting up the Backend

Install Dependencies

  1. Python 3.10 - Follow instructions to install the latest version of python for your platform in the python docs

  2. Virtual Environment - Recommend working within a virtual environment . This keeps your dependencies for each project separate and organized. Instructions for setting up a virual environment for your platform can be found in the python docs

  3. PIP Dependencies - Once your virtual environment is setup and running, install the required dependencies by navigating to the /backend directory and running:

pip install -r requirements.txt

Key Pip Dependencies

  • Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.

  • Trax Trax is an end-to-end library for deep learning that focuses on clear code and speed. I

  • Tensorflow An end-to-end machine learning platform

  • jax JAX is NumPy on the CPU, GPU, and TPU, with great automatic differentiation for high-performance machine learning research.

Run the Server

Backend

To run the application navigate to the backend folder and run the following commands:

export FLASK_APP=app
export FLASK_ENV=development
flask run

These commands put the application in development and directs our application to use the __init__.py file in our flaskr folder. Working in development mode shows an interactive debugger in the console and restarts the server whenever changes are made. If running locally on Windows, look for the commands in the Flask documentation.

The application is run on http://127.0.0.1:5000/ by default and is a proxy in the frontend configuration.

API Reference

Getting Started

  • Base URL: At present this app can only be run locally and is not hosted as a base URL. The backend app is hosted at the default, http://127.0.0.1:5000/, which is set as a proxy in the frontend configuration.
  • Authentication: This version of the application does not require authentication or API keys.

Error Handling

Errors are returned as JSON objects in the following format:

{
    "success": False, 
    "error": 400,
    "message": "bad request"
}

The API will return three error types when requests fail:

  • 400: bad request
  • 404: resource not found
  • 422: not processable
  • 405: method not allowed
  • 500: Internal server error

Endpoints

POST'/ner'

  • Request Arguments: a json object with statement to find named entities .
  • Returns: success value
  • curl http://127.0.0.1:5000/ner -X POST -H "Content-Type: application/json" -d d '{"statement":"The nightlife in Colombia is great as per Kenyans based in Bogota NewYork"}'
{
  {"data":{"":"O","Bogota":"B-geo","Colombia":"B-geo","Kenyans":"O","NewYork":"I-geo","The":"O","as":"O","based":"O","great":"O","in":"O","is":"O","nightlife":"O","per":"O"},
  "success":true}
}

POST'/siamese'

  • Request Arguments: a json object with statement_one and statement_two to determine if the statements are similar.
  • Returns: success value
  • curl http://127.0.0.1:5000/siamese -X POST -H "Content-Type: application/json" -d '{"statement_one":"MIT is good","statement_two":"highschool"}'
{
  "similar":"False","success":true}

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.