Skip to content

Commit

Permalink
Add moderation solution
Browse files Browse the repository at this point in the history
* Add moderation solution

* Fix missing semicolon
  • Loading branch information
rok-povsic authored Oct 18, 2018
1 parent 12f0ac4 commit 09623e8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let Inputs = require('./Inputs');
let Concepts = require('./Concepts');
let Workflow = require('./Workflow');
let Workflows = require('./Workflows');
let Solutions = require('./solutions/Solutions');
let {API, ERRORS, getBasePath} = require('./constants');
let {TOKEN_PATH} = API;

Expand Down Expand Up @@ -106,6 +107,7 @@ class App {
this.concepts = new Concepts(this._config);
this.workflow = new Workflow(this._config);
this.workflows = new Workflows(this._config);
this.solutions = new Solutions(this._config);
}

_getToken(resolve, reject) {
Expand Down Expand Up @@ -136,6 +138,5 @@ class App {
});
}
}
;

module.exports = App;
56 changes: 56 additions & 0 deletions src/solutions/Moderation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
let axios = require('axios');
let {wrapToken} = require('../utils');
let {isSuccess, clone} = require('../helpers');

let BASE_URL = 'https://api.clarifai-moderation.com';

class Moderation {

constructor(_config) {
this._config = _config;

}

predict(modelID, imageURL) {
return wrapToken(this._config, (headers) => {
let url = `${BASE_URL}/v2/models/${modelID}/outputs`;
let params = {
inputs: [
{
data: {
image: {
url: imageURL
}
}
}
]
};

return new Promise((resolve, reject) => {
return axios.post(url, params, {headers}).then((response) => {
if (isSuccess(response)) {
let data = clone(response.data);
resolve(data);
} else {
reject(response);
}
}, reject);
});
});
}

getModerationStatus(imageID) {
return wrapToken(this._config, (headers) => {
let url = `${BASE_URL}/v2/inputs/${imageID}/outputs`;
return new Promise((resolve, reject) => {
return axios.get(url, {headers}).then((response) => {
let data = clone(response.data);
resolve(data);
}, reject);

});
});
}
}

module.exports = Moderation;
10 changes: 10 additions & 0 deletions src/solutions/Solutions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let Moderation = require('./Moderation');

class Solutions {

constructor(_config) {
this.moderation = new Moderation(_config);
}
}

module.exports = Solutions;

0 comments on commit 09623e8

Please sign in to comment.