Abstract class for Naogi ML deployment
Project description
naogi_model
NaogiModel it is an abstract class for the naogi.com ML deployment platform
How to deploy via naogi.com
- Add
naogito your project requirements.txt - create file
naogi.pyin the root directory (copypaste file from naogi.py) - implement your logic of model loading, prepareing and calling
- go to you naogi.com profile, create project and connect git
How it works? (What to implement in naogi.py)
Loading model (server starting time)
When naogi server is starting, it call load_model(self) -- you have to implement model loading logic in that function (loading from file, internet, etc.)
Here you have to load and init your model and save the model object to some variable
Example
def load_model(self):
self.model = __get_model()
self.model.load_weights()
Prepareing (request time)
When you call [GET/POST] /prepare of your API prepare(self, params_dict) is calling first.
All request params can be found in params_dict. Here you can prepare you params: open and modify Image, transform and normalize text and safe data for prepare to self attribute.
Example
# now you can make GET /predict?text_data=My-long-text
# (and not worry about spaces)
def prepare(self, params_dict):
self.text = params_dict['text_data'].strip()
Predicting (request time)
After request params prepareing predict(self) is calling.
def predict(self):
raw = self.model.predict(self.text)
return __from_raw_to_some(raw)
Here you have to return the value, that valid for some Renderer class (json, file, custom)
Rendering (request time)
And the last step is calling renderer().render(...) and passing the result of predict
Out of the box you can use JsonRenderer and FileRenderer
or
you can create custom renderer from AbstractRenderer
class MyRenderer(AbstractRenderer):
def render(data):
return ...
def renderer(self):
return MyRenderer
JsonRenderer accepts any json.dumps valid data
FileRenderer uses flask's send_file under the hood, so you can pass any bytes. Additional params can watch here
Fin
And finally you can make API calls to <your-naogi-project-url>/predict with params
Development
...
Testing
Before testing you should install pytest
From root folder
PYTHONPATH='./' pytest tests/renderers/pil_image_renderer.py
Deploy
rm -rf dist/*
python3 -m build
python3 -m twine upload --repository pypi dist/*
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file naogi-0.0.6.tar.gz.
File metadata
- Download URL: naogi-0.0.6.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc083a054dc0443a705e44ba07d8f83c4bbe504268b0ba213a1752df3dd40e12
|
|
| MD5 |
21b391e3c7e83c9a1c1bf0a922b0f333
|
|
| BLAKE2b-256 |
e42f334fdce0d9b6a3672e3dab71d5e638faccaf9d39fc6911f4a5f89dab64c5
|
File details
Details for the file naogi-0.0.6-py3-none-any.whl.
File metadata
- Download URL: naogi-0.0.6-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e8bdd1cbb512c0b4296293751ab5958be6a0cc668ab6a5e374c25dc63089866
|
|
| MD5 |
43603b7c4c308823d08f52dbce3530db
|
|
| BLAKE2b-256 |
ef1d0b45a6d98213084d5338f9b70349f11ad03ba934a7a1418b6bb3f40d576a
|