Skip to content

Instantly share code, notes, and snippets.

@alvarolopez
Last active April 3, 2020 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvarolopez/850160d4681794d5292222d4ebbaf938 to your computer and use it in GitHub Desktop.
Save alvarolopez/850160d4681794d5292222d4ebbaf938 to your computer and use it in GitHub Desktop.
IRIS and DEEPaaS integration
$ virtualenv env --python=python3
(...)
$ source env/bin/activate
(env) $ pip3 install .
(...)
(env) $ pip3 install deepaas
(...)
(env) $ deepaas-run
## ###
## ###### ##
.##### ##### #######. .#####.
## ## ## // ## // ## ## ##
##. .## ### ### // ### ## ##
## ## #### #### #####.
Hybrid-DataCloud ##
Welcome to the DEEPaaS API API endpoint. You can directly browse to the
API documentation endpoint to check the API using the builtint Swagger UI
or you can use any of our endpoints.
API documentation: http://127.0.0.1:5000/ui
API specification: http://127.0.0.1:5000/swagger.json
V2 endpoint: http://127.0.0.1:5000/v2
-------------------------------------------------------------------------
2020-02-04 13:10:50.027 21186 INFO deepaas [-] Starting DEEPaaS version 1.0.0
2020-02-04 13:10:50.231 21186 INFO deepaas.api [-] Serving loaded V2 models: ['iris-deepaas']
from joblib import dump, load
import numpy
from sklearn import svm
from sklearn import datasets
from webargs import fields, validate
def train():
clf = svm.SVC()
X, y = datasets.load_iris(return_X_y=True)
clf.fit(X, y)
dump(clf, 'iris.joblib')
def predict(data):
clf = load('iris.joblib')
data = numpy.array(data).reshape(1, -1)
prediction = clf.predict(data)
return {"labels": prediction.tolist()}
def get_predict_args():
args = {
"data": fields.List(
fields.Float(),
required=True,
description="Data to make a prediction. The IRIS dataset expects "
"four values containing the Sepal Length, Sepal Width, "
"Petal Length and Petal Width.",
validate=validate.Length(equal=4),
),
}
return args
from joblib import dump, load
import numpy
from sklearn import svm
from sklearn import datasets
def train():
clf = svm.SVC()
X, y = datasets.load_iris(return_X_y=True)
clf.fit(X, y)
dump(clf, 'iris.joblib')
def predict(data):
clf = load('iris.joblib')
data = numpy.array(data).reshape(1, -1)
prediction = clf.predict(data)
return {"labels": prediction.tolist()}
from distutils.core import setup
setup(
name='test-iris-with-deepaas',
version='1.0',
description='This is an SVM trained with the IRIS dataset',
author='Álvaro López',
author_email='aloga@ifca.unican.es',
py_modules="iris-deepaas.py",
dependencies=['joblib', 'scikit-learn'],
entry_points={
'deepaas.v2.model': ['iris=iris-deepaas'],
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment