Skip to main content

This is a package which aims to combine the lighweight web-framework flask

Project description

logo

This is a repository for the open-source project Flaskriver. It combines the lightweight web-framework Flask with the online-ML library River to make deploying online-ML models to web web easier. For more info on online-ML check out the river repository or the official website.

Introduction

First you will have to install the package via pip:

pip install flaskriver

The following code will spin up a developement server which is providing a logistic regression model. You can reach it's endpoints at:

from flaskriver import ClassificationInterface
from flask import Flask
from river import linear_model, metrics

model = linear_model.LogisticRegression()

mae = metrics.MAE()
accuracy = metrics.Accuracy()
metrics = [mae, accuracy]

interface = ClassificationInterface(model, metrics)

app = Flask(__name__)
interface.registerToApp(app)

if __name__ == "__main__":
    app.run(host="localhost", debug=True)

At these endpoints the app will await the training data as JSON (since river models work with dictionaries). A JSON body for training the model could look something like this:

{
    "features":{
        "x1":300,
        "x2":210
    },
    "target":false
}

And the JSON body for predicting a value would then look like this:

{
    "x1":100,
    "x2":150
}

With the following code you can set up a small client which goes through an entire dataset (the "Phising" dataset which comes with River) and incrementally trains the model and evaluates it's metrics.

import requests
from river import datasets

dataset = datasets.Phishing()

train_url = f"http://localhost:5000/train"
metric_url = f"http://localhost:5000/metric"


for x, y in dataset:
    payload = {"features": x, "target": y}
    response = requests.post(train_url, json=payload)

    response = requests.get(metric_url)
    print(response.json())

Documentation

You can find more detailed documentation for Flaskriver at flaskriver.ml

Contributing

If you would like to contribute something to the project fell free to share your ideas in form of an issue. You can also reach out to me directly via e-mail.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flaskriver-0.0.4.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

flaskriver-0.0.4-py2.py3-none-any.whl (4.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file flaskriver-0.0.4.tar.gz.

File metadata

  • Download URL: flaskriver-0.0.4.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for flaskriver-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c116a4aeae1311e0da8d709e946df2fe21f9277794840f9fb0fb0f306d91f914
MD5 4961de94f31d8519c163987ec4b83e27
BLAKE2b-256 106f5c1ca43e0157766280b3c56ed1b1f64c5bb7bb18f5dfd541145c5562f488

See more details on using hashes here.

File details

Details for the file flaskriver-0.0.4-py2.py3-none-any.whl.

File metadata

  • Download URL: flaskriver-0.0.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for flaskriver-0.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e84a2f20aada23d0830c76855e11f91df59728af6a2c9ee9cc6c27a86f4048cc
MD5 8bf5055379f44ca966e0d10bb5e9c876
BLAKE2b-256 26ecfa1e420875a9e32eaacf79187e712aa0c49aed97a4568cf98f39810358e0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page