# CloudVision API\*

* Pentru enable -> Google Cloud Platform Dashboard -> Search for Cloud Vision API -> Enable (proces foarte asemanator cu cel necesar pentru enable TranslateAPI)
* Cheia pe care o folositi la translateAPI poate fi folosita si pentru CloudVision API
* În proiectul asocial Backend-ului -> terminal -> instalam @google-cloud/vision (**npm i @google-cloud/vision**)
* Fisier nou in folderul utils: imageRecognitionFunctions.js

```
// imageRecognitionFunctions.js
const vision = require('@google-cloud/vision');
const dotenv = require("dotenv");
dotenv.config();

const imageRecognitionAPI = new vision.ImageAnnotatorClient({
    keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS
});

async function detectLabels(file) {
    try{
        const [result] = await imageRecognitionAPI.labelDetection(file);
        const labels = result.labelAnnotations;
        const labelsDescriptions = labels.map((label) => {
            return label.description;
        }
        );
        return labelsDescriptions;
    }
    catch(error){
        console.log(error);
        return;
    }
}

detectLabels('https://www.impact.ro/wp-content/uploads/2021/12/New-York.jpg')
// detectLabels('./resources/waldo.jpeg')

module.exports = {
    detectLabels
}
```

* Drept parametru puteti trimite un fisier local sau chiar un link (atentie, pentru a introduce un link spre o poza trebuie sa apasati click dreapta pe o poza -> copy image adress -> paste ca parametru)
* Exemplu de endpoint care utilizeaza aceasta metoda

```
// utilsRouter.js
router.get("/labels", async (req, res) => {
    const { link } = req.body;
    if (!link) {
        return res.status(400).send("Bad request. Missing parametres.");
    }
    const labels = await detectLabels(link);
    console.log(labels);
    return res.json({
        labels,
    });
}
);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gurita-alexandru.gitbook.io/cloud-computing-2023-simpre/cloudcomputing2022/cloudvision-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
