Skip to content

Instantly share code, notes, and snippets.

@gbrian
Created April 23, 2017 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbrian/a364fa8f6d4fc6a1f452fef794a56179 to your computer and use it in GitHub Desktop.
Save gbrian/a364fa8f6d4fc6a1f452fef794a56179 to your computer and use it in GitHub Desktop.
function tagit(){
var app = new Clarifai.App(
'xZqcIvLNv0f9wNzuVtA97ntA2CB8IHSVFzKc0hzv',
'KYkdTnFHmT6D4Yv8gk5gEPc__1fZ2nJItBrrI8hM'
);
function tags(url, callback){
// predict the contents of an image by passing in a url
app.models.predict(Clarifai.TRAVEL_MODEL, url)
.then(
function(response) {
callback(response.outputs["0"].data.concepts
.filter(c => c.value >= 0.6).map(c => ({name: c.name, value: c.value})));
},
console.error
) };
function tagitem(item){
var url = item.src;
var details = jQuery(item).parent().parent().find(".hotel-details");
tags(url, (tags) => tags.map(t => details.prepend("<span class='tag' title='"+t.value+"'>"+t.name+"</span>")));
}
var item = jQuery("img").filter((o,i) => i.src.indexOf("ImageHandler") !== -1).each((i,el) => tagitem(el));
}
jQuery("head").append("<style>.tag{margin-right: 3px;background-color: #30a1d9;color: white;padding: 3px;}</style>")
jQuery.getScript("https://sdk.clarifai.com/js/clarifai-latest.js", tagit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment