Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add screenshot, enhance HTML #57

Merged
merged 1 commit into from
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 98 additions & 133 deletions watson_services_labs/visual_recognition/Reco-Lab-WebPage.json
Original file line number Diff line number Diff line change
@@ -1,133 +1,98 @@


[
{
"id": "99cd6f6a.147ae",
"type": "watson-visual-recognition",
"name": "",
"x": 542,
"y": 307,
"wires": [
[
"25699d65.bcf17a"
]
]
},
{
"id": "52bedda6.5f6fdc",
"type": "http in",
"name": "",
"url": "\/reco",
"method": "get",
"swaggerDoc": "",
"x": 160,
"y": 125,
"wires": [
[
"b2105f77.d22cb"
]
]
},
{
"id": "531aa621.2fd37",
"type": "http response",
"name": "HTTP Response",
"x": 828,
"y": 190,
"wires": [

]
},
{
"id": "b2105f77.d22cb",
"type": "switch",
"name": "Check image param",
"property": "payload.imageurl",
"rules": [
{
"t": "null"
},
{
"t": "else"
}
],
"checkall": "false",
"outputs": 2,
"x": 284,
"y": 187,
"wires": [
[
"a07fb791.06f72"
],
[
"8233012.715c88"
]
]
},
{
"id": "a07fb791.06f72",
"type": "template",
"name": "Get Image URL",
"field": "payload",
"format": "html",
"template": "<h1>Welcome to the Watson Visual Recognition Demo on Node-RED<\/h1>\n<h2>Select an image URL<\/h2>\n<form action=\"{{req._parsedUrl.pathname}}\">\n <img src=\"http:\/\/visual-recognition-demo.mybluemix.net\/images\/horses.jpg\" height='100'\/>\n <img src=\"http:\/\/visual-recognition-demo.mybluemix.net\/images\/73388.jpg\" height='100'\/>\n <img src=\"http:\/\/visual-recognition-demo.mybluemix.net\/images\/26537.jpg\" height='100'\/>\n <img src=\"http:\/\/visual-recognition-demo.mybluemix.net\/images\/4068.jpg\" height='100'\/>\n <br\/>Copy above image location URL or enter any image URL:<br\/>\n <input type=\"text\" name=\"imageurl\"\/>\n <input type=\"submit\" value=\"Analyze\"\/>\n<\/form>",
"x": 578,
"y": 156,
"wires": [
[
"531aa621.2fd37"
]
]
},
{
"id": "25699d65.bcf17a",
"type": "template",
"name": "Report",
"field": "payload",
"format": "html",
"template": "<h1>Visual Recognition<\/h1>\n<p>Analyzed image: {{payload}}<br\/><img src=\"{{payload}}\" height='100'\/><\/p>\n<table border='1'>\n <thead><tr><th>Name<\/th><th>Score<\/th><\/tr><\/thead>\n{{#labels}}\n <tr><td><b>{{label_name}}<\/b><\/td><td><i>{{label_score}}<\/i><\/td><\/tr>\n{{\/labels}}\n<\/table>\n<form action=\"{{req._parsedUrl.pathname}}\">\n <input type=\"submit\" value=\"Try again\"\/>\n<\/form>",
"x": 673,
"y": 224,
"wires": [
[
"531aa621.2fd37"
]
]
},
{
"id": "8233012.715c88",
"type": "change",
"name": "Extract img URL",
"rules": [
{
"t": "set",
"p": "payload",
"to": "msg.payload.imageurl"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 370,
"y": 245,
"wires": [
[
"99cd6f6a.147ae"
]
]
},
{
"id": "79431c21.52306c",
"type": "comment",
"name": "!!Make sure you bind Visual Recognition Service to Node-RED App!!",
"info": "When running in BlueMix, the credentials for the service will be filled-in from BMix credentials management.\nFor this to work, the Visual Recognition Service has to be bound to the Node-RED application.\n",
"x": 549,
"y": 342,
"wires": [

]
}
]

[{
"id" : "99cd6f6a.147ae",
"type" : "watson-visual-recognition",
"name" : "",
"x" : 542,
"y" : 307,
"wires" : [["25699d65.bcf17a", "c04bcd07.e27f5"]]
}, {
"id" : "52bedda6.5f6fdc",
"type" : "http in",
"name" : "",
"url" : "/reco",
"method" : "get",
"swaggerDoc" : "",
"x" : 160,
"y" : 125,
"wires" : [["b2105f77.d22cb"]]
}, {
"id" : "531aa621.2fd37",
"type" : "http response",
"name" : "HTTP Response",
"x" : 828,
"y" : 190,
"wires" : []
}, {
"id" : "b2105f77.d22cb",
"type" : "switch",
"name" : "Check image param",
"property" : "payload.imageurl",
"rules" : [{
"t" : "null"
}, {
"t" : "else"
}
],
"checkall" : "false",
"outputs" : 2,
"x" : 284,
"y" : 187,
"wires" : [["a07fb791.06f72"], ["8233012.715c88"]]
}, {
"id" : "a07fb791.06f72",
"type" : "template",
"name" : "Get Image URL",
"field" : "payload",
"format" : "html",
"template" : "<html>\n<head><title>Watson Visual Recognition on Node-RED</title></head>\n<body>\n<h1>Welcome to the Watson Visual Recognition Demo on Node-RED</h1>\n<h2>Select an image URL</h2>\n<form action=\"{{req._parsedUrl.pathname}}\">\n <img src=\"http://visual-recognition-demo.mybluemix.net/images/horses.jpg\" height='100'/>\n <img src=\"http://visual-recognition-demo.mybluemix.net/images/73388.jpg\" height='100'/>\n <img src=\"http://visual-recognition-demo.mybluemix.net/images/26537.jpg\" height='100'/>\n <img src=\"http://visual-recognition-demo.mybluemix.net/images/4068.jpg\" height='100'/>\n <br/>Copy above image location URL or enter any image URL:<br/>\n <input type=\"text\" name=\"imageurl\"/>\n <input type=\"submit\" value=\"Analyze\"/>\n</form>\n</body>\n</html>",
"x" : 578,
"y" : 156,
"wires" : [["531aa621.2fd37"]]
}, {
"id" : "25699d65.bcf17a",
"type" : "template",
"name" : "Report",
"field" : "payload",
"format" : "html",
"template" : "<html>\n<head><title>Watson Visual Recognition on Node-RED</title></head>\n<body>\n<h1>Node-RED Watson Visual Recognition output</h1>\n<p>Analyzed image: {{payload}}<br/><img src=\"{{payload}}\" height='100'/></p>\n<table border='1'>\n <thead><tr><th>Name</th><th>Score</th></tr></thead>\n{{#labels}}\n <tr><td><b>{{label_name}}</b></td><td><i>{{label_score}}</i></td></tr>\n{{/labels}}\n</table>\n<form action=\"{{req._parsedUrl.pathname}}\">\n <input type=\"submit\" value=\"Try again\"/>\n</form>\n</body>\n</html>",
"x" : 673,
"y" : 224,
"wires" : [["531aa621.2fd37"]]
}, {
"id" : "8233012.715c88",
"type" : "change",
"name" : "Extract img URL",
"rules" : [{
"t" : "set",
"p" : "payload",
"to" : "msg.payload.imageurl"
}
],
"action" : "",
"property" : "",
"from" : "",
"to" : "",
"reg" : false,
"x" : 370,
"y" : 245,
"wires" : [["99cd6f6a.147ae"]]
}, {
"id" : "79431c21.52306c",
"type" : "comment",
"name" : "!!Make sure you bind Visual Recognition Service to Node-RED App!!",
"info" : "When running in BlueMix, the credentials for the service will be filled-in from BMix credentials management.\nFor this to work, the Visual Recognition Service has to be bound to the Node-RED application.\n",
"x" : 549,
"y" : 342,
"wires" : []
}, {
"id" : "c04bcd07.e27f5",
"type" : "debug",
"name" : "",
"active" : true,
"console" : "false",
"complete" : "labels",
"x" : 834,
"y" : 274,
"wires" : []
}
]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The nodes required to build this flow are:

- And a final ![`template`](../../node-RED_labs/images/node-red_template.png) node linked to the ![`HTTPResponse`](../../node-RED_labs/images/node-red_HTTPResponse.png) output node. The template will format the output returned from the Visual Recognition node into an HTML table for easier reading:
```HTML
<h1>Visual Recognition</h1>
<h1>Node-RED Watson Visual Recognition output</h1>
<p>Analyzed image: {{payload}}<br/><img src="{{payload}}" height='100'/></p>
<table border='1'>
<thead><tr><th>Name</th><th>Score</th></tr></thead>
Expand All @@ -59,10 +59,15 @@ The nodes required to build this flow are:
<input type="submit" value="Try again"/>
</form>
```
![Reco-Lab-TemplateReport-Node-Props](images/Reco-Lab-TemplateReport-Node-Props.png)
![Reco-Lab-TemplateReport-Node-Props](images/Reco-Lab-TemplateReport-Node-Props.png)
Note that the HTML snippet above has been simplified and stripped out of non-essential HTML tags, the completed flow solution has a complete HTML page.

### Testing the flow
To run the web page, point your browser to `/http://xxxx.mybluemix.net/reco` and enter the URL of some image. The URL of the listed images can be copied to clipboard and pasted into the text field.
To run the web page, point your browser to `/http://xxxx.mybluemix.net/reco` and enter the URL of some image.
The URL of the pre-selected images can be copied to clipboard and pasted into the text field.

The Watson Visual Recognition API will return an array with the recognized features, which will be formatted in a HTML table by the template:
![Visual RecognitionScreenshot ](images/Reco-Lab-VisualRecognition_Screenshot.png)

### Flow source
The complete flow is available at [Reco-Lab-WebPage](Reco-Lab-WebPage.json).