Skip to content

Commit

Permalink
🚀 🚀 🚀 First launch of MLChain
Browse files Browse the repository at this point in the history
  • Loading branch information
phamngoclinh96 committed Aug 17, 2020
0 parents commit b442350
Show file tree
Hide file tree
Showing 161 changed files with 10,277 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
__pycache__
.vscode/
build
dist
mlchain.egg-info
*.idea
.pyc
test/*
.pytest_cache
51 changes: 51 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
language: python
arch:
- amd64
python:
- 3.6
- 3.7
jobs:
include:
# ====== WINDOWS =========
- name: "Python 3.6.8 on Windows"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell # 'language: python' is an error on Travis CI Windows
before_install:
- choco install python --version 3.6.8
- python -m pip install scikit-build
- python -m pip install pytest
install:
- python --version
- python -m pip install .
script:
- pip install pytest
- pytest tests/
env: PATH=/c/Python36:/c/Python36/Scripts:$PATH
- name: "Python 3.7.4 on Windows"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell # 'language: python' is an error on Travis CI Windows
before_install:
- choco install python --version 3.7.4
- python -m pip install scikit-build
- python -m pip install pytest
install:
- python --version
- python -m pip install .
script:
- pip install pytest
- pytest tests/
env: PATH=/c/Python37:/c/Python37/Scripts:$PATH

before_install:
- sudo apt-get update
- sudo apt-get install -y software-properties-common
- sudo apt-get update
- sudo apt-get install -y --no-install-recommends build-essential gcc
- pip install scikit-build
- pip install pytest
install:
- python --version
- pip install .
script:
- pip install pytest
- pytest tests/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Techainer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Techainer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
10 changes: 10 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include LICENSE *.rst *.toml *.yml *.yaml
graft .github

# Frontend
recursive-include mlchain/ *.css
recursive-include mlchain/ *.html
recursive-include mlchain/ *.woff2
recursive-include mlchain/ *.ico
recursive-include mlchain/ *.js
recursive-include mlchain/ *.png
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<p align="center">
<a href="https://mlchain.ml" target="_blank">
<img src="docs/img/logo.png" target="_blank" height="80"/>
</a><br><br>
<i> <strong>MLChain:</strong> Auto-Magical Deploy AI model at large scale, high performance, and easy to use </i> <br>
<a href="https://mlchain.readthedocs.io/en/latest/?" target="_blank">
<br>
<strong> Explore the docs » </strong>
</a> <br>
<a href="https://mlchain.ml" target="_blank"> Our Website </a>
·
<a href="https://github.com/techainer/examples-python" target="_blank"> Examples in Python </a>
</p>


[![PyPI version](https://badge.fury.io/py/mlchain.svg)](https://badge.fury.io/py/mlchain)
[![Downloads](https://pepy.tech/badge/mlchain)](https://pepy.tech/project/mlchain)
[![Build Status](https://travis-ci.org/Techainer/mlchain-python.svg?branch=master)](https://travis-ci.org/Techainer/mlchain-python)
[![Documentation Status](https://readthedocs.org/projects/mlchain/badge/?version=latest)](https://mlchain.readthedocs.io/en/latest/?badge=latest)
[![license](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Techainer/mlchain-python/blob/master/LICENSE)
</div>


MLChain 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 features

- <b> Fast: </b> MLChain prioritize speed above other criteria.

- <b> Fast to code: </b> With a finished Machine Learning model, it takes 4 minutes on average
to deploy a fully functioning API with MLChain.

- <b> Flexible: </b> The nature of ML-Chain allows developing end-to-end adaptive, with
varied serializer and framework hosting at your choice.

- <b> Less debugging </b>: We get it. Humans make mistakes. With MLChain, its configuration makes debugging a lot easier and almost unnecessary.

- <b> Easy to code: </b> as a piece of cake!

- <b> Standards-based: </b> Based on the open standards for APIs: OpenAPI (previously known as Swagger), along with JSON Schema and other options.


## Installation

### PyPI
To install latest stable version of MLChain, simply run:
```bash
pip install mlchain
```

![](docs/img/README/mlchain.gif)

### Build from source
To install latest changes from `master` branch, run the following:
```bash
git clone https://github.com/Techainer/mlchain-python
cd mlchain-python
pip install -r requirements.txt
python setup.py install
```

## Documentation
Read ours documentation [here](https://mlchain.ml)


## Demo
Here's a minimal example of serving a dummy python class

Create a `main.py` file with:

```python
from mlchain.base import ServeModel

class Model():
def __init__(self):
self.ans = 10

def predict(self):
return self.ans

# Define model
model = Model()

# Serve model
serve_model = ServeModel(model)`

# Deploy model
if __name__ == '__main__':
from mlchain.rpc.server.flask_server import FlaskServer
FlaskServer(serve_model).run(port=5000,threads=12) # Run flask model with upto 12 threads
```
Now run:

```bash
python3 main.py
```

Now you can access your api at http://localhost:5000

## Other examples
- Serving MNIST using mlchain: https://github.com/Techainer/mnist-mlchain-examples
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Mlchain helps AI developers to easily run, deploy and monitor AI models and Workflows without having Devops skills.

This Mlchain Python library lets you launch models and do many tasks with Mlchain Platform. Please sign up your account on Mlchain before working with it.
1 change: 1 addition & 0 deletions build_wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3 setup.py bdist_wheel
Binary file added docs/.DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions docs/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
appdirs==1.4.0
click==6.7
Jinja2==2.9.6
livereload==2.5.1
Markdown==2.6.8
markdown-include==0.5.1
MarkupSafe==1.0
mkdocs==0.16.3
mkdocs-bootstrap==0.1.1
mkdocs-bootswatch==0.4.0
mkdocs-material==1.8.0
packaging==16.8
Pygments==2.2.0
pymdown-extensions==3.5
pyparsing==2.1.10
PyYAML==3.12
six==1.10.0
tornado==4.5.1
60 changes: 60 additions & 0 deletions docs/0_Quick_Deploy/quick_deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Deploy your model in 20 seconds

Implement our model

```python

class Model:
def _init__(self):
self.model = torch.load(...)

def predict(self, img:nd.array):
return self.model(img)

def predict_batch(self, imgs:List(nd.array)):
return self.model(img for img in imgs)
```

### Deploy with Python/Flask (bad)

```python
import flask
import json
import time

app = flask.Flask(__name__)
app.config["DEBUG"] = True

model = Model()

@app.route('/predict/<img>', methods=['GET'])
def predict(img):
start = time.time()
ans = model.predict(img)
total_time = time.time() - start
final_return = {'Time': total_time, 'result': ans}
return json.dump(final_return)

@app.route('/predict/<imgs>', methods=['POST', 'GET'])
def predict_batch(imgs):
final_return = []
for img in imgs:
start = time.time()
ans = model.predict(img)
total_time = time.time() - start
final_dict = {'Time': total_time, 'result': ans}
final_return.append(final_dict)
return json.dump(final_return)

app.run()
```

### Deploy with MLChain (good)

```python
from mlchain.base import ServeModel
model = Model()
serve_model = ServeModel(model)
```

On top of that,
Loading

0 comments on commit b442350

Please sign in to comment.