Package: mlchain
MLChain:Auto-Magical Deploy AI model at large scale, high performance, and easy to useExplore the docs »Our Website·Examples in PythonMLChain is a simple, easy to use library that allows you to deploy your Machine Learning
model to hosting server easily and efficiently, drastically reducing the time required
to build API that support an end-to-end AI product.Key featuresFast:MLChain prioritize speed above other criteria.Fast to code:With a finished Machine Learning model, it takes 4 minutes on average
to deploy a fully functioning API with MLChain.Flexible:The nature of ML-Chain allows developing end-to-end adaptive, with
varied serializer and framework hosting at your choice.Less debugging: We get it. Humans make mistakes. With MLChain, its configuration makes debugging a lot easier and almost unnecessary.Easy to code:as a piece of cake!Standards-based:Based on the open standards for APIs: OpenAPI (previously known as Swagger), along with JSON Schema and other options.InstallationMLChain required Python 3.6 and abovePyPITo install latest stable version of MLChain, simply run:pipinstallmlchainBuild from sourceIf you can't wait for the next release, install the most up to date code with frommasterbranch by running the following command:gitclonehttps://github.com/Techainer/mlchain-pythoncdmlchain-python
pipinstall-rrequirements.txt
pythonsetup.pyinstallOr simply install using git:pipinstallgit+https://github.com/Techainer/mlchain-python@master--upgradeDocumentationRead ours documentationhereDemoHere's a minimal example of serving a dummy python classCreate aserver.pyfile:importcv2importnumpyasnpfrommlchain.baseimportServeModelclassModel():""" Just a dummy model """defpredict(self,image:np.ndarray):"""Resize input to 100 by 100.Args:image (numpy.ndarray): An input image.Returns:The image (np.ndarray) at 100 by 100."""image=cv2.resize(image,(100,100))returnimage# Define modelmodel=Model()# Serve modelserve_model=ServeModel(model)# Deploy modelif__name__=='__main__':frommlchain.serverimportFlaskServer# Run flask model with upto 12 threadsFlaskServer(serve_model).run(port=5000,threads=12)Now run:pythonserver.pyAnd you should see something like this:[mlchain-logger]:[7895] [2020-08-18 09:53:02 +0700]-[INFO]-[flask_server.py:424]---------------------------------------------------------------------------------[mlchain-logger]:[7895] [2020-08-18 09:53:02 +0700]-[INFO]-[flask_server.py:425]-Served model with Flask at host=127.0.0.1, port=5000[mlchain-logger]:[7895] [2020-08-18 09:53:02 +0700]-[INFO]-[flask_server.py:426]-Debug = False[mlchain-logger]:[7895] [2020-08-18 09:53:02 +0700]-[INFO]-[flask_server.py:427]---------------------------------------------------------------------------------Now you can access your API athttp://localhost:5000You can open Swagger UI athttp://localhost:5000/swaggerand try your API out right awayAfter explore all your API endpoint over there, create aclient.pyfile:importnumpyasnpfrommlchain.clientimportClientmodel=Client(api_address='http://localhost:5000').model()# Create a dummy input with shape (200, 200)input_image=np.ones((200,200),dtype=np.uint8)# Then pass it through our client just like normal Pythonresult_image=model.predict(input_image)print(result_image.shape)# And the result should be (100, 100)Now you have a supper simpleClientto work with. Sooo easy :DExamplesServing MNIST using MLchain:https://github.com/Techainer/mnist-mlchain-examplesAsking for helpWelcome to the MLChain community!If you have any questions, please feel free to:Read the docsOpen an issuesWe are happy to help