The official PredicSis ML SDK for Javascript (for pure frontend applications, without node).
Add PredicSis ML SDK into your bower.json
bower install predicsis_ml_sdk-javascript --save-dev
If you want to change PredicSis API host, add these lines to your app.js
configuration file.
angular
.module('YourAngularApplication', ['predicsis.jsSDK'])
.config(function(predicsisAPIProvider, config) {
predicsisAPIProvider.setBaseUrl('https://predicsis_api_host');
predicsisAPIProvider.setOauthToken('4V83j2BWgcPONK8Xw8P7953yPvnTzz784V83j2BWgcPONK8Xw8P7953yPvnTzz78');
})
.controller('ExampleCtrl', function(predicsisAPI) {
var self = this;
predicsisAPI.Datasets.all().then(function(datasetList) { self.datasets = datasetList; });
});
You can also setup your personal access token within a run context. This can be useful if your token is stored in a cookie or in localStorage.
angular
.module('YourAngularApplication', ['predicsis.jsSDK'])
.config(function(predicsisAPIProvider) {
predicsisAPIProvider.setBaseUrl('http://localhost:8003');
})
.run(function(predicsisAPI, $cookieStore) {
predicsisAPI.setOauthToken($cookieStore.get('session'));
predicsisAPI.setErrorHandler(console.log.bind(console));
})
.controller('ExampleCtrl', function(predicsisAPI) {
var self = this;
predicsisAPI.Datasets.all().then(function(datasetList) { self.datasets = datasetList; });
});
If you want to send API requests with no Authorization header, you must explicitly use
predicsisAPI.setOauthToken(false);
Default values:
- api endpoint:
https://api.predicsis.com
- error handler:
throw Error(response);
- oauth access token:
no-token-defined
You can start using our SDK assuming you already have a user token
Once you're done, you can send API request easily:
- list projects:
predicsisAPI.Projects .all() .then(function(projectList) { console.log(projectList); })
- generate a dictionary from a dataset:
predicsisAPI.Dictionaries .create({dataset_id: '53c7dea470632d3417020000', name: 'My dictionary'}) .then(function(dictionary) { console.log(dictionary); });
- start a learn process:
predicsisAPI.Models.learn(project)
- ...
See the SDK documentation for more examples.
//Get an HTML5 File instance
fileInput.addEventListener('change', function(evt) {
var file = evt.target.files[0];
predicsisAPI.uploadHelper
.processFile(file, { chunkSize: 50 * 1024 * 1024 });
$rootScope.$on('jsSDK.upload.starting', function(event, upload) {
console.log(upload.id, upload.fileName, upload.fileSize, upload.progression);
});
$rootScope.$on('jsSDK.upload.progress', function(event, upload) {
console.log(upload.id, upload.fileName, upload.fileSize, upload.progression, upload.path);
});
$rootScope.$on('jsSDK.upload.uploaded', function(event, upload) {
console.log(upload.id, upload.fileName, upload.fileSize, upload.progression, upload.path);
});
$rootScope.$on('jsSDK.upload.cancelled', function(event, upload) {
console.log(upload.id, upload.fileName, upload.fileSize, upload.progression, upload.path);
});
$rootScope.$on('jsSDK.upload.error', function(event, failure, retry) {
console.log(failure.id, failure.fileName, failure.path, failure.err);
retryButton.addEventListener('click', retry);
});
});
This project comes with a little angular application (located in the app
folder). After a complete install, just run:
bower install
npm install
# start the server
grunt connect:server
And go to http://localhost:8100/app/index.html
.
MIT. See the LICENSE for more details.
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request