Skip to content

tchiayan/easy_serve

Repository files navigation

Easy Serve

High level abstraction for deploying simple machine learning models using Flask. This project allows you to quickly deploy a small testing model locally as an API service without complicated setup.

Build Status PyPI version License: MIT

Getting started

  1. Install the package using pip command: pip install easy_serve
  2. Extend your model using EasyServe class.
  3. Run server using this command: python -m easy_serve.server --class_path PATH_TO_easy_serve_CLASS --class_name YOUR_CUSTOM_easy_serve --port PORT --model_args param1=value1;param2=value2

Example

  1. Create a file custom_model.py Here's a complete example of creating and deploying a simple model:
from easy_serve import EasyServe

class TextProcessor(EasyServe):
    def __init__(self, prefix=""):
        self.prefix = prefix
    
    def model_init(self):
        print("Model initialized!")
    
    def preprocessing(self, request):
        return request.json.get('text', '')
    
    def inference(self, text):
        return f"{self.prefix} {text}".strip()
    
    def postprocessing(self, result):
        return {"result": result.upper()}
  1. Run the server
python -m easy_serve.server --class_path custom_model --class_name TextProcessor --port 5000 --model_args prefix=Hello
  1. Test with curl:
curl -X POST http://localhost:5000/prediction -H "Content-Type: application/json" -d '{"text":"world"}'

Response:

{"result":"HELLO WORLD"}

About

High level abstraction for deploying simple machine learning models using Flask

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages