Last active
March 10, 2017 19:34
-
-
Save sunnygleason/68c54981dfd434d648ed70ecf78e7978 to your computer and use it in GitHub Desktop.
PubNub Clarifai Image Analysis UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.5.0.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> | |
<script src="https://cdn.pubnub.com/sdk/pubnub-angular/pubnub-angular-4.0.2.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" /> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" /> | |
</head> | |
<body> | |
<div class="container" ng-app="PubNubAngularApp" ng-controller="MyImgCtrl"> | |
<pre> | |
NOTE: make sure to update the PubNub keys below with your keys, | |
and ensure that the Clarifai BLOCK is configured properly! | |
</pre> | |
<h3>MyImage Analysis</h3> | |
<pre> | |
Apple Pie: https://images-gmi-pmc.edge-generalmills.com/0653795c-5b4b-4822-abad-80d72c253a68.jpg | |
Choc. Chip Cookie: http://images-gmi-pmc.edge-generalmills.com/eb52c020-c145-440c-8445-911f133c0096.jpg | |
Milk: https://hood.com/uploadedImages/Products/LightBlock-whole(1).png | |
</pre> | |
<input ng-model="toSend" placeholder="image url" /> | |
<input type="button" ng-click="publish()" value="Send!" /> | |
<br /><br /> | |
<ul> | |
<li ng-repeat="message in messages track by $index"> | |
{{message.analysis.results[0].result.tag.classes}} | |
<br /> | |
{{message.analysis.results[0].result.tag.probs}} | |
<br /> | |
<img ng-src="{{message.url}}" height="200"></img> | |
</li> | |
</ul> | |
</div> | |
<script> | |
angular.module('PubNubAngularApp', ["pubnub.angular.service"]) | |
.controller('MyImgCtrl', function($rootScope, $scope, Pubnub) { | |
$scope.messages = []; | |
$scope.msgChannel = 'clarifai-channel'; | |
if (!$rootScope.initialized) { | |
Pubnub.init({ | |
publishKey: 'YOUR_PUB_KEY', | |
subscribeKey: 'YOUR_SUB_KEY', | |
ssl:true | |
}); | |
$rootScope.initialized = true; | |
} | |
var msgCallback = function(payload) { | |
$scope.$apply(function() { | |
$scope.messages.push(payload); | |
}); | |
}; | |
$scope.publish = function() { | |
Pubnub.publish({ | |
channel: $scope.msgChannel, | |
message: {url:$scope.toSend} | |
}); | |
$scope.toSend = ""; | |
}; | |
Pubnub.subscribe({ channels: [$scope.msgChannel] }); | |
Pubnub.addListener({ message: msgCallback }); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment