Code viewer for World: Similarity API
var img1, img2;

function preload() 
{
   img1 = loadImage ('/uploads/wooh2/Original.jpg');
   img2 = loadImage ('/uploads/wooh2/Resized_width.jpg');
}

function setup() {
    createCanvas( 1920, 1080 );
}

// Reference: https://rapidapi.com/jlcdev/api/similarity2/
function makeRequest(img1, img2) {
    var data = {
        "image_a": {
            "type": "url",
            "content": img1
        },
        "image_b": {
            "type": "url",
            "content": img2
        }
    }
    
    var dataString = JSON.stringify ( data );
    
    const request = {
        async: true,
    	crossDomain: true,
    	url: 'https://similarity2.p.rapidapi.com/similarity',
    	method: 'POST',
    	headers: {
    		'content-type': 'application/json',
    		'X-RapidAPI-Key': '6a91978638msha6d15484bb38d0fp147206jsn12206b0ca611',
    		 // Another key: 69fc5ad275mshbac40381c4ae8a5p1d2848jsn2e16e32352eb
    		'X-RapidAPI-Host': 'similarity2.p.rapidapi.com'
    	},
    	processData: false,
	    data: dataString,
    };
    console.log("Made request");

    $.ajax(request).done(function (response) {
    	showResponse(response);
    });
}

function showResponse(response) {
    img1.resize(0, 300);
    image(img1, 50, 50);
    
    img2.resize(0, 300);
    image(img2, 600, 50);
    
    var similarity = response.similarity;
    console.log(response);
    textSize(30);
    text("Similarity: " + similarity, 300, 400);
}

// Call Similarity API
makeRequest("https://ancientbrain.com/uploads/wooh2/Original.jpg", "https://ancientbrain.com/uploads/wooh2/Resized_width.jpg");