Skip to content

Commit d2e148d

Browse files
committed
Merged old nodes (recognition) with new ones (training)
1 parent 2401644 commit d2e148d

2 files changed

Lines changed: 317 additions & 122 deletions

File tree

services/visual_recognition/v1.html

Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,318 @@
8282
});
8383
})();
8484
</script>
85+
86+
<script type="text/javascript">
87+
88+
function classifiersList(node) {
89+
90+
console.log("-> classifiersList");
91+
92+
var last = $('#node-input-classifier').children().last();
93+
var opts = [];
94+
$.getJSON('watson-visual-recognition/list/'+node.service,function(data) {
95+
var classifiers = data.classifiers;
96+
for (var i=0; i < classifiers.length; i++) {
97+
console.log("-> classifiersList.data "+classifiers[i].name);
98+
var selected = node.classifier === classifiers[i].name;
99+
opts.push(
100+
'<option value="' + classifiers[i].classifier_id + '"' + (selected ? " selected":"") + '>' +
101+
classifiers[i].name +
102+
'</option>'
103+
);
104+
}
105+
106+
console.log("-> node.classifier: "+node.classifier);
107+
if (opts.length === 0) {
108+
$('#node-input-classifier').find("option").filter(function() {
109+
return $(this).val() === node.classifier;
110+
}).attr('selected', true);
111+
} else {
112+
last.before(opts.join(""));
113+
}
114+
});
115+
}
116+
117+
RED.nodes.registerType('watson-visual-util',{
118+
category: 'IBM_Watson',
119+
color: '#FFFF80',
120+
defaults: {
121+
name: {value:""},
122+
command: {value:"",required:true},
123+
classifier: {value:"",required:false},
124+
username: {value:"",required:true},
125+
password: {value:"",required:true},
126+
service: {value:"",required:true}
127+
},
128+
inputs:1,
129+
outputs:1,
130+
icon: "visual2.png",
131+
label: function() {
132+
return this.name||"visual utils";
133+
},
134+
135+
visuals: [],
136+
137+
oneditprepare: function() {
138+
var node = this;
139+
console.log("this: "+JSON.stringify(this));
140+
141+
classifiersList(node);
142+
143+
$.getJSON('watson-visual-recognition/vcap/',function(data) {
144+
145+
node.visuals = data;
146+
var last = $('#node-input-service').children().last();
147+
var opts = [];
148+
149+
for (var i=0; i < data.length; i++) {
150+
var selected = node.service === data[i].name;
151+
opts.push(
152+
'<option value="' + data[i].name + '"' + (selected ? " selected":"") + '>' +
153+
data[i].name +
154+
'</option>'
155+
);
156+
}
157+
158+
if (opts.length === 0) {
159+
node.service = "_ext_";
160+
$('#node-input-service').find("option").filter(function() {
161+
return $(this).val() == node.service;
162+
}).attr('selected', true);
163+
} else {
164+
last.before(opts.join(""));
165+
}
166+
167+
if (node.service === '_ext_') {
168+
$("#external_visual_service :input").attr('disabled',false);
169+
} else {
170+
for (var i2=0;i2<node.visuals.length;i2++) {
171+
var ws = node.visuals[i2];
172+
if (ws.name === node.service) {
173+
$("#node-input-username").val(ws.username);
174+
$("#node-input-password").val(ws.password);
175+
console.log("** Visual: "+JSON.stringify(node.visuals[i2]));
176+
}
177+
}
178+
$("#external_visual_service :input").attr('disabled',true);
179+
}
180+
181+
if (node.command === 'list') {
182+
$("#node-input-classifier :input").attr('disabled',true);
183+
} else {
184+
$("#node-input-classifier :input").attr('disabled',false);
185+
}
186+
187+
});
188+
189+
$("#node-input-command").on("change",function() {
190+
if (this.value === 'list') {
191+
$("#node-input-classifier :input").attr('disabled',true);
192+
} else {
193+
$("#node-input-classifier :input").attr('disabled',false);
194+
}
195+
});
196+
197+
$("#node-input-service").on("change",function() {
198+
$("#node--input-service").val(this.value);
199+
if (this.value === '_ext_') {
200+
$("#external_visual_details :input").attr('disabled',false);
201+
} else {
202+
if(node.visuals) {
203+
$("#external_visual_details :input").attr('disabled',true);
204+
for (var i=0;i<node.visuals.length;i++) {
205+
var ws = node.visuals[i];
206+
if (ws.name === this.value) {
207+
$("#node-input-username").val(ws.username);
208+
$("#node-input-password").val(ws.password);
209+
}
210+
}
211+
}
212+
213+
}
214+
});
215+
216+
$("#node-input-command").on("change",function() {
217+
if (this.value === 'list') {
218+
$("#node-input-classifier :input").attr('disabled',true);
219+
} else {
220+
$("#node-input-classifier :input").attr('disabled',false);
221+
}
222+
});
223+
}
224+
225+
});
226+
227+
RED.nodes.registerType('watson-visual-training',{
228+
category: 'IBM_Watson',
229+
color: '#FFFF80',
230+
defaults: {
231+
name: {value:""},
232+
classifier: {value:"",required:true},
233+
username: {value:"",required:true},
234+
password: {value:"",required:true},
235+
service: {value:"",required:true}
236+
},
237+
inputs:1,
238+
outputs:1,
239+
icon: "visual2.png",
240+
label: function() {
241+
return this.name||"visual training";
242+
},
243+
244+
visuals: [],
245+
246+
oneditprepare: function() {
247+
var node = this;
248+
console.log("this: "+JSON.stringify(this));
249+
250+
$.getJSON('watson-visual-recognition/vcap/',function(data) {
251+
252+
node.visuals = data;
253+
console.log("Visuals: "+JSON.stringify(data));
254+
255+
var last = $('#node-input-service').children().last();
256+
var opts = [];
257+
258+
console.log("node.service: "+node.service);
259+
for (var i=0; i < data.length; i++) {
260+
console.log("data.name: "+data[i].name);
261+
262+
var selected = node.service === data[i].name;
263+
console.log("selected: "+selected);
264+
opts.push(
265+
'<option value="' + data[i].name + '"' + (selected ? " selected":"") + '>' +
266+
data[i].name +
267+
'</option>'
268+
);
269+
}
270+
271+
if (opts.length === 0) {
272+
node.service = "_ext_";
273+
$('#node-input-service').find("option").filter(function() {
274+
return $(this).val() == node.service;
275+
}).attr('selected', true);
276+
} else {
277+
last.before(opts.join(""));
278+
}
279+
280+
if (node.service === '_ext_') {
281+
} else {
282+
for (var i2=0;i2<node.visuals.length;i2++) {
283+
var ws = node.visuals[i2];
284+
if (ws.name === node.service) {
285+
$("#node-input-username").val(ws.username);
286+
$("#node-input-password").val(ws.password);
287+
util.log("** Visual: "+JSON.stringify(node.visuals[i2]));
288+
}
289+
}
290+
$("#external_visual_details :input").attr('disabled',true);
291+
}
292+
});
293+
294+
$("#node-input-service").on("change",function() {
295+
$("#node--input-service").val(this.value);
296+
if (this.value === '_ext_') {
297+
$("#external_visual_details :input").attr('disabled',false);
298+
} else {
299+
if(node.visuals) {
300+
$("#external_visual_details :input").attr('disabled',true);
301+
for (var i=0;i<node.visuals.length;i++) {
302+
var ws = node.visuals[i];
303+
if (ws.name === this.value) {
304+
$("#node-input-username").val(ws.username);
305+
$("#node-input-password").val(ws.password);
306+
}
307+
}
308+
}
309+
310+
}
311+
});
312+
}
313+
});
314+
315+
</script>
316+
317+
<script type="text/x-red" data-template-name="watson-visual-util">
318+
<div class="form-row">
319+
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
320+
<input type="text" id="node-input-name" placeholder="Name">
321+
</div>
322+
<div class="form-row">
323+
<label for="node-input-command"><i class="icon-tag"></i> Command</label>
324+
<select id="node-input-command">
325+
<option value="list">List Classifiers</option>
326+
<option value="details">Classifier Details</option>
327+
<option value="delete">Delete Classifier</option>
328+
</select>
329+
</div>
330+
<div class="form-row">
331+
<label for="node-input-classifier"><i class="icon-tag"></i> Classifier</label>
332+
<select id="node-input-classifier">
333+
<option value="" disabled></option>
334+
</select>
335+
<!--input type="text" id="node-input-classifier" placeholder="Name"-->
336+
</div>
337+
<div class="form-row">
338+
<label for="node-input-service"><i class="fa fa-globe"></i> Service</label>
339+
<select id="node-input-service">
340+
<option value="" disabled></option>
341+
<option value="_ext_"> External service</option>
342+
</select>
343+
</div>
344+
<div id="external_visual_details">
345+
<div class="form-row">
346+
<label for="node-input-username"><i class="fa fa-user"></i> Username</label>
347+
<input type="text" id="node-input-username">
348+
</div>
349+
<div class="form-row">
350+
<label for="node-input-password"><i class="fa fa-lock"></i> Password</label>
351+
<input type="text" id="node-input-password">
352+
</div>
353+
</div>
354+
</script>
355+
356+
<script type="text/x-red" data-help-name="watson-visual-util">
357+
<p>A node for managing the classifiers in the Visual Recognition service in Watson</p>
358+
<p>More information about this service can be found in the
359+
<a href='https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/visual-recognition/'>Image Recognition API documentation</a></p>.
360+
</script>
361+
362+
<script type="text/x-red" data-template-name="watson-visual-training">
363+
<div class="form-row">
364+
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
365+
<input type="text" id="node-input-name" placeholder="Name">
366+
</div>
367+
<div class="form-row">
368+
<label for="node-input-classifier"><i class="icon-tag"></i> Classifier</label>
369+
<input type="text" id="node-input-classifier" placeholder="Name">
370+
</div>
371+
<div class="form-row">
372+
<label for="node-input-service"><i class="fa fa-globe"></i> Service</label>
373+
<select id="node-input-service">
374+
<option value="" disabled></option>
375+
<option value="_ext_"> External service</option>
376+
</select>
377+
</div>
378+
<div id="external_visual_details">
379+
<div class="form-row">
380+
<label for="node-input-username"><i class="fa fa-user"></i> Username</label>
381+
<input type="text" id="node-input-username">
382+
</div>
383+
<div class="form-row">
384+
<label for="node-input-password"><i class="fa fa-lock"></i> Password</label>
385+
<input type="text" id="node-input-password">
386+
</div>
387+
</div>
388+
</script>
389+
390+
<script type="text/x-red" data-help-name="watson-visual-training">
391+
<p>A node for training the Visual Recognition service in Watson</p>
392+
<p>This service requires that two sets of images are provided for the training. These sets of files should be
393+
zipped and provided to the node either as binary streams or as URL's. The positive and negative set of images
394+
should be pointed by <b>msg.positive</b> and <b>msg.negative</b>.</p>
395+
<p>More information about this service can be found in the
396+
<a href='https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/visual-recognition/'>Image Recognition API documentation</a></p>.
397+
</script>
398+
399+

0 commit comments

Comments
 (0)