-
Notifications
You must be signed in to change notification settings - Fork 0
/
clarifai-api.js
48 lines (42 loc) · 1023 Bytes
/
clarifai-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require("dotenv").config();
const axios = require("axios");
let all_labels = [];
const PAT = process.env.CLARIFAI_PAT;
const USER_ID = "clarifai";
const APP_ID = "main";
const MODEL_ID = "general-image-recognition";
const getLabels = async (imageList) => {
const data = {
user_app_id: {
user_id: USER_ID,
app_id: APP_ID,
},
inputs: imageList.map((url) => ({
data: {
image: {
url: url,
},
},
})),
};
try {
const response = await axios.post(
`https://api.clarifai.com/v2/models/${MODEL_ID}/outputs`,
data,
{
headers: {
Accept: "application/json",
Authorization: "Key " + PAT,
},
}
);
// Extract and store results in the global array
all_labels = response.data.outputs.map((output) =>
output.data.concepts.map((concept) => concept.name).slice(0, 10)
);
} catch (error) {
console.log("error", error);
}
return all_labels;
};
module.exports = getLabels;