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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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