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:
- http://localhost/predict:5000
- http://localhost/train:5000
- http://localhost/metric:5000
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.
Metadata
Release files for flaskriver 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flaskriver-0.0.4.tar.gz | 3.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flaskriver-0.0.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 8.1 kB
Release files / flaskriver-0.0.4.tar.gz
| Download URL | flaskriver-0.0.4.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c116a4aeae1311e0da8d709e946df2fe21f9277794840f9fb0fb0f306d91f914
|
|
BLAKE2b-256 checksum How to use checksums |
106f5c1ca43e0157766280b3c56ed1b1f64c5bb7bb18f5dfd541145c5562f488
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|
Release files / flaskriver-0.0.4-py2.py3-none-any.whl
| Download URL | flaskriver-0.0.4-py2.py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
e84a2f20aada23d0830c76855e11f91df59728af6a2c9ee9cc6c27a86f4048cc
|
|
BLAKE2b-256 checksum How to use checksums |
26ecfa1e420875a9e32eaacf79187e712aa0c49aed97a4568cf98f39810358e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.7
|