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.
- Install the package using pip command:
pip install easy_serve - Extend your model using
EasyServeclass. - 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
- 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()}- Run the server
python -m easy_serve.server --class_path custom_model --class_name TextProcessor --port 5000 --model_args prefix=Hello- Test with curl:
curl -X POST http://localhost:5000/prediction -H "Content-Type: application/json" -d '{"text":"world"}'Response:
{"result":"HELLO WORLD"}