Code viewer for World: New World
// Function to perform image analysis using the Computer Vision API
function analyzeImage(apiKey, imageUrl) {
    var endpoint = "https://suraksha.cognitiveservices.azure.com/"; // Replace with your actual endpoint

    var params = {
        "visualFeatures": "Categories,Description",
        "details": "",
        "language": "en"
    };

    fetch(endpoint + "/vision/v3.1/analyze", {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Ocp-Apim-Subscription-Key': apiKey
        },
        body: JSON.stringify({ url: imageUrl })
    })
    .then(response => response.json())
    .then(data => {
        console.log("Analysis Results: ", data);
        // Displaying analysis results in console
        console.log("Description: ", data.description.captions[0].text);
        console.log("Categories: ", data.categories);
    })
    .catch(error => {
        console.error("Error: ", error);
    });
}

// Get API key and image URL from user input (for demonstration)
var apiKey = prompt("Please enter your API key:");
var imageUrl = prompt("Please enter the URL of the image to analyze:");

// Check if the user provided both API key and image URL
if (apiKey && imageUrl) {
    // Call analyzeImage function with user-provided API key and image URL
    analyzeImage(apiKey, imageUrl);
} else {
    console.log("API key or image URL is missing.");
}