Skip to main content

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 naogi to your project requirements.txt
  • create file naogi.py in 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

naogi-0.0.6.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

naogi-0.0.6-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

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

Hashes for naogi-0.0.6.tar.gz
Algorithm Hash digest
SHA256 bc083a054dc0443a705e44ba07d8f83c4bbe504268b0ba213a1752df3dd40e12
MD5 21b391e3c7e83c9a1c1bf0a922b0f333
BLAKE2b-256 e42f334fdce0d9b6a3672e3dab71d5e638faccaf9d39fc6911f4a5f89dab64c5

See more details on using hashes here.

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

Hashes for naogi-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9e8bdd1cbb512c0b4296293751ab5958be6a0cc668ab6a5e374c25dc63089866
MD5 43603b7c4c308823d08f52dbce3530db
BLAKE2b-256 ef1d0b45a6d98213084d5338f9b70349f11ad03ba934a7a1418b6bb3f40d576a

See more details on using hashes here.

Supported by

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